forked from infobloxopen/infoblox-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
object_manager_netview_test.go
152 lines (128 loc) · 4.47 KB
/
object_manager_netview_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
package ibclient
import (
"fmt"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Object Manager: network view", func() {
Describe("Create Network View", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
netviewName := "Default View"
comment := "test client"
setEas := EA{"Cloud API Owned": true}
fakeRefReturn := "networkview/ZG5zLm5ldHdvcmtfdmlldyQyMw:global_view/false"
nvFakeConnector := &fakeConnector{
createObjectObj: NewNetworkView(netviewName, comment, setEas, ""),
resultObject: NewNetworkView(netviewName, comment, setEas, fakeRefReturn),
fakeRefReturn: fakeRefReturn,
}
objMgr := NewObjectManager(nvFakeConnector, cmpType, tenantID)
var actualNetworkView *NetworkView
var err error
It("should pass expected NetworkView Object to CreateObject", func() {
actualNetworkView, err = objMgr.CreateNetworkView(netviewName, comment, setEas)
})
It("should return expected NetworkView Object", func() {
Expect(actualNetworkView).To(Equal(nvFakeConnector.resultObject))
Expect(err).To(BeNil())
})
})
Describe("Get Network View", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
netviewName := "Default View"
fakeRefReturn := "networkview/ZG5zLm5ldHdvcmtfdmlldyQyMw:global_view/false"
queryParams := NewQueryParams(
false,
map[string]string{
"name": netviewName,
})
nvFakeConnector := &fakeConnector{
getObjectObj: NewEmptyNetworkView(),
getObjectQueryParams: queryParams,
getObjectRef: "",
resultObject: []NetworkView{*NewNetworkView(netviewName, "", nil, fakeRefReturn)},
}
objMgr := NewObjectManager(nvFakeConnector, cmpType, tenantID)
var actualNetworkView *NetworkView
var err error
It("should pass expected NetworkView Object to GetObject", func() {
actualNetworkView, err = objMgr.GetNetworkView(netviewName)
})
It("should return expected NetworkView Object", func() {
Expect(*actualNetworkView).To(Equal(nvFakeConnector.resultObject.([]NetworkView)[0]))
Expect(err).To(BeNil())
})
})
Describe("Update Network View", func() {
var (
err error
objMgr IBObjectManager
conn *fakeConnector
ref string
actualObj *NetworkView
)
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
netviewName := "default"
refBase := "ZG5zLm5ldHdvcmtfdmlldyQyMw"
It("Updating comment and EAs", func() {
ref = fmt.Sprintf("networkview/%s:%s", refBase, netviewName)
initialEas := EA{
"ea0": "ea0_old_value",
"ea1": "ea1_old_value",
"ea3": "ea3_value",
"ea4": "ea4_value",
"ea5": "ea5_old_value"}
initObj := NewNetworkView(netviewName, "old comment", initialEas, ref)
setEas := EA{
"ea0": "ea0_old_value",
"ea1": "ea1_new_value",
"ea2": "ea2_new_value",
"ea5": "ea5_old_value"}
expectedEas := setEas
getObjIn := NewEmptyNetworkView()
comment := "test comment 1"
updateNetviewName := "default_view"
updatedRef := fmt.Sprintf("networkview/%s:%s", refBase, updateNetviewName)
updateObjIn := NewNetworkView(updateNetviewName, comment, expectedEas, ref)
expectedObj := NewNetworkView(updateNetviewName, comment, expectedEas, updatedRef)
conn = &fakeConnector{
getObjectObj: getObjIn,
getObjectQueryParams: NewQueryParams(false, nil),
getObjectRef: ref,
getObjectError: nil,
resultObject: initObj,
updateObjectObj: updateObjIn,
updateObjectRef: ref,
updateObjectError: nil,
fakeRefReturn: updatedRef,
}
objMgr = NewObjectManager(conn, cmpType, tenantID)
actualObj, err = objMgr.UpdateNetworkView(ref, updateNetviewName, comment, setEas)
Expect(err).To(BeNil())
Expect(actualObj).To(BeEquivalentTo(expectedObj))
})
})
Describe("Delete Network View", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
fakeRefReturn := "networkview/ZG5zLm5ldHdvcmtfdmlldyQyMw:global_view/false"
deleteRef := fakeRefReturn
nwFakeConnector := &fakeConnector{
deleteObjectRef: deleteRef,
fakeRefReturn: fakeRefReturn,
}
objMgr := NewObjectManager(nwFakeConnector, cmpType, tenantID)
var actualRef string
var err error
It("should pass expected Network View Ref to DeleteObject", func() {
actualRef, err = objMgr.DeleteNetworkView(deleteRef)
})
It("should return expected Network View Ref", func() {
Expect(actualRef).To(Equal(fakeRefReturn))
Expect(err).To(BeNil())
})
})
})