summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/api/defhandler_test.go
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2019-07-17 17:14:07 -0700
committerKiran Kamineni <kiran.k.kamineni@intel.com>2019-07-18 16:24:34 -0700
commitb8ecedd40b6be727233bf620a0aa5592f98161e7 (patch)
tree43d8525616b1a6ddd01ce23ad1bee090b8984264 /src/k8splugin/api/defhandler_test.go
parent045ce10b7c48136dee24761e23ea0156f6255521 (diff)
Add a listallhandler to definitions api
GET calls to the v1/rb/definition will return all definitions and their versions Issue-ID: MULTICLOUD-715 Change-Id: Ia0951ac83283830e475bf727e7d5ced7aab3add2 Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
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 {