aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/api/instancehandler_test.go
diff options
context:
space:
mode:
authorRitu Sood <Ritu.Sood@intel.com>2019-08-19 22:27:28 +0000
committerGerrit Code Review <gerrit@onap.org>2019-08-19 22:27:28 +0000
commit49ea7e46428c70fb553f6785b1ce22882f64c259 (patch)
tree6d40bc90e598592aba33c5d721f3f92fdc2f33ca /src/k8splugin/api/instancehandler_test.go
parent3f122fd2ac12ac9110c65924070732836de4ce8a (diff)
parentf22ab29dff2b69aaadd748c34c259f25dacec52d (diff)
Merge "Add query parameters support to instance API"
Diffstat (limited to 'src/k8splugin/api/instancehandler_test.go')
-rw-r--r--src/k8splugin/api/instancehandler_test.go49
1 files changed, 46 insertions, 3 deletions
diff --git a/src/k8splugin/api/instancehandler_test.go b/src/k8splugin/api/instancehandler_test.go
index 83fa3d2b..418054ec 100644
--- a/src/k8splugin/api/instancehandler_test.go
+++ b/src/k8splugin/api/instancehandler_test.go
@@ -60,7 +60,7 @@ func (m *mockInstanceClient) Get(id string) (app.InstanceResponse, error) {
return m.items[0], nil
}
-func (m *mockInstanceClient) List() ([]app.InstanceMiniResponse, error) {
+func (m *mockInstanceClient) List(rbname, rbversion, profilename string) ([]app.InstanceMiniResponse, error) {
if m.err != nil {
return []app.InstanceMiniResponse{}, m.err
}
@@ -68,12 +68,12 @@ func (m *mockInstanceClient) List() ([]app.InstanceMiniResponse, error) {
return m.miniitems, nil
}
-func (m *mockInstanceClient) Find(rbName string, ver string, profile string, labelKeys map[string]string) ([]app.InstanceResponse, error) {
+func (m *mockInstanceClient) Find(rbName string, ver string, profile string, labelKeys map[string]string) ([]app.InstanceMiniResponse, error) {
if m.err != nil {
return nil, m.err
}
- return m.items, nil
+ return m.miniitems, nil
}
func (m *mockInstanceClient) Delete(id string) error {
@@ -312,6 +312,8 @@ func TestInstanceListHandler(t *testing.T) {
label string
input string
expectedCode int
+ queryParams bool
+ queryParamsMap map[string]string
expectedResponse []app.InstanceMiniResponse
instClient *mockInstanceClient
}{
@@ -373,11 +375,52 @@ func TestInstanceListHandler(t *testing.T) {
},
},
},
+ {
+ label: "List Instances Based on Query Parameters",
+ queryParams: true,
+ queryParamsMap: map[string]string{
+ "rb-name": "test-rbdef1",
+ },
+ expectedCode: http.StatusOK,
+ expectedResponse: []app.InstanceMiniResponse{
+ {
+ ID: "HaKpys8e",
+ Request: app.InstanceRequest{
+ RBName: "test-rbdef",
+ RBVersion: "v1",
+ ProfileName: "profile1",
+ CloudRegion: "region1",
+ },
+ Namespace: "testnamespace",
+ },
+ },
+ instClient: &mockInstanceClient{
+ miniitems: []app.InstanceMiniResponse{
+ {
+ ID: "HaKpys8e",
+ Request: app.InstanceRequest{
+ RBName: "test-rbdef",
+ RBVersion: "v1",
+ ProfileName: "profile1",
+ CloudRegion: "region1",
+ },
+ Namespace: "testnamespace",
+ },
+ },
+ },
+ },
}
for _, testCase := range testCases {
t.Run(testCase.label, func(t *testing.T) {
request := httptest.NewRequest("GET", "/v1/instance", nil)
+ if testCase.queryParams {
+ q := request.URL.Query()
+ for k, v := range testCase.queryParamsMap {
+ q.Add(k, v)
+ }
+ request.URL.RawQuery = q.Encode()
+ }
resp := executeRequest(request, NewRouter(nil, nil, testCase.instClient, nil, nil, nil))
if testCase.expectedCode != resp.StatusCode {