-
Notifications
You must be signed in to change notification settings - Fork 44
/
cluster_test.go
72 lines (60 loc) · 1.53 KB
/
cluster_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
package proxmox
import (
"context"
"testing"
"github.com/luthermonson/go-proxmox/tests/mocks"
"github.com/stretchr/testify/assert"
)
func TestCluster(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
client := mockClient()
ctx := context.Background()
cluster, err := client.Cluster(ctx)
assert.Nil(t, err)
assert.Equal(t, 4, cluster.Version)
assert.Equal(t, "cluster", cluster.ID)
for _, n := range cluster.Nodes {
assert.Contains(t, n.ID, "node/node")
assert.Equal(t, "node", n.Type)
}
}
func TestNextID(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
client := mockClient()
ctx := context.Background()
cluster, err := client.Cluster(ctx)
assert.Nil(t, err)
nextid, err := cluster.NextID(ctx)
assert.Nil(t, err)
assert.Equal(t, 100, nextid)
}
func TestCheckID(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
client := mockClient()
ctx := context.Background()
cluster, err := client.Cluster(ctx)
assert.Nil(t, err)
checkIDFree, err := cluster.CheckID(ctx, 100)
assert.Nil(t, err)
assert.Equal(t, true, checkIDFree)
checkIDTaken, err := cluster.CheckID(ctx, 200)
assert.Nil(t, err)
assert.Equal(t, false, checkIDTaken)
}
func TestCluster_Resources(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
client := mockClient()
ctx := context.Background()
cluster, err := client.Cluster(ctx)
assert.Nil(t, err)
// json unmarshaling tests
rs, err := cluster.Resources(ctx)
assert.Equal(t, 20, len(rs))
// type param test
rs, err = cluster.Resources(ctx, "node")
assert.Equal(t, 1, len(rs))
}