1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
package integration
import (
"context"
"testing"
"github.com/linode/linodego"
"github.com/stretchr/testify/require"
)
func TestMonitorServicesTokenCreation_Get_smoke(t *testing.T) {
client, _, teardown, err := setupPostgresDatabase(t, nil, "fixtures/TestDatabaseACLP_List")
if err != nil {
t.Error(err)
}
defer teardown()
dbs, err := client.ListDatabases(context.Background(), nil)
if len(dbs) == 0 {
t.Errorf("Expected a list of Databases, but got none: %v", err)
}
if err != nil {
t.Errorf("Error listing Databases, expected struct, got error %v", err)
}
var entityIDs []any
for _, db := range dbs {
entityIDs = append(entityIDs, db.ID)
}
client, teardown = createTestClient(t, "fixtures/TestServiceToken_POST")
defer teardown()
// Create a JWE token for the given entity IDs
createOpts := linodego.MonitorTokenCreateOptions{
EntityIDs: entityIDs,
}
// Use the same context with timeout for the token creation
token, createErr := client.CreateMonitorServiceTokenForServiceType(context.Background(), "dbaas", createOpts)
if createErr != nil {
t.Errorf("Error creating token : %s", createErr)
}
// Validate the token
validateToken(t, *token)
}
func validateToken(
t *testing.T,
token linodego.MonitorServiceToken,
) {
require.NotEmpty(t, token.Token)
}
|