diff options
-rw-r--r-- | src/k8splugin/api/defhandler.go | 6 | ||||
-rw-r--r-- | src/k8splugin/api/defhandler_test.go | 25 | ||||
-rw-r--r-- | src/k8splugin/mock_files/mock_json/create_rbdefinition.json | 3 | ||||
-rw-r--r-- | src/k8splugin/rb/definition.go | 1 |
4 files changed, 33 insertions, 2 deletions
diff --git a/src/k8splugin/api/defhandler.go b/src/k8splugin/api/defhandler.go index 31b0f38f..f53acdd2 100644 --- a/src/k8splugin/api/defhandler.go +++ b/src/k8splugin/api/defhandler.go @@ -54,6 +54,12 @@ func (h rbDefinitionHandler) createHandler(w http.ResponseWriter, r *http.Reques return } + // Chart Name is required + if v.ChartName == "" { + http.Error(w, "Missing chart name in POST request", http.StatusBadRequest) + return + } + ret, err := h.client.Create(v) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/src/k8splugin/api/defhandler_test.go b/src/k8splugin/api/defhandler_test.go index fd17f50e..e638ca05 100644 --- a/src/k8splugin/api/defhandler_test.go +++ b/src/k8splugin/api/defhandler_test.go @@ -90,13 +90,15 @@ func TestRBDefCreateHandler(t *testing.T) { label: "Create without UUID", expectedCode: http.StatusCreated, reader: bytes.NewBuffer([]byte(`{ - "name":"testdomain", + "name":"testresourcebundle", + "chart-name":"testchart", "description":"test description", "service-type":"firewall" }`)), expected: rb.Definition{ UUID: "123e4567-e89b-12d3-a456-426655440000", Name: "testresourcebundle", + ChartName: "testchart", Description: "test description", ServiceType: "firewall", }, @@ -106,12 +108,33 @@ func TestRBDefCreateHandler(t *testing.T) { { UUID: "123e4567-e89b-12d3-a456-426655440000", Name: "testresourcebundle", + ChartName: "testchart", Description: "test description", ServiceType: "firewall", }, }, }, }, + { + label: "Missing Name in Request Body", + reader: bytes.NewBuffer([]byte(`{ + "chart-name":"testchart", + "description":"test description", + "service-type":"firewall" + }`)), + expectedCode: http.StatusBadRequest, + rbDefClient: &mockRBDefinition{}, + }, + { + label: "Missing Chart Name in Request Body", + reader: bytes.NewBuffer([]byte(`{ + "name":"testresourcebundle", + "description":"test description", + "service-type":"firewall" + }`)), + expectedCode: http.StatusBadRequest, + rbDefClient: &mockRBDefinition{}, + }, } for _, testCase := range testCases { diff --git a/src/k8splugin/mock_files/mock_json/create_rbdefinition.json b/src/k8splugin/mock_files/mock_json/create_rbdefinition.json index 994afdf8..370c3c79 100644 --- a/src/k8splugin/mock_files/mock_json/create_rbdefinition.json +++ b/src/k8splugin/mock_files/mock_json/create_rbdefinition.json @@ -1,6 +1,7 @@ { + "uuid": "7eb09e38-4363-9942-1234-3beb2e95fd85", "name": "test-rbdef", + "chart-name": "testchart", "description": "testing resource bundle definition api", - "uuid": "7eb09e38-4363-9942-1234-3beb2e95fd85", "service-type": "firewall" }
\ No newline at end of file diff --git a/src/k8splugin/rb/definition.go b/src/k8splugin/rb/definition.go index 91419bf1..084abe7b 100644 --- a/src/k8splugin/rb/definition.go +++ b/src/k8splugin/rb/definition.go @@ -31,6 +31,7 @@ import ( type Definition struct { UUID string `json:"uuid,omitempty"` Name string `json:"name"` + ChartName string `json:"chart-name"` Description string `json:"description"` ServiceType string `json:"service-type"` } |