-
Notifications
You must be signed in to change notification settings - Fork 8
/
mve_integration_test.go
106 lines (88 loc) · 2.97 KB
/
mve_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
package megaport
import (
"context"
"log/slog"
"os"
"testing"
"time"
"github.com/stretchr/testify/suite"
)
const (
TEST_MVE_TEST_LOCATION_MARKET = "AU"
)
// MVEIntegrationTestSuite is the integration test suite for the MVE service
type MVEIntegrationTestSuite IntegrationTestSuite
func TestMVEIntegrationTestSuite(t *testing.T) {
t.Parallel()
if *runIntegrationTests {
suite.Run(t, new(MVEIntegrationTestSuite))
}
}
func (suite *MVEIntegrationTestSuite) 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
}
// TestArubaMVE tests the lifecycle of an Aruba SD-WAN MVE
func (suite *MVEIntegrationTestSuite) TestArubaMVE() {
mveSvc := suite.client.MVEService
ctx := context.Background()
locSvc := suite.client.LocationService
logger := suite.client.Logger
logger.DebugContext(ctx, "Buying MVE")
testLocation, err := GetRandomLocation(ctx, locSvc, TEST_MVE_TEST_LOCATION_MARKET)
if err != nil {
suite.FailNowf("could not get location", "could not get location %v", err)
}
logger.DebugContext(ctx, "test location determined", slog.String("location", testLocation.Name))
mveConfig := &ArubaConfig{
Vendor: "aruba",
ProductSize: "MEDIUM",
ImageID: 23,
AccountName: "test",
AccountKey: "test",
SystemTag: "test",
}
buyMVERes, err := mveSvc.BuyMVE(ctx, &BuyMVERequest{
LocationID: testLocation.ID,
Name: "MVE Test",
Term: 12,
VendorConfig: mveConfig,
Vnics: nil,
WaitForProvision: true,
WaitForTime: 5 * time.Minute,
DiversityZone: "red",
})
if err != nil {
suite.FailNowf("error buying mve", "error buying mve %v", err)
}
mveUid := buyMVERes.TechnicalServiceUID
if !IsGuid(mveUid) {
suite.FailNowf("invalid mve uid", "invalid mve uid %s", mveUid)
}
logger.DebugContext(ctx, "MVE Purchased", slog.String("mve_id", mveUid))
logger.InfoContext(ctx, "Deleting MVE now", slog.String("mve_id", mveUid))
deleteRes, err := mveSvc.DeleteMVE(ctx, &DeleteMVERequest{
MVEID: mveUid,
})
if err != nil {
suite.FailNowf("could not delete mve", "could not delete mve %v", err)
}
suite.True(deleteRes.IsDeleted)
mveDetails, err := mveSvc.GetMVE(ctx, mveUid)
if err != nil {
suite.FailNowf("could not get mve", "could not get mve %v", err)
}
suite.EqualValues(STATUS_DECOMMISSIONED, mveDetails.ProvisioningStatus)
logger.DebugContext(ctx, "MVE deleted", slog.String("provisioning_status", mveDetails.ProvisioningStatus))
}