-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
19 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: "[email protected]", | ||
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: "[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, | ||
}) | ||
|
@@ -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, | ||
}) | ||
|