From 4ed2e10ac340fcc22fc8b5860173ad2e4f397ada Mon Sep 17 00:00:00 2001 From: Akilan Selvacoumar Date: Sun, 22 Aug 2021 18:49:49 +0400 Subject: [PATCH] added method to check if the ID belongs to a group or container --- client/TrackContainers.go | 11 +++++++++++ client/TrackContianers_test.go | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/client/TrackContainers.go b/client/TrackContainers.go index 389675d..b61d7f2 100644 --- a/client/TrackContainers.go +++ b/client/TrackContainers.go @@ -162,4 +162,15 @@ func GetContainerInformation(ID string) (*TrackContainer, error) { } } return nil, errors.New("Container not found. ") +} + +// CheckID Checks if the ID belongs to a group or a single container +func CheckID(ID string) (string,error) { + // For group checks if the 1st characters is "grp" + if ID[0:3] == "grp" { + return "group", nil + } else { + return "container", nil + } + return "",nil } \ No newline at end of file diff --git a/client/TrackContianers_test.go b/client/TrackContianers_test.go index 0f1f7c4..ec8a90d 100644 --- a/client/TrackContianers_test.go +++ b/client/TrackContianers_test.go @@ -102,3 +102,19 @@ func TestRemoveTrackedContainer(t *testing.T) { t.Fail() } } + +// Test function that checks if the ID belongs to +// a group or container running +func TestCheckID(t *testing.T) { + id := "grp123" + checkID, err := CheckID(id) + if err != nil { + fmt.Println(err) + t.Fail() + } + if checkID == "group" { + fmt.Println("pass") + } else { + t.Fail() + } +}