-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvdc_test.go
86 lines (83 loc) · 3.5 KB
/
vdc_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
package vcdusage_test
import (
"testing"
"github.com/stellaraf/go-vcdusage"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_VDCs(t *testing.T) {
u, err := vcdusage.ParseURL(Env.URL)
require.NoError(t, err)
client, err := vcdusage.New(
vcdusage.Insecure(),
vcdusage.URL(u),
vcdusage.Username(Env.Username),
vcdusage.Password(Env.Password),
)
require.NoError(t, err)
vdcs, err := client.VDCs(Env.OrgID)
require.NoError(t, err)
for _, vdc := range vdcs {
vdc := vdc
t.Run(vdc.Obj.Vdc.Name, func(t *testing.T) {
t.Parallel()
cores := vdc.CoreCount()
mem := vdc.Memory()
stor := vdc.Storage()
vmCount := vdc.VMCount()
poweredOn := vdc.PoweredOnVMCount()
assert.NotZero(t, cores, "core count zero")
assert.NotZero(t, mem.Float64(), "memory zero")
assert.NotZero(t, stor.Float64(), "storage zero")
assert.Equal(t, Env.Cores, cores, "mismatching core count: %v != %v", Env.Cores, cores)
assert.Equal(t, Env.Memory, mem.GB(), "mismatching memory: %v != %v", Env.Memory, mem.GB())
assert.Equal(t, Env.Storage, stor.GB(), "mismatching storage: %v != %v", Env.Storage, stor.GB())
assert.Equal(t, Env.VMCount, vmCount, "mismatching VM count: %v != %v", Env.VMCount, vmCount)
assert.Equal(t, Env.VMCount, poweredOn, "mismatching powered-on VM count: %v != %v", Env.VMCount, vmCount)
})
}
t.Run("individual VDC", func(t *testing.T) {
t.Parallel()
vdc, err := client.VDC(Env.OrgID, Env.VdcID)
require.NoError(t, err)
cores := vdc.CoreCount()
mem := vdc.Memory()
stor := vdc.Storage()
vmCount := vdc.VMCount()
poweredOn := vdc.PoweredOnVMCount()
assert.NotZero(t, cores, "core count zero")
assert.NotZero(t, mem.Float64(), "memory zero")
assert.NotZero(t, stor.Float64(), "storage zero")
assert.Equal(t, Env.Cores, cores, "mismatching core count: %v != %v", Env.Cores, cores)
assert.Equal(t, Env.Memory, mem.GB(), "mismatching memory: %v != %v", Env.Memory, mem.GB())
assert.Equal(t, Env.Storage, stor.GB(), "mismatching storage: %v != %v", Env.Storage, stor.GB())
assert.Equal(t, Env.VMCount, vmCount, "mismatching VM count: %v != %v", Env.VMCount, vmCount)
assert.Equal(t, Env.VMCount, poweredOn, "mismatching powered-on VM count: %v != %v", Env.VMCount, vmCount)
})
t.Run("all VDCs", func(t *testing.T) {
t.Parallel()
cores := vdcs.CoreCount()
mem := vdcs.Memory()
stor := vdcs.Storage()
vmCount := vdcs.VMCount()
poweredOn := vdcs.PoweredOnVMCount()
assert.NotZero(t, cores, "core count zero")
assert.NotZero(t, mem.Float64(), "memory zero")
assert.NotZero(t, stor.Float64(), "storage zero")
assert.Equal(t, Env.Cores, cores, "mismatching core count: %v != %v", Env.Cores, cores)
assert.Equal(t, Env.Memory, mem.GB(), "mismatching memory: %v != %v", Env.Memory, mem.GB())
assert.Equal(t, Env.Storage, stor.GB(), "mismatching storage: %v != %v", Env.Storage, stor.GB())
assert.Equal(t, Env.VMCount, vmCount, "mismatching VM count: %v != %v", Env.VMCount, vmCount)
assert.Equal(t, Env.VMCount, poweredOn, "mismatching powered-on VM count: %v != %v", Env.VMCount, vmCount)
})
t.Run("all powered off", func(t *testing.T) {
t.Parallel()
vdc, err := client.VDC(Env.OrgID2, Env.VdcID2)
require.NoError(t, err)
stor := vdc.StorageAll()
vmCount := vdc.VMCount()
assert.NotZero(t, stor.Float64(), "storage zero")
assert.Equal(t, Env.Storage2, stor.GB(), "mismatching storage: %v != %v", Env.Storage2, stor.GB())
assert.Equal(t, Env.VMCount2, vmCount, "mismatching VM count: %v != %v", Env.VMCount2, vmCount)
})
}