From 0750bf1d8af98f1b9b0d18a1a7e132d6aff5af14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Wed, 14 Dec 2022 17:02:18 +0100 Subject: [PATCH] cleanup test local-url --- server/test/client_test.go | 12 ++---- server/test/message_test.go | 24 +++-------- server/test/send_test.go | 80 +++++++++-------------------------- server/test/user_test.go | 24 +++-------- server/test/util/webserver.go | 4 +- server/test/webserver_test.go | 16 +++---- 6 files changed, 42 insertions(+), 118 deletions(-) diff --git a/server/test/client_test.go b/server/test/client_test.go index daf370d..a3d20a4 100644 --- a/server/test/client_test.go +++ b/server/test/client_test.go @@ -8,11 +8,9 @@ import ( ) func TestGetClient(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + _, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -59,11 +57,9 @@ func TestGetClient(t *testing.T) { } func TestCreateAndDeleteClient(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + _, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -104,11 +100,9 @@ func TestCreateAndDeleteClient(t *testing.T) { } func TestReuseFCM(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + _, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", diff --git a/server/test/message_test.go b/server/test/message_test.go index bfb8653..951d20d 100644 --- a/server/test/message_test.go +++ b/server/test/message_test.go @@ -12,11 +12,9 @@ import ( ) func TestSearchMessageFTSSimple(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + ws, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() - baseUrl := "http://127.0.0.1:" + ws.Port - data := tt.InitDefaultData(t, ws) type mglist struct { @@ -40,11 +38,9 @@ func TestSearchMessageFTSMulti(t *testing.T) { //TODO list messages from channel that you cannot see func TestDeleteMessage(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + _, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -70,11 +66,9 @@ func TestDeleteMessage(t *testing.T) { } func TestDeleteMessageAndResendUsrMsgId(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + _, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -122,11 +116,9 @@ func TestDeleteMessageAndResendUsrMsgId(t *testing.T) { } func TestGetMessageSimple(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + ws, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() - baseUrl := "http://127.0.0.1:" + ws.Port - data := tt.InitDefaultData(t, ws) msgOut := tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{ @@ -141,22 +133,18 @@ func TestGetMessageSimple(t *testing.T) { } func TestGetMessageNotFound(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + ws, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() - baseUrl := "http://127.0.0.1:" + ws.Port - data := tt.InitDefaultData(t, ws) tt.RequestAuthGetShouldFail(t, data.User[0].AdminKey, baseUrl, "/api/messages/8963586", 404, apierr.MESSAGE_NOT_FOUND) } func TestGetMessageFull(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + ws, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() - baseUrl := "http://127.0.0.1:" + ws.Port - data := tt.InitDefaultData(t, ws) ts := time.Now().Unix() - 735 diff --git a/server/test/send_test.go b/server/test/send_test.go index 8e3771d..9f4ba46 100644 --- a/server/test/send_test.go +++ b/server/test/send_test.go @@ -12,13 +12,11 @@ import ( ) func TestSendSimpleMessageJSON(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + ws, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() pusher := ws.Pusher.(*push.TestSink) - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -67,13 +65,11 @@ func TestSendSimpleMessageJSON(t *testing.T) { } func TestSendSimpleMessageQuery(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + ws, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() pusher := ws.Pusher.(*push.TestSink) - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -105,13 +101,11 @@ func TestSendSimpleMessageQuery(t *testing.T) { } func TestSendSimpleMessageForm(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + ws, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() pusher := ws.Pusher.(*push.TestSink) - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -147,13 +141,11 @@ func TestSendSimpleMessageForm(t *testing.T) { } func TestSendSimpleMessageFormAndQuery(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + ws, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() pusher := ws.Pusher.(*push.TestSink) - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -176,13 +168,11 @@ func TestSendSimpleMessageFormAndQuery(t *testing.T) { } func TestSendSimpleMessageJSONAndQuery(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + ws, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() pusher := ws.Pusher.(*push.TestSink) - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -205,13 +195,11 @@ func TestSendSimpleMessageJSONAndQuery(t *testing.T) { } func TestSendSimpleMessageAlt1(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + ws, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() pusher := ws.Pusher.(*push.TestSink) - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -254,13 +242,11 @@ func TestSendSimpleMessageAlt1(t *testing.T) { } func TestSendContentMessage(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + ws, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() pusher := ws.Pusher.(*push.TestSink) - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -301,13 +287,11 @@ func TestSendContentMessage(t *testing.T) { } func TestSendWithSendername(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + ws, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() pusher := ws.Pusher.(*push.TestSink) - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -352,13 +336,11 @@ func TestSendWithSendername(t *testing.T) { } func TestSendLongContent(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + ws, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() pusher := ws.Pusher.(*push.TestSink) - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -413,11 +395,9 @@ func TestSendLongContent(t *testing.T) { } func TestSendTooLongContent(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + _, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -442,11 +422,9 @@ func TestSendTooLongContent(t *testing.T) { } func TestSendTooLongTitle(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + _, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -465,13 +443,11 @@ func TestSendTooLongTitle(t *testing.T) { } func TestSendIdempotent(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + ws, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() pusher := ws.Pusher.(*push.TestSink) - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -545,13 +521,11 @@ func TestSendIdempotent(t *testing.T) { } func TestSendWithPriority(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + ws, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() pusher := ws.Pusher.(*push.TestSink) - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -640,13 +614,11 @@ func TestSendWithPriority(t *testing.T) { } func TestSendInvalidPriority(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + ws, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() pusher := ws.Pusher.(*push.TestSink) - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -760,13 +732,11 @@ func TestSendInvalidPriority(t *testing.T) { } func TestSendWithTimestamp(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + ws, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() pusher := ws.Pusher.(*push.TestSink) - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -819,13 +789,11 @@ func TestSendWithTimestamp(t *testing.T) { } func TestSendInvalidTimestamp(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + ws, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() pusher := ws.Pusher.(*push.TestSink) - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -924,13 +892,11 @@ func TestSendInvalidTimestamp(t *testing.T) { } func TestSendCompat(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + ws, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() pusher := ws.Pusher.(*push.TestSink) - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -1014,11 +980,9 @@ func TestSendCompat(t *testing.T) { } func TestSendToNewChannel(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + _, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -1096,11 +1060,9 @@ func TestSendToNewChannel(t *testing.T) { } func TestSendToManualChannel(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + _, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -1189,11 +1151,9 @@ func TestSendToManualChannel(t *testing.T) { } func TestSendToTooLongChannel(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + _, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", diff --git a/server/test/user_test.go b/server/test/user_test.go index cdc901e..016bdf3 100644 --- a/server/test/user_test.go +++ b/server/test/user_test.go @@ -9,11 +9,9 @@ import ( ) func TestCreateUserNoClient(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + _, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "no_client": true, }) @@ -35,11 +33,9 @@ func TestCreateUserNoClient(t *testing.T) { } func TestCreateUserDummyClient(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + _, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -76,11 +72,9 @@ func TestCreateUserDummyClient(t *testing.T) { } func TestCreateUserWithUsername(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + _, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -103,11 +97,9 @@ func TestCreateUserWithUsername(t *testing.T) { } func TestUpdateUsername(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + _, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -139,11 +131,9 @@ func TestUpdateUsername(t *testing.T) { } func TestRecreateKeys(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + _, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", @@ -202,11 +192,9 @@ func TestRecreateKeys(t *testing.T) { func TestDeleteUser(t *testing.T) { t.SkipNow() // TODO DeleteUser Not implemented - ws, stop := tt.StartSimpleWebserver(t) + _, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() - baseUrl := "http://127.0.0.1:" + ws.Port - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{ "agent_model": "DUMMY_PHONE", "agent_version": "4X", diff --git a/server/test/util/webserver.go b/server/test/util/webserver.go index eebaee8..59cd5fa 100644 --- a/server/test/util/webserver.go +++ b/server/test/util/webserver.go @@ -18,7 +18,7 @@ import ( type Void = struct{} -func StartSimpleWebserver(t *testing.T) (*logic.Application, func()) { +func StartSimpleWebserver(t *testing.T) (*logic.Application, string, func()) { InitTests() uuid2, _ := langext.NewHexUUID() @@ -100,5 +100,5 @@ func StartSimpleWebserver(t *testing.T) (*logic.Application, func()) { TestFailErr(t, err) } - return app, stop + return app, "http://127.0.0.1:" + app.Port, stop } diff --git a/server/test/webserver_test.go b/server/test/webserver_test.go index 8fe3750..6423261 100644 --- a/server/test/webserver_test.go +++ b/server/test/webserver_test.go @@ -7,18 +7,16 @@ import ( ) func TestWebserver(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + _, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() - fmt.Printf("Port := %s\n", ws.Port) + fmt.Printf("URL := %s\n", baseUrl) } func TestPing(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + _, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() - baseUrl := "http://127.0.0.1:" + ws.Port - _ = tt.RequestGet[tt.Void](t, baseUrl, "/api/ping") _ = tt.RequestPut[tt.Void](t, baseUrl, "/api/ping", nil) _ = tt.RequestPost[tt.Void](t, baseUrl, "/api/ping", nil) @@ -27,19 +25,15 @@ func TestPing(t *testing.T) { } func TestMongo(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + _, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() - baseUrl := "http://127.0.0.1:" + ws.Port - _ = tt.RequestPost[tt.Void](t, baseUrl, "/api/db-test", nil) } func TestHealth(t *testing.T) { - ws, stop := tt.StartSimpleWebserver(t) + _, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() - baseUrl := "http://127.0.0.1:" + ws.Port - _ = tt.RequestGet[tt.Void](t, baseUrl, "/api/health") }