Skip to content

Commit 00ebf35

Browse files
authored
Merge pull request #25 from kubescape/adding-tests
Adding unittests
2 parents 5b062de + 1e61041 commit 00ebf35

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

pkg/client/v1/kscloudapi_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,39 @@ func withAPIGarbled(enabled bool) mockAPIOption {
402402
o.withGarbled = enabled
403403
}
404404
}
405+
406+
func TestGetExceptionsURL(t *testing.T) {
407+
ks, err := NewKSCloudAPI("https://api.kubescape.com", "https://api.google.com/report", "00000000-0000-0000-0000-000000000000", "00000000-0000-0000-0000-000000000000")
408+
if err != nil {
409+
t.Fatal(err)
410+
}
411+
412+
tests := []struct {
413+
name string
414+
clusterName string
415+
expectedURL string
416+
}{
417+
{
418+
name: "should return correct URL with given cluster name",
419+
clusterName: "testCluster",
420+
expectedURL: "https://api.kubescape.com/api/v1/controlExceptions?customerGUID=00000000-0000-0000-0000-000000000000&gitRegoStoreVersion=v2",
421+
},
422+
{
423+
name: "should return correct URL with different cluster name",
424+
clusterName: "anotherTestCluster",
425+
expectedURL: "https://api.kubescape.com/api/v1/controlExceptions?customerGUID=00000000-0000-0000-0000-000000000000&gitRegoStoreVersion=v2",
426+
},
427+
{
428+
name: "should return correct URL when cluster name is empty",
429+
clusterName: "",
430+
expectedURL: "https://api.kubescape.com/api/v1/controlExceptions?customerGUID=00000000-0000-0000-0000-000000000000&gitRegoStoreVersion=v2",
431+
},
432+
}
433+
434+
for _, tt := range tests {
435+
t.Run(tt.name, func(t *testing.T) {
436+
resultURL := ks.getExceptionsURL(tt.clusterName)
437+
require.Equal(t, tt.expectedURL, resultURL)
438+
})
439+
}
440+
}

0 commit comments

Comments
 (0)