diff options
Diffstat (limited to 'src/k8splugin/api')
-rw-r--r-- | src/k8splugin/api/api.go | 6 | ||||
-rw-r--r-- | src/k8splugin/api/brokerhandler_test.go | 18 | ||||
-rw-r--r-- | src/k8splugin/api/instancehandler.go | 10 | ||||
-rw-r--r-- | src/k8splugin/api/instancehandler_test.go | 49 |
4 files changed, 61 insertions, 22 deletions
diff --git a/src/k8splugin/api/api.go b/src/k8splugin/api/api.go index 4308db4f..726bd116 100644 --- a/src/k8splugin/api/api.go +++ b/src/k8splugin/api/api.go @@ -39,6 +39,12 @@ func NewRouter(defClient rb.DefinitionManager, instRouter := router.PathPrefix("/v1").Subrouter() instRouter.HandleFunc("/instance", instHandler.createHandler).Methods("POST") instRouter.HandleFunc("/instance", instHandler.listHandler).Methods("GET") + // Match rb-names, versions or profiles + instRouter.HandleFunc("/instance", instHandler.listHandler). + Queries("rb-name", "{rb-name}", + "rb-version", "{rb-version}", + "profile-name", "{profile-name}").Methods("GET") + instRouter.HandleFunc("/instance/{instID}", instHandler.getHandler).Methods("GET") instRouter.HandleFunc("/instance/{instID}", instHandler.deleteHandler).Methods("DELETE") // (TODO): Fix update method diff --git a/src/k8splugin/api/brokerhandler_test.go b/src/k8splugin/api/brokerhandler_test.go index 319c64e7..8ef5e184 100644 --- a/src/k8splugin/api/brokerhandler_test.go +++ b/src/k8splugin/api/brokerhandler_test.go @@ -285,7 +285,7 @@ func TestBrokerFindHandler(t *testing.T) { }, }, instClient: &mockInstanceClient{ - items: []app.InstanceResponse{ + miniitems: []app.InstanceMiniResponse{ { ID: "HaKpys8e", Request: app.InstanceRequest{ @@ -295,22 +295,6 @@ func TestBrokerFindHandler(t *testing.T) { CloudRegion: "region1", }, Namespace: "testnamespace", - Resources: []helm.KubernetesResource{ - { - GVK: schema.GroupVersionKind{ - Group: "apps", - Version: "v1", - Kind: "Deployment"}, - Name: "test-deployment", - }, - { - GVK: schema.GroupVersionKind{ - Group: "", - Version: "v1", - Kind: "Service"}, - Name: "test-service", - }, - }, }, }, }, diff --git a/src/k8splugin/api/instancehandler.go b/src/k8splugin/api/instancehandler.go index 3ec055bc..be8e64fa 100644 --- a/src/k8splugin/api/instancehandler.go +++ b/src/k8splugin/api/instancehandler.go @@ -106,10 +106,16 @@ func (i instanceHandler) getHandler(w http.ResponseWriter, r *http.Request) { } } -// getHandler retrieves information about an instance via the ID +// listHandler retrieves information about an instance via the ID func (i instanceHandler) listHandler(w http.ResponseWriter, r *http.Request) { - resp, err := i.client.List() + //If parameters are not provided, they are sent as empty strings + //Which will list all instances + rbName := r.FormValue("rb-name") + rbVersion := r.FormValue("rb-version") + ProfileName := r.FormValue("profile-name") + + resp, err := i.client.List(rbName, rbVersion, ProfileName) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return 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 { |