-
Notifications
You must be signed in to change notification settings - Fork 88
/
object_manager_cname-record_test.go
166 lines (149 loc) · 5.53 KB
/
object_manager_cname-record_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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package ibclient
import (
"fmt"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Object Manager: CNAME-record", func() {
Describe("Allocate CNAME Record ", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
canonical := "test-canonical.domain.com"
dnsView := "default"
vmID := "93f9249abc039284"
vmName := "dummyvm"
recordName := "test.domain.com"
useTtl := false
ttl := uint32(0)
comment := "test CNAME record creation"
fakeRefReturn := fmt.Sprintf("record:cname/ZG5zLmJpbmRfY25h:%s/%20%20", recordName)
eas := EA{"VM Name": vmName, "VM ID": vmID}
conn := &fakeConnector{
createObjectObj: NewRecordCNAME(dnsView, canonical, recordName, useTtl, ttl, comment, eas, ""),
getObjectRef: fakeRefReturn,
getObjectObj: NewEmptyRecordCNAME(),
getObjectQueryParams: NewQueryParams(false, nil),
resultObject: NewRecordCNAME(dnsView, canonical, recordName, useTtl, ttl, comment, eas, fakeRefReturn),
fakeRefReturn: fakeRefReturn,
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
var actualRecord *RecordCNAME
var err error
It("should pass expected CNAME record Object to CreateObject", func() {
actualRecord, err = objMgr.CreateCNAMERecord(dnsView, canonical, recordName, useTtl, ttl, comment, eas)
})
It("should return expected CNAME record Object", func() {
Expect(actualRecord).To(Equal(conn.resultObject))
Expect(err).To(BeNil())
})
})
Describe("Negative case: returns an error message if required fields are not passed", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
dnsView := "default"
vmID := "93f9249abc039284"
vmName := "dummyvm"
useTtl := false
ttl := uint32(0)
comment := "test CNAME record creation"
eas := EA{"VM Name": vmName, "VM ID": vmID}
conn := &fakeConnector{
createObjectObj: NewRecordCNAME(dnsView, "", "", useTtl, ttl, comment, eas, ""),
createObjectError: fmt.Errorf("canonical name and record name fields are required to create a CNAME record"),
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
var actualRecord, expectedObj *RecordCNAME
var err error
It("should pass expected CNAME record Object to CreateObject", func() {
actualRecord, err = objMgr.CreateCNAMERecord(dnsView, "", "", useTtl, ttl, comment, eas)
})
It("should return expected CNAME record Object", func() {
Expect(actualRecord).To(Equal(expectedObj))
Expect(err).To(Equal(conn.createObjectError))
})
})
Describe("Get CNAME Record ", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
canonical := "test-canonical.domain.com"
dnsView := "default"
recordName := "test.domain.com"
useTtl := false
ttl := uint32(0)
fakeRefReturn := fmt.Sprintf("record:cname/ZG5zLmJpbmRfY25h:%s/%20%20", recordName)
queryParams := NewQueryParams(
false,
map[string]string{
"view": dnsView,
"canonical": canonical,
"name": recordName,
})
conn := &fakeConnector{
getObjectRef: "",
getObjectObj: NewEmptyRecordCNAME(),
getObjectQueryParams: queryParams,
resultObject: []RecordCNAME{*NewRecordCNAME(dnsView, canonical, recordName, useTtl, ttl, "", nil, fakeRefReturn)},
fakeRefReturn: fakeRefReturn,
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
var actualRecord *RecordCNAME
var err error
It("should pass expected CNAME record Object to CreateObject", func() {
actualRecord, err = objMgr.GetCNAMERecord(dnsView, canonical, recordName)
})
It("should return expected CNAME record Object", func() {
Expect(*actualRecord).To(Equal(conn.resultObject.([]RecordCNAME)[0]))
Expect(err).To(BeNil())
})
})
Describe("Negative case: return an error mesage when the required fields to get a unique record are not passed", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
canonical := "test-canonical.domain.com"
recordName := "test.domain.com"
queryParams := NewQueryParams(
false,
map[string]string{
"canonical": canonical,
"name": recordName,
})
conn := &fakeConnector{
getObjectRef: "",
getObjectObj: NewEmptyRecordCNAME(),
getObjectQueryParams: queryParams,
getObjectError: fmt.Errorf("DNS view, canonical name and record name of the record are required to retreive a unique CNAME record"),
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
var actualRecord, expectedObj *RecordCNAME
var err error
expectedObj = nil
It("should pass expected CNAME record Object to CreateObject", func() {
actualRecord, err = objMgr.GetCNAMERecord("", canonical, recordName)
})
It("should return expected CNAME record Object", func() {
Expect(actualRecord).To(Equal(expectedObj))
Expect(err).To(Equal(conn.getObjectError))
})
})
Describe("Delete CNAME Record", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
recordName := "test"
deleteRef := fmt.Sprintf("record:CNAME/ZG5zLmJpbmRfY25h:%s/%20%20", recordName)
fakeRefReturn := deleteRef
nwFakeConnector := &fakeConnector{
deleteObjectRef: deleteRef,
fakeRefReturn: fakeRefReturn,
}
objMgr := NewObjectManager(nwFakeConnector, cmpType, tenantID)
var actualRef string
var err error
It("should pass expected CNAME record Ref to DeleteObject", func() {
actualRef, err = objMgr.DeleteCNAMERecord(deleteRef)
})
It("should return expected CNAME record Ref", func() {
Expect(actualRef).To(Equal(fakeRefReturn))
Expect(err).To(BeNil())
})
})
})