-
Notifications
You must be signed in to change notification settings - Fork 8
/
partner_integration_test.go
154 lines (133 loc) · 5.37 KB
/
partner_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package megaport
import (
"context"
"log/slog"
"os"
"testing"
"github.com/stretchr/testify/suite"
)
// PartnerIntegrationTestSuite is the integration test suite for the Partner service
type PartnerIntegrationTestSuite IntegrationTestSuite
func TestPartnerIntegrationTestSuite(t *testing.T) {
t.Parallel()
if *runIntegrationTests {
suite.Run(t, new(PartnerIntegrationTestSuite))
}
}
func (suite *PartnerIntegrationTestSuite) SetupSuite() {
accessKey := os.Getenv("MEGAPORT_ACCESS_KEY")
secretKey := os.Getenv("MEGAPORT_SECRET_KEY")
handler := slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{Level: programLevel})
programLevel.Set(slog.LevelDebug)
megaportClient, err := New(nil, WithBaseURL(MEGAPORTURL), WithLogHandler(handler), WithCredentials(accessKey, secretKey))
if err != nil {
suite.FailNowf("", "could not initialize megaport test client: %s", err.Error())
}
_, err = megaportClient.Authorize(ctx)
if err != nil {
suite.FailNowf("", "could not authorize megaport test client: %s", err.Error())
}
suite.client = megaportClient
}
// TestListPartnerMegaports tests the ListPartnerMegaports method.
func (suite *PartnerIntegrationTestSuite) TestListPartnerMegaports() {
partnerSvc := suite.client.PartnerService
ctx := context.Background()
_, err := partnerSvc.ListPartnerMegaports(ctx)
if err != nil {
suite.FailNowf("could not list partners", "could not list partners %v", err)
}
}
// TestFilterPartnerMegaportByCompanyName tests the FilterPartnerMegaportByCompanyName method.
func (suite *PartnerIntegrationTestSuite) TestFilterPartnerMegaportByCompanyName() {
partnerSvc := suite.client.PartnerService
ctx := context.Background()
partners, err := partnerSvc.ListPartnerMegaports(ctx)
if err != nil {
suite.FailNowf("could not list partners", "could not list partners %v", err)
}
filtered, err := partnerSvc.FilterPartnerMegaportByCompanyName(ctx, partners, "AWS", true)
if err != nil {
suite.FailNowf("could not filter partners", "could not filter partners %v", err)
}
for _, partner := range filtered {
suite.Equal(partner.CompanyName, "AWS")
}
}
// TestFilterPartnerMegaportByLocationId tests the FilterPartnerMegaportByLocationId method.
func (suite *PartnerIntegrationTestSuite) TestFilterPartnerMegaportByLocationId() {
partnerSvc := suite.client.PartnerService
locSvc := suite.client.LocationService
ctx := context.Background()
partners, err := partnerSvc.ListPartnerMegaports(ctx)
if err != nil {
suite.FailNowf("could not list partners", "could not list partners %v", err)
}
location, err := locSvc.GetLocationByName(ctx, "Equinix SY3")
if err != nil {
suite.FailNowf("could not get location", "could not get location %v", err)
}
filtered, err := partnerSvc.FilterPartnerMegaportByLocationId(ctx, partners, location.ID)
if err != nil {
suite.FailNowf("could not filter partners", "could not filter partners %v", err)
}
for _, partner := range filtered {
suite.Equal(partner.LocationId, location.ID)
}
}
// TestFilterPartnerMegaportByConnectType tests the FilterPartnerMegaportByConnectType method.
func (suite *PartnerIntegrationTestSuite) TestFilterPartnerMegaportByConnectType() {
partnerSvc := suite.client.PartnerService
ctx := context.Background()
partners, err := partnerSvc.ListPartnerMegaports(ctx)
if err != nil {
suite.FailNowf("could not list partners", "could not list partners %v", err)
}
filtered, err := partnerSvc.FilterPartnerMegaportByConnectType(ctx, partners, CONNECT_TYPE_AWS_VIF, true)
if err != nil {
suite.FailNowf("could not filter partners", "could not filter partners %v", err)
}
for _, partner := range filtered {
suite.Equal(partner.ConnectType, CONNECT_TYPE_AWS_VIF)
}
filtered2, err := partnerSvc.FilterPartnerMegaportByConnectType(ctx, partners, CONNECT_TYPE_AWS_HOSTED_CONNECTION, true)
if err != nil {
suite.FailNowf("could not filter partners", "could not filter partners %v", err)
}
for _, partner := range filtered2 {
suite.Equal(partner.ConnectType, CONNECT_TYPE_AWS_HOSTED_CONNECTION)
}
}
// TestFilterPartnerMegaportByProductName tests the FilterPartnerMegaportByProductName method.
func (suite *PartnerIntegrationTestSuite) TestFilterPartnerMegaportByProductName() {
partnerSvc := suite.client.PartnerService
ctx := context.Background()
partners, err := partnerSvc.ListPartnerMegaports(ctx)
if err != nil {
suite.FailNowf("could not list partners", "could not list partners %v", err)
}
productName := partners[0].ProductName
filtered, err := partnerSvc.FilterPartnerMegaportByProductName(ctx, partners, productName, true)
if err != nil {
suite.FailNowf("could not filter partners", "could not filter partners %v", err)
}
for _, partner := range filtered {
suite.Equal(partner.ProductName, productName)
}
}
// TestFilterPartnerMegaportByDiversityZone tests the FilterPartnerMegaportByDiversityZone method.
func (suite *PartnerIntegrationTestSuite) TestFilterPartnerMegaportByDiversityZone() {
partnerSvc := suite.client.PartnerService
ctx := context.Background()
partners, err := partnerSvc.ListPartnerMegaports(ctx)
if err != nil {
suite.FailNowf("could not list partners", "could not list partners %v", err)
}
filtered, err := partnerSvc.FilterPartnerMegaportByDiversityZone(ctx, partners, "red", true)
if err != nil {
suite.FailNowf("could not filter partners", "could not filter partners %v", err)
}
for _, partner := range filtered {
suite.Equal(partner.DiversityZone, "red")
}
}