Skip to content

Commit

Permalink
modify splitParent function, document test
Browse files Browse the repository at this point in the history
  • Loading branch information
Didainius committed Jun 12, 2019
1 parent 8d88736 commit 1dab111
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
23 changes: 12 additions & 11 deletions govcd/api_vcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,18 @@ func (vcd *TestVCD) infoCleanup(format string, args ...interface{}) {
}

// Gets the two components of a "parent" string, as passed to AddToCleanupList
func splitParent(parent string, separator string) (first, second string) {
func splitParent(parent string, separator string) (first, second, third string) {
strList := strings.Split(parent, separator)
if len(strList) != 2 {
return "", ""
if len(strList) < 2 && len(strList) > 3 {
return "", "", ""
}
first = strList[0]
second = strList[1]

if len(strList) == 3 {
third = strList[2]
}

return
}

Expand Down Expand Up @@ -440,7 +445,7 @@ func (vcd *TestVCD) removeLeftoverEntities(entity CleanupEntity) {
//TODO: find an easy way of undoing edge GW customization
return
case "network":
orgName, vdcName := splitParent(entity.Parent, "|")
orgName, vdcName, _ := splitParent(entity.Parent, "|")
if orgName == "" || vdcName == "" {
vcd.infoCleanup(splitParentNotFound, entity.Parent)
return
Expand Down Expand Up @@ -480,7 +485,7 @@ func (vcd *TestVCD) removeLeftoverEntities(entity CleanupEntity) {
vcd.infoCleanup("removeLeftoverEntries: [ERROR] No VDC and ORG provided for media '%s'\n", entity.Name)
return
}
orgName, vdcName := splitParent(entity.Parent, "|")
orgName, vdcName, _ := splitParent(entity.Parent, "|")
if orgName == "" || vdcName == "" {
vcd.infoCleanup(splitParentNotFound, entity.Parent)
return
Expand Down Expand Up @@ -612,11 +617,7 @@ func (vcd *TestVCD) removeLeftoverEntities(entity CleanupEntity) {
return
}

splitParent := strings.Split(entity.Parent, "|")
if len(splitParent) != 3 {
vcd.infoCleanup("removeLeftoverEntries: [ERROR] Incorrent parent info specified '%s'\n", entity.Parent)
}
orgName, vdcName, edgeName := splitParent[0], splitParent[1], splitParent[2]
orgName, vdcName, edgeName := splitParent(entity.Parent, "|")

org, err := GetOrgByName(vcd.client, orgName)
if err != nil {
Expand All @@ -634,7 +635,7 @@ func (vcd *TestVCD) removeLeftoverEntities(entity CleanupEntity) {

err = edge.DeleteLBServiceMonitor(&types.LBMonitor{Name: entity.Name})
if err != nil {
vcd.infoCleanup(notFoundMsg, entity.Name, err)
vcd.infoCleanup(notFoundMsg, entity.EntityType, entity.Name)
return
}

Expand Down
10 changes: 10 additions & 0 deletions govcd/lbservicemonitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ import (
. "gopkg.in/check.v1"
)

// Test_LBServiceMonitor tests CRUD methods for load balancer service monitor.
// The following things are tested:
// Creation of load balancer service monitor
// Read load balancer by both ID and Name (service monitor name must be unique in single edge gateway)
// Update - change a single field and compare that configuration and result objects are deeply equal
// Update - try and fail to update without mandatory field
// Delete
func (vcd *TestVCD) Test_LBServiceMonitor(check *C) {
if vcd.config.VCD.EdgeGateway == "" {
check.Skip("Skipping test because no edge gateway given")
Expand Down Expand Up @@ -58,6 +65,9 @@ func (vcd *TestVCD) Test_LBServiceMonitor(check *C) {
check.Assert(err, IsNil)
check.Assert(updatedLBMonitor.Timeout, Equals, 35)

// Verify that updated monitor and it's configuration are identical
check.Assert(updatedLBMonitor, DeepEquals, lbMonitorByID)

// Update should fail without name
lbMonitorByID.Name = ""
_, err = edge.UpdateLBServiceMonitor(lbMonitorByID)
Expand Down

0 comments on commit 1dab111

Please sign in to comment.