-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathcluster_sdn_test.go
More file actions
137 lines (110 loc) · 3.67 KB
/
Copy pathcluster_sdn_test.go
File metadata and controls
137 lines (110 loc) · 3.67 KB
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
package proxmox
import (
"context"
"testing"
"github.com/luthermonson/go-proxmox/tests/mocks"
"github.com/stretchr/testify/assert"
)
func TestCluster_SDNSubnets(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
cluster, _ := mockClient().Cluster(context.Background())
subnets, err := cluster.SDNSubnets(context.Background(), "user1")
assert.Nil(t, err)
assert.Len(t, subnets, 1)
assert.Equal(t, "10.0.0.0/24", subnets[0].CIDR)
}
func TestCluster_SDNApply(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
cluster, _ := mockClient().Cluster(context.Background())
task, err := cluster.SDNApply(context.Background())
assert.Nil(t, err)
assert.NotNil(t, task)
assert.Equal(t, "node1", task.Node)
}
func TestCluster_SDNVNets_ClientThreaded(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
cluster, _ := mockClient().Cluster(context.Background())
vnets, err := cluster.SDNVNets(context.Background())
assert.Nil(t, err)
assert.Len(t, vnets, 5)
assert.Equal(t, "user1", vnets[0].Name)
// client should be threaded onto each entry so chained mutations work
assert.NotNil(t, vnets[0].client)
}
func TestCluster_SDNVNet(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
cluster, _ := mockClient().Cluster(context.Background())
v, err := cluster.SDNVNet(context.Background(), "user1")
assert.Nil(t, err)
assert.NotNil(t, v)
assert.Equal(t, "user1", v.Name)
assert.NotNil(t, v.client)
}
func TestCluster_NewSDNVNet(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
cluster, _ := mockClient().Cluster(context.Background())
err := cluster.NewSDNVNet(context.Background(), &VNetOptions{Name: "user99", Zone: "test1", Type: "vnet"})
assert.Nil(t, err)
}
func TestCluster_UpdateSDNVNet(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
cluster, _ := mockClient().Cluster(context.Background())
err := cluster.UpdateSDNVNet(context.Background(), &VNet{Name: "user1", Zone: "test1", Alias: "renamed"})
assert.Nil(t, err)
}
func TestCluster_DeleteSDNVNet(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
cluster, _ := mockClient().Cluster(context.Background())
err := cluster.DeleteSDNVNet(context.Background(), "user1")
assert.Nil(t, err)
}
func TestCluster_SDNZonesFiltered(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
cluster, _ := mockClient().Cluster(context.Background())
// no filter
zones, err := cluster.SDNZones(context.Background())
assert.Nil(t, err)
assert.Len(t, zones, 2)
// with filter — variadic, multiple strings get joined and spaces stripped
zones, err = cluster.SDNZones(context.Background(), "vx", "lan ")
assert.Nil(t, err)
assert.Len(t, zones, 1)
}
func TestCluster_SDNZone_Basic(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
cluster, _ := mockClient().Cluster(context.Background())
zone, err := cluster.SDNZone(context.Background(), "test1")
assert.Nil(t, err)
assert.Equal(t, "test1", zone.Name)
assert.Equal(t, "vxlan", zone.Type)
}
func TestCluster_NewSDNZone(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
cluster, _ := mockClient().Cluster(context.Background())
err := cluster.NewSDNZone(context.Background(), &SDNZoneOptions{Name: "newzone", Type: "simple"})
assert.Nil(t, err)
}
func TestCluster_UpdateSDNZone(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
cluster, _ := mockClient().Cluster(context.Background())
err := cluster.UpdateSDNZone(context.Background(), &SDNZoneOptions{Name: "test1", Type: "vxlan", MTU: 1450})
assert.Nil(t, err)
}
func TestCluster_DeleteSDNZone(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
cluster, _ := mockClient().Cluster(context.Background())
err := cluster.DeleteSDNZone(context.Background(), "test1")
assert.Nil(t, err)
}