Skip to content

Commit

Permalink
Merge pull request #35 from e-XpertSolutions/feature-branch.34
Browse files Browse the repository at this point in the history
f5/health_check: fix panic in SyncStatusDetails
  • Loading branch information
gilliek authored May 3, 2022
2 parents a458275 + 259f191 commit 74ffe27
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
6 changes: 5 additions & 1 deletion f5/health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ func (c *Client) SyncStatusDetails() (SyncStatusResp, error) {
return syncStat, fmt.Errorf("could not retrieve group name")
}

syncStat.GroupName = description[:strings.Index(description, "(")-1]
if pos := strings.Index(description, "("); pos > 0 {
syncStat.GroupName = description[:pos-1]
} else {
syncStat.GroupName = "unknown"
}

return syncStat, nil
}
32 changes: 32 additions & 0 deletions f5/health_check_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package f5

import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
)

func TestClient_SyncStatusDetails_Bug34(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, `{"kind":"tm:cm:sync-status:sync-statusstats","selfLink":"https://localhost/mgmt/tm/cm/sync-status?ver=14.1.4.6","entries":{"https://localhost/mgmt/tm/cm/sync-status/0":{"nestedStats":{"entries":{"color":{"description":"green"},"https://localhost/mgmt/tm/cm/syncStatus/0/details":{"nestedStats":{"entries":{"https://localhost/mgmt/tm/cm/syncStatus/0/details/0":{"nestedStats":{"entries":{"details":{"description":"i5800b-1.labo.e-xpertsolutions.lan: connected"}}}},"https://localhost/mgmt/tm/cm/syncStatus/0/details/1":{"nestedStats":{"entries":{"details":{"description":" All devices in the device group are in sync"}}}},"https://localhost/mgmt/tm/cm/syncStatus/0/details/2":{"nestedStats":{"entries":{"details":{"description":"In Sync): All devices in the device group are in sync"}}}},"https://localhost/mgmt/tm/cm/syncStatus/0/details/3":{"nestedStats":{"entries":{"details":{"description":" (In Sync): All devices in the device group are in sync"}}}},"https://localhost/mgmt/tm/cm/syncStatus/0/details/4":{"nestedStats":{"entries":{"details":{"description":"datasync-global-dg (In Sync): All devices in the device group are in sync"}}}},"https://localhost/mgmt/tm/cm/syncStatus/0/details/5":{"nestedStats":{"entries":{"details":{"description":"device_trust_group (In Sync): All devices in the device group are in sync"}}}}}}},"mode":{"description":"high-availability"},"status":{"description":"offline"},"summary":{"description":"All devices in the device group are in sync"}}}}}}`)
}))
defer ts.Close()

c := &Client{
baseURL: ts.URL,
c: http.Client{},
makeAuth: authFunc(func(req *http.Request) error {
return nil
}),
}

resp, err := c.SyncStatusDetails()
if err != nil {
t.Errorf("unexpected error: %v", err)
}

if resp.GroupName != "unknown" {
t.Errorf("unexpected group name: %v", resp.GroupName)
}
}

0 comments on commit 74ffe27

Please sign in to comment.