From 869a075401e39dcf785ea0a73e07b55f4389d4e9 Mon Sep 17 00:00:00 2001 From: Alex Demidoff Date: Fri, 19 Jan 2024 15:51:52 +0000 Subject: [PATCH] PMM-12811 fix platform_test.go --- api-tests/server/platform_test.go | 95 +++++++------------------------ 1 file changed, 19 insertions(+), 76 deletions(-) diff --git a/api-tests/server/platform_test.go b/api-tests/server/platform_test.go index 5dc6df7919..56452eacbb 100644 --- a/api-tests/server/platform_test.go +++ b/api-tests/server/platform_test.go @@ -17,7 +17,6 @@ package server import ( "net/http" - "os" "testing" "github.com/AlekSi/pointer" @@ -36,18 +35,16 @@ func TestPlatform(t *testing.T) { client := platformClient.Default.PlatformService serverClient := serverClient.Default.ServerService + // TODO: provide a real PersonalAccessToken for the dev environment so this test can be run. + // The one below is a fake, it is there to fix the test compilation. + const serverName = string("my PMM") - username, password := os.Getenv("PERCONA_TEST_PORTAL_USERNAME"), os.Getenv("PERCONA_TEST_PORTAL_PASSWORD") t.Run("connect and disconnect", func(t *testing.T) { - if username == "" || password == "" { - t.Skip("Environment variables PERCONA_TEST_PORTAL_USERNAME, PERCONA_TEST_PORTAL_PASSWORD not set.") - } t.Run("PMM server does not have address set", func(t *testing.T) { _, err := client.Connect(&platform.ConnectParams{ Body: platform.ConnectBody{ - Email: "wrong@example.com", - Password: password, - ServerName: serverName, + PersonalAccessToken: "JReeZA5EqM4b6bZMxBOEaAxoc4rWd5teK7HF", + ServerName: serverName, }, Context: pmmapitests.Context, }) @@ -64,60 +61,22 @@ func TestPlatform(t *testing.T) { require.NoError(t, err) assert.Equal(t, "localhost", res.Payload.Settings.PMMPublicAddress) - t.Run("wrong email", func(t *testing.T) { + t.Run("empty access token", func(t *testing.T) { _, err := client.Connect(&platform.ConnectParams{ Body: platform.ConnectBody{ - Email: "wrong@example.com", - Password: password, - ServerName: serverName, + PersonalAccessToken: "", + ServerName: serverName, }, Context: pmmapitests.Context, }) - pmmapitests.AssertAPIErrorf(t, err, http.StatusUnauthorized, codes.Unauthenticated, "Incorrect username or password.") - }) - - t.Run("wrong password", func(t *testing.T) { - _, err := client.Connect(&platform.ConnectParams{ - Body: platform.ConnectBody{ - Email: username, - Password: "WrongPassword12345", - ServerName: serverName, - }, - Context: pmmapitests.Context, - }) - pmmapitests.AssertAPIErrorf(t, err, http.StatusUnauthorized, codes.Unauthenticated, "Incorrect username or password.") - }) - - t.Run("empty email", func(t *testing.T) { - _, err := client.Connect(&platform.ConnectParams{ - Body: platform.ConnectBody{ - Email: "", - Password: password, - ServerName: serverName, - }, - Context: pmmapitests.Context, - }) - pmmapitests.AssertAPIErrorf(t, err, http.StatusBadRequest, codes.InvalidArgument, "invalid field Email: value '' must not be an empty string") - }) - - t.Run("empty password", func(t *testing.T) { - _, err := client.Connect(&platform.ConnectParams{ - Body: platform.ConnectBody{ - Email: username, - ServerName: serverName, - Password: "", - }, - Context: pmmapitests.Context, - }) - pmmapitests.AssertAPIErrorf(t, err, http.StatusBadRequest, codes.InvalidArgument, "invalid field Password: value '' must not be an empty string") + pmmapitests.AssertAPIErrorf(t, err, http.StatusBadRequest, codes.InvalidArgument, "invalid field PersonalAccessToken: value '' must not be an empty string") }) t.Run("empty server name", func(t *testing.T) { _, err := client.Connect(&platform.ConnectParams{ Body: platform.ConnectBody{ - Email: username, - Password: password, - ServerName: "", + PersonalAccessToken: "JReeZA5EqM4b6bZMxBOEaAxoc4rWd5teK7HF", + ServerName: "", }, Context: pmmapitests.Context, }) @@ -127,9 +86,8 @@ func TestPlatform(t *testing.T) { t.Run("successful connect and disconnect", func(t *testing.T) { _, err := client.Connect(&platform.ConnectParams{ Body: platform.ConnectBody{ - ServerName: serverName, - Email: username, - Password: password, + ServerName: serverName, + PersonalAccessToken: "JReeZA5EqM4b6bZMxBOEaAxoc4rWd5teK7HF", }, Context: pmmapitests.Context, }) @@ -155,16 +113,11 @@ func TestPlatform(t *testing.T) { }) t.Run("search tickets", func(t *testing.T) { - if username == "" || password == "" { - t.Skip("Environment variables PERCONA_TEST_PORTAL_USERNAME, PERCONA_TEST_PORTAL_PASSWORD not set.") - } - t.Run("success", func(t *testing.T) { _, err := client.Connect(&platform.ConnectParams{ Body: platform.ConnectBody{ - ServerName: serverName, - Email: username, - Password: password, + ServerName: serverName, + PersonalAccessToken: "JReeZA5EqM4b6bZMxBOEaAxoc4rWd5teK7HF", }, Context: pmmapitests.Context, }) @@ -183,16 +136,11 @@ func TestPlatform(t *testing.T) { }) t.Run("search entitlements", func(t *testing.T) { //nolint:dupl - if username == "" || password == "" { - t.Skip("Environment variables PERCONA_TEST_PORTAL_USERNAME, PERCONA_TEST_PORTAL_PASSWORD not set.") - } - t.Run("success", func(t *testing.T) { _, err := client.Connect(&platform.ConnectParams{ Body: platform.ConnectBody{ - ServerName: serverName, - Email: username, - Password: password, + ServerName: serverName, + PersonalAccessToken: "JReeZA5EqM4b6bZMxBOEaAxoc4rWd5teK7HF", }, Context: pmmapitests.Context, }) @@ -211,16 +159,11 @@ func TestPlatform(t *testing.T) { }) t.Run("get contact information", func(t *testing.T) { //nolint:dupl - if username == "" || password == "" { - t.Skip("Environment variables PERCONA_TEST_PORTAL_USERNAME, PERCONA_TEST_PORTAL_PASSWORD not set.") - } - t.Run("success", func(t *testing.T) { _, err := client.Connect(&platform.ConnectParams{ Body: platform.ConnectBody{ - ServerName: serverName, - Email: username, - Password: password, + ServerName: serverName, + PersonalAccessToken: "JReeZA5EqM4b6bZMxBOEaAxoc4rWd5teK7HF", }, Context: pmmapitests.Context, })