This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
virtualnetworks_test.go
176 lines (138 loc) · 3.93 KB
/
virtualnetworks_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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package packngo
import (
"testing"
)
func TestAccVirtualNetworksFacility(t *testing.T) {
skipUnlessAcceptanceTestsAllowed(t)
c, projectID, teardown := setupWithProject(t)
defer teardown()
l, _, err := c.ProjectVirtualNetworks.List(projectID, nil)
if err != nil {
t.Fatal(err)
}
if len(l.VirtualNetworks) != 0 {
t.Fatal("Newly created project should not have any vlans")
}
testDesc := "test_desc_" + randString8()
cr := VirtualNetworkCreateRequest{
ProjectID: projectID,
Description: testDesc,
Facility: testFacility(),
}
vlan, _, err := c.ProjectVirtualNetworks.Create(&cr)
if err != nil {
t.Fatal(err)
}
vlan, _, err = c.ProjectVirtualNetworks.Get(vlan.ID,
&GetOptions{Includes: []string{"assigned_to", "facility"}})
if err != nil {
t.Fatal(err)
}
if vlan.Metro != nil {
t.Fatalf("Metro should be null in facility-enabled VLAN")
}
if vlan.Facility.Code != testFacility() {
t.Fatalf("Wrong Facility in test VLAN, should be %s, was %s", testFacility(), vlan.Facility.Code)
}
_, err = c.ProjectVirtualNetworks.Delete(vlan.ID)
if err != nil {
t.Fatal(err)
}
}
func TestAccVirtualNetworksMetro(t *testing.T) {
skipUnlessAcceptanceTestsAllowed(t)
c, projectID, teardown := setupWithProject(t)
defer teardown()
l, _, err := c.ProjectVirtualNetworks.List(projectID, nil)
if err != nil {
t.Fatal(err)
}
if len(l.VirtualNetworks) != 0 {
t.Fatal("Newly created project should not have any vlans")
}
testDesc := "test_desc_" + randString8()
cr := VirtualNetworkCreateRequest{
ProjectID: projectID,
Description: testDesc,
Metro: testMetro(),
}
vlan, _, err := c.ProjectVirtualNetworks.Create(&cr)
if err != nil {
t.Fatal(err)
}
vlan, _, err = c.ProjectVirtualNetworks.Get(vlan.ID,
&GetOptions{Includes: []string{"assigned_to", "metro"}})
if err != nil {
t.Fatal(err)
}
if vlan.Facility != nil {
t.Fatalf("Facility should be null in metro-enabled VLAN")
}
if vlan.Metro.Code != testMetro() {
t.Fatalf("Wrong metro for testing VLAN, should be %s, was %s", testMetro(), vlan.Metro.Code)
}
_, err = c.ProjectVirtualNetworks.Delete(vlan.ID)
if err != nil {
t.Fatal(err)
}
}
func TestAccVirtualNetworksBasic(t *testing.T) {
skipUnlessAcceptanceTestsAllowed(t)
c, projectID, teardown := setupWithProject(t)
defer teardown()
l, _, err := c.ProjectVirtualNetworks.List(projectID, nil)
if err != nil {
t.Fatal(err)
}
if len(l.VirtualNetworks) != 0 {
t.Fatal("Newly created project should not have any vlans")
}
testDesc := "test_desc_" + randString8()
cr := VirtualNetworkCreateRequest{
ProjectID: projectID,
Description: testDesc,
Facility: testFacility(),
}
vlan, _, err := c.ProjectVirtualNetworks.Create(&cr)
if err != nil {
t.Fatal(err)
}
vlan, _, err = c.ProjectVirtualNetworks.Get(vlan.ID,
&GetOptions{Includes: []string{"assigned_to"}})
if err != nil {
t.Fatal(err)
}
if vlan.Project.ID != projectID {
t.Fatalf("VLAN's project ID should be %s, was %s", projectID,
vlan.Project.ID)
}
if vlan.Description != testDesc {
t.Fatal("Wrong description string in created VLAN")
}
l, _, err = c.ProjectVirtualNetworks.List(projectID,
&ListOptions{Includes: []string{"assigned_to"}})
if err != nil {
t.Fatal(err)
}
if len(l.VirtualNetworks) != 1 {
t.Fatal("At this point, there should be exactly 1 VLAN in the project")
}
if l.VirtualNetworks[0].Project.ID != projectID {
t.Fatalf("VLAN's project ID from list should be %s, was %s", projectID,
l.VirtualNetworks[0].Project.ID)
}
_, err = c.ProjectVirtualNetworks.Delete(l.VirtualNetworks[0].ID)
if err != nil {
t.Fatal(err)
}
l, _, err = c.ProjectVirtualNetworks.List(projectID, nil)
if err != nil {
t.Fatal(err)
}
if len(l.VirtualNetworks) != 0 {
t.Fatal("The test project should not have any VLANs now")
}
// TODO: Test several bad inputs to ensure rejection without adverse affects
// Create virtual network with bad POST body parameters
// Ensure create failed
}