-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathclient_integration_test.go
63 lines (48 loc) · 1.56 KB
/
client_integration_test.go
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
55
56
57
58
59
60
61
62
63
package megaport
import (
"context"
"log/slog"
"net/http"
"os"
"testing"
"github.com/stretchr/testify/suite"
)
type IntegrationTestSuite struct {
suite.Suite
client *Client
}
type ClientIntegrationTestSuite IntegrationTestSuite
func TestClientIntegrationTestSuite(t *testing.T) {
t.Parallel()
if *runIntegrationTests {
suite.Run(t, new(ClientIntegrationTestSuite))
}
}
func (suite *ClientIntegrationTestSuite) SetupSuite() {
accessKey := os.Getenv("MEGAPORT_ACCESS_KEY")
secretKey := os.Getenv("MEGAPORT_SECRET_KEY")
httpClient := &http.Client{}
handler := slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{Level: programLevel})
programLevel.Set(slog.LevelDebug)
var err error
megaportClient, err := New(httpClient, WithBaseURL(MEGAPORTURL), WithLogHandler(handler), WithCredentials(accessKey, secretKey))
if err != nil {
suite.FailNowf("", "could not initialize megaport test client: %s", err.Error())
}
// NOTE: unlike other test suites we don't do the authorization here because we want to test that functionality
suite.client = megaportClient
}
func (suite *ClientIntegrationTestSuite) TestLogin() {
ctx := context.Background()
resp, err := suite.client.Authorize(ctx)
if err != nil {
suite.client.Logger.ErrorContext(ctx, "login error", slog.String("error", err.Error()))
}
suite.NoError(err)
// Session Token is not empty
suite.NotEmpty(resp.AccessToken)
suite.NotZero(resp.Expiration)
// Internal is same as returned
suite.Equal(resp.AccessToken, suite.client.accessToken)
suite.Equal(resp.Expiration, suite.client.tokenExpiry)
}