-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathcluster_sdn_ipams_test.go
More file actions
96 lines (77 loc) · 2.57 KB
/
Copy pathcluster_sdn_ipams_test.go
File metadata and controls
96 lines (77 loc) · 2.57 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
package proxmox
import (
"context"
"testing"
"github.com/luthermonson/go-proxmox/tests/mocks"
"github.com/stretchr/testify/assert"
)
func TestCluster_SDNIPAMs(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
cluster, _ := mockClient().Cluster(context.Background())
ipams, err := cluster.SDNIPAMs(context.Background(), "")
assert.Nil(t, err)
assert.Len(t, ipams, 2)
assert.Equal(t, "pve", ipams[0].IPAM)
}
func TestSDNIPAM_ReadUpdateDelete(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
cluster, _ := mockClient().Cluster(context.Background())
i := cluster.SDNIPAM("pve")
assert.Nil(t, i.Read(context.Background()))
assert.Equal(t, "pve", i.Type)
assert.Nil(t, i.Update(context.Background(), &SDNIPAMOptions{}))
assert.Nil(t, i.Delete(context.Background()))
}
func TestSDNIPAM_Status(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
cluster, _ := mockClient().Cluster(context.Background())
i := cluster.SDNIPAM("pve")
entries, err := i.Status(context.Background())
assert.Nil(t, err)
assert.Len(t, entries, 1)
assert.Equal(t, "vm100", entries[0]["hostname"])
}
func TestCluster_NewSDNIPAM(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
cluster, _ := mockClient().Cluster(context.Background())
err := cluster.NewSDNIPAM(context.Background(), &SDNIPAMOptions{IPAM: "netbox2", Type: "netbox", URL: "https://x"})
assert.Nil(t, err)
assert.NotNil(t, cluster.NewSDNIPAM(context.Background(), nil))
assert.NotNil(t, cluster.NewSDNIPAM(context.Background(), &SDNIPAMOptions{IPAM: "x"}))
}
func TestCluster_SDNIPAMsFiltered(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
cluster, _ := mockClient().Cluster(context.Background())
ipams, err := cluster.SDNIPAMs(context.Background(), "pve")
assert.Nil(t, err)
assert.Len(t, ipams, 1)
}
func TestSDNIPAM_UpdateNilOpts(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
cluster, _ := mockClient().Cluster(context.Background())
i := cluster.SDNIPAM("pve")
assert.Nil(t, i.Update(context.Background(), nil))
}
func TestSDNIPAM_EmptyName_Errors(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
i := &SDNIPAM{client: mockClient()}
assert.Error(t, i.Read(context.Background()))
assert.Error(t, i.Update(context.Background(), &SDNIPAMOptions{}))
assert.Error(t, i.Delete(context.Background()))
_, err := i.Status(context.Background())
assert.Error(t, err)
}
func TestSDNIPAM_Read_NotFound(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
cluster, _ := mockClient().Cluster(context.Background())
i := cluster.SDNIPAM("missing")
assert.Error(t, i.Read(context.Background()))
}