Skip to content

Commit

Permalink
PMM-12811 fix platform_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
ademidoff committed Jan 19, 2024
1 parent 2f48f8f commit 869a075
Showing 1 changed file with 19 additions and 76 deletions.
95 changes: 19 additions & 76 deletions api-tests/server/platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package server

import (
"net/http"
"os"
"testing"

"github.com/AlekSi/pointer"
Expand All @@ -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: "[email protected]",
Password: password,
ServerName: serverName,
PersonalAccessToken: "JReeZA5EqM4b6bZMxBOEaAxoc4rWd5teK7HF",
ServerName: serverName,
},
Context: pmmapitests.Context,
})
Expand All @@ -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: "[email protected]",
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,
})
Expand All @@ -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,
})
Expand All @@ -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,
})
Expand All @@ -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,
})
Expand All @@ -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,
})
Expand Down

0 comments on commit 869a075

Please sign in to comment.