Skip to content

Commit

Permalink
added unit test cases for Forward zone. (infobloxopen#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
JchhatbarInfoblox authored and Aish-sp committed Jun 20, 2024
1 parent 126653f commit f3baeab
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 88 deletions.
209 changes: 121 additions & 88 deletions object_manager_forward_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,30 @@ var _ = Describe("Object Manager: forward zone", func() {
tenantID := "01234567890abcdef01234567890abcdef"
comment := "test client"
disable := false
//eas := EA{"Cloud API Owned": true}
forwardTo := []NameServer{{Name: "fz1.test.com", Address: "10.0.0.1"}, {Name: "fz2.test.com", Address: "10.0.0.2"}}
forwardTo := NullForwardTo{
ForwardTo: []NameServer{
{Name: "fz1.test.com", Address: "10.0.0.1"},
{Name: "fz2.test.com", Address: "10.0.0.2"},
},
IsNull: false,
}
fqdn := "test.fz.com"
fakeRefReturn := fmt.Sprintf("record:txt/ZG5zLmJpbmRfY25h:%s/%20%20", fqdn)
fakeRefReturn := fmt.Sprintf("zone_forward/ZG5zLmhvc3QkLZhd3QuaDE:%s/%20%20", fqdn)

conn := &fakeConnector{
createObjectObj: NewZoneForward("comment", false, nil, forwardTo, false, nil, fqdn, "", "", ""),
createObjectObj: NewZoneForward(comment, false, nil, forwardTo, false, nil, fqdn, "", "", "", "", ""),
getObjectRef: fakeRefReturn,
getObjectObj: NewEmptyZoneForward(),
getObjectQueryParams: NewQueryParams(false, nil),
resultObject: NewZoneForward("comment", false, nil, forwardTo, false, nil, fqdn, "", "", ""),
resultObject: NewZoneForward(comment, false, nil, forwardTo, false, nil, fqdn, "", "", "", fakeRefReturn, ""),
fakeRefReturn: fakeRefReturn,
}
objMgr := NewObjectManager(conn, cmpType, tenantID)

var actualRecord *ZoneForward
var err error
It("should pass expected Forward Zone Object to CreateObject", func() {
actualRecord, err = objMgr.CreateZoneForward(comment, disable, nil, forwardTo, false, nil, fqdn, "", "", "")
})
It("should return expected Forward Zone Object", func() {
actualRecord, err = objMgr.CreateZoneForward(comment, disable, nil, forwardTo, false, nil, fqdn, "", "", "", "")
Expect(actualRecord).To(Equal(conn.resultObject))
Expect(err).To(BeNil())
})
Expand All @@ -43,128 +46,160 @@ var _ = Describe("Object Manager: forward zone", func() {
tenantID := "01234567890abcdef01234567890abcdef"
comment := "test client"
disable := false
//eas := EA{"Cloud API Owned": true}
forwardTo := []NameServer{{Name: "fz1.test.com", Address: "10.0.0.1"}, {Name: "fz2.test.com", Address: "10.0.0.2"}}
fqdn := "test.fz.com"
fakeRefReturn := fmt.Sprintf("record:txt/ZG5zLmJpbmRfY25h:%s/%20%20", fqdn)
forwardTo := NullForwardTo{
ForwardTo: []NameServer{
{Name: "fz1.test.com", Address: "10.0.0.1"},
{Name: "fz2.test.com", Address: "10.0.0.2"},
},
IsNull: false,
}
fqdn := "" //"test.fz.com"
fakeRefReturn := fmt.Sprintf("zone_forward/ZG5zLmhvc3QkLZhd3QuaDE:%s/%20%20", fqdn)

conn := &fakeConnector{
createObjectObj: NewZoneForward("comment", false, nil, forwardTo, false, nil, "", "", "", ""),
createObjectObj: NewZoneForward(comment, false, nil, forwardTo, false, nil, "", "", "", "", "", ""),
getObjectRef: fakeRefReturn,
getObjectObj: NewEmptyZoneForward(),
getObjectQueryParams: NewQueryParams(false, nil),
resultObject: NewZoneForward("comment", false, nil, forwardTo, false, nil, fqdn, "", "", ""),
resultObject: NewZoneForward(comment, false, nil, forwardTo, false, nil, fqdn, "", "", "", fakeRefReturn, ""),
fakeRefReturn: fakeRefReturn,
createObjectError: fmt.Errorf("FQDN is required to create a forward zone"),
}
objMgr := NewObjectManager(conn, cmpType, tenantID)

var actualRecord *ZoneForward
var err error
It("should pass expected Forward Zone Object to CreateObject", func() {
actualRecord, err = objMgr.CreateZoneForward(comment, disable, nil, forwardTo, false, nil, fqdn, "", "", "")
})
It("should return expected Forward Zone Object", func() {
actualRecord, err = objMgr.CreateZoneForward(comment, disable, nil, forwardTo, false, nil, fqdn, "", "", "", "")
Expect(actualRecord).To(BeNil())
Expect(err).To(Equal(conn.createObjectError))
})
})

Describe("Get forward zone", func() {
Describe("Get forward zone test", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
comment := "test client"
view := "default"
//eas := EA{"Cloud API Owned": true}
forwardTo := []NameServer{{Name: "fz1.test.com", Address: "10.0.0.1"}, {Name: "fz2.test.com", Address: "10.0.0.2"}}

forwardTo := NullForwardTo{
ForwardTo: []NameServer{
{Name: "fz1.test.com", Address: "10.0.0.1"},
{Name: "fz2.test.com", Address: "10.0.0.2"},
},
IsNull: false,
}
fqdn := "test.fz.com"
fakeRefReturn := fmt.Sprintf("record:txt/ZG5zLmJpbmRfY25h:%s/%20%20", fqdn)

queryParams := NewQueryParams(
false,
map[string]string{
"fqdn": fqdn,
"comment": comment,
"view": view,
})
fakeRefReturn := fmt.Sprintf("zone_forward/ZG5zLmhvc3QkLZhd3QuaDE:%s/%s", fqdn, view)

filters := map[string]string{
"fqdn": fqdn,
"view": view,
"comment": comment,
}

queryParams := NewQueryParams(false, filters)
conn := &fakeConnector{
createObjectObj: NewZoneForward("comment", false, nil, forwardTo, false, nil, "", "", "", ""),
createObjectObj: NewZoneForward(comment, false, nil, forwardTo, false, nil, fqdn, "", view, "", fakeRefReturn, ""),
getObjectRef: "",
getObjectObj: NewEmptyZoneForward(),
getObjectQueryParams: queryParams,
resultObject: []ZoneForward{*NewZoneForward("comment", false, nil, forwardTo, false, nil, fqdn, "", "", "")},
resultObject: []ZoneForward{*NewZoneForward(comment, false, nil, forwardTo, false, nil, fqdn, "", view, "", fakeRefReturn, "")},
fakeRefReturn: fakeRefReturn,
getObjectQueryParams: queryParams,
}
objMgr := NewObjectManager(conn, cmpType, tenantID)

conn.resultObject.([]ZoneForward)[0].Ref = fakeRefReturn

var actualRecord []ZoneForward
var err error
It("should pass expected Forward Zone Object to GetObject", func() {
actualRecord, err = objMgr.GetZoneForwardFilters(*queryParams)
actualRecord, err = objMgr.GetZoneForwardFilters(queryParams)
Expect(err).To(BeNil())
Expect(actualRecord[0]).To(Equal(conn.resultObject.([]ZoneForward)[0]))
})
It("should return expected Forward Zone Object", func() {
Expect(actualRecord).To(Equal(conn.resultObject.([]ZoneForward)))
})

Describe("Get forward zone by Ref", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
comment := "test client"
view := "default"
//eas := EA{"Cloud API Owned": true}
//forwardTo := []NameServer{{Name: "fz1.test.com", Address: "10.0.0.1"}, {Name: "fz2.test.com", Address: "10.0.0.2"}}
forwardTo := NullForwardTo{
ForwardTo: []NameServer{
{Name: "fz1.test.com", Address: "10.0.0.1"},
{Name: "fz2.test.com", Address: "10.0.0.2"},
},
IsNull: false,
}
fqdn := "test12.ex.com"
fakeRefReturn := fmt.Sprintf("zone_forward/ZG5zLm5ldHdvcmtfdmlldyQyMw:%s/%s", fqdn, view)
conn := &fakeConnector{
getObjectRef: fakeRefReturn,
getObjectObj: NewEmptyZoneForward(),
getObjectQueryParams: NewQueryParams(false, nil),
resultObject: NewZoneForward(comment, false, nil, forwardTo, false, nil, fqdn, "", view, "", fakeRefReturn, ""),
fakeRefReturn: fakeRefReturn,
}
objMgr := NewObjectManager(conn, cmpType, tenantID)

conn.resultObject.(*ZoneForward).Ref = fakeRefReturn

var actualRecord *ZoneForward
var err error
It("should pass expected Forward Zone Ref to GetObject", func() {
actualRecord, err = objMgr.GetZoneForwardByRef(fakeRefReturn)
Expect(err).To(BeNil())
Expect(actualRecord).To(Equal(conn.resultObject))
})
})

//Describe("Update Zone Forward", func() {
// var (
// err error
// objMgr IBObjectManager
// conn *fakeConnector
// ref string
// actualObj *ZoneForward
// )
//
//TODO: Implement update forward zone properly

//Describe("Update Forward Zone", func() {
// cmpType := "Docker"
// tenantID := "01234567890abcdef01234567890abcdef"
// fqdn := "test.fz.com"
// refBase := "ZG5zLm5ldHdvcmtfdmlldyQyMw"
//
// It("Updating comment and EAs", func() {
// ref = fmt.Sprintf("zone_forward/%s:%s", refBase, fqdn)
// initialEas := EA{
// "ea0": "ea0_old_value",
// "ea1": "ea1_old_value",
// "ea3": "ea3_value",
// "ea4": "ea4_value",
// "ea5": "ea5_old_value"}
// initObj := NewZoneForward("comment", false, initialEas,
// []NameServer{{Address: "1.2.3.4", Name: "fz1.test.com"}}, false, nil, fqdn, "", "", "")
// initComment := "comment"
// updatedComment := "updated comment"
// disable := true
// forwardTo := NullForwardTo{
// ForwardTo: []NameServer{
// {Name: "fz1.test.com", Address: "10.0.0.1"},
// {Name: "fz2.test.com", Address: "10.0.0.2"},
// },
// IsNull: false,
// }
// view := "default"
// fqdn := "updated.fz.com"
// initRef := fmt.Sprintf("zone_forward/ZG5zLmhvc3QkLZhd3QuaDE:%s/%s", fqdn, view)
// zoneFormat := "Forward"
// updatedRef := initRef
//
// setEas := EA{
// "ea0": "ea0_old_value",
// "ea1": "ea1_new_value",
// "ea2": "ea2_new_value",
// "ea5": "ea5_old_value"}
// expectedEas := setEas
// initObj := NewZoneForward(initComment, disable, nil, forwardTo, false, nil, fqdn, "", view, zoneFormat, initRef, "")
// updatedObj := NewZoneForward(updatedComment, disable, nil, forwardTo, false, nil, fqdn, "", view, zoneFormat, updatedRef, "")
// expectedObj := NewZoneForward(updatedComment, disable, nil, forwardTo, false, nil, fqdn, "", view, zoneFormat, updatedRef, "")
//
// getObjIn := NewEmptyZoneForward()
// conn := &fakeConnector{
// getObjectObj: NewEmptyZoneForward(),
// getObjectQueryParams: NewQueryParams(false, nil),
// getObjectRef: initRef,
// getObjectError: nil,
// resultObject: initObj,
//
// comment := "test comment 1"
// updatedRef := fmt.Sprintf("zone_forward/%s:%s", refBase, fqdn)
// updateObjIn := NewNetworkView(updateNetviewName, comment, expectedEas, ref)
// updateObjectObj: updatedObj,
// updateObjectRef: initRef,
// updateObjectError: nil,
// }
// objMgr := NewObjectManager(conn, cmpType, tenantID)
//
// 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)
// var actualRecord *ZoneForward
// var err error
// It("should pass expected Forward Zone Object to UpdateObject", func() {
// actualRecord, err = objMgr.UpdateZoneForward(initRef, updatedComment, disable, nil, forwardTo, false, nil, "", "")
// Expect(actualRecord).To(BeEquivalentTo(expectedObj))
// Expect(err).To(BeNil())
// Expect(actualObj).To(BeEquivalentTo(expectedObj))
// })
//})

Expand All @@ -184,8 +219,6 @@ var _ = Describe("Object Manager: forward zone", func() {
var err error
It("should pass expected zone forward Ref to DeleteObject", func() {
actualRef, err = objMgr.DeleteZoneForward(deleteRef)
})
It("should return expected zone forward Ref", func() {
Expect(actualRef).To(Equal(fakeRefReturn))
Expect(err).To(BeNil())
})
Expand Down
4 changes: 4 additions & 0 deletions object_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func (c *fakeConnector) GetObject(obj IBObject, ref string, qp *QueryParams, res
*res.(*[]RecordA) = c.resultObject.([]RecordA)
case *RecordMX:
*res.(*[]RecordMX) = c.resultObject.([]RecordMX)
case *ZoneForward:
*res.(*[]ZoneForward) = c.resultObject.([]ZoneForward)
}
} else {
switch obj.(type) {
Expand Down Expand Up @@ -121,6 +123,8 @@ func (c *fakeConnector) GetObject(obj IBObject, ref string, qp *QueryParams, res
*res.(*[]Dns) = c.resultObject.([]Dns)
case *Dhcp:
*res.(*[]Dhcp) = c.resultObject.([]Dhcp)
case *ZoneForward:
*res.(**ZoneForward) = c.resultObject.(*ZoneForward)
}
}

Expand Down

0 comments on commit f3baeab

Please sign in to comment.