summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/api/defhandler_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/k8splugin/api/defhandler_test.go')
-rw-r--r--src/k8splugin/api/defhandler_test.go80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/k8splugin/api/defhandler_test.go b/src/k8splugin/api/defhandler_test.go
index 077d0708..dcfea1de 100644
--- a/src/k8splugin/api/defhandler_test.go
+++ b/src/k8splugin/api/defhandler_test.go
@@ -240,6 +240,86 @@ func TestRBDefListVersionsHandler(t *testing.T) {
}
}
+func TestRBDefListAllHandler(t *testing.T) {
+
+ testCases := []struct {
+ label string
+ expected []rb.Definition
+ expectedCode int
+ rbDefClient *mockRBDefinition
+ }{
+ {
+ label: "List Bundle Definitions",
+ expectedCode: http.StatusOK,
+ expected: []rb.Definition{
+ {
+ RBName: "resourcebundle1",
+ RBVersion: "v1",
+ ChartName: "barchart",
+ Description: "test description for one",
+ },
+ {
+ RBName: "resourcebundle2",
+ RBVersion: "version2",
+ ChartName: "foochart",
+ Description: "test description for two",
+ },
+ },
+ rbDefClient: &mockRBDefinition{
+ // list of definitions that will be returned by the mockclient
+ Items: []rb.Definition{
+ {
+ RBName: "resourcebundle1",
+ RBVersion: "v1",
+ ChartName: "barchart",
+ Description: "test description for one",
+ },
+ {
+ RBName: "resourcebundle2",
+ RBVersion: "version2",
+ ChartName: "foochart",
+ Description: "test description for two",
+ },
+ },
+ },
+ },
+ }
+
+ for _, testCase := range testCases {
+ t.Run(testCase.label, func(t *testing.T) {
+ request := httptest.NewRequest("GET", "/v1/rb/definition", nil)
+ resp := executeRequest(request, NewRouter(testCase.rbDefClient, nil, nil, nil, nil, nil))
+
+ //Check returned code
+ if resp.StatusCode != testCase.expectedCode {
+ t.Fatalf("Expected %d; Got: %d", testCase.expectedCode, resp.StatusCode)
+ }
+
+ //Check returned body only if statusOK
+ if resp.StatusCode == http.StatusOK {
+ got := []rb.Definition{}
+ json.NewDecoder(resp.Body).Decode(&got)
+
+ // Since the order of returned slice is not guaranteed
+ // Check both and return error if both don't match
+ sort.Slice(got, func(i, j int) bool {
+ return got[i].RBVersion < got[j].RBVersion
+ })
+ // Sort both as it is not expected that testCase.expected
+ // is sorted
+ sort.Slice(testCase.expected, func(i, j int) bool {
+ return testCase.expected[i].RBVersion < testCase.expected[j].RBVersion
+ })
+
+ if reflect.DeepEqual(testCase.expected, got) == false {
+ t.Errorf("listHandler returned unexpected body: got %v;"+
+ " expected %v", got, testCase.expected)
+ }
+ }
+ })
+ }
+}
+
func TestRBDefGetHandler(t *testing.T) {
testCases := []struct {