summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/api/defhandler_test.go
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2018-11-20 14:32:50 -0800
committerKiran Kamineni <kiran.k.kamineni@intel.com>2018-11-21 11:36:41 -0800
commitf54fee24c32465478e2c6fc4cd6fc6bfb44fe096 (patch)
treeebe95c5f51972d2cacb8c304abace2423b7952db /src/k8splugin/api/defhandler_test.go
parent3f780f7973081903f1ab6ea01a855fb6c5512a48 (diff)
Add upload backend implementation
Upload is a seperate API where it takes a binary stream and stores it. The api supports tar.gz file format only. P2: Check if ID is valid before trying upload Add test with an invalid ID Issue-ID: MULTICLOUD-393 Change-Id: Id636a95823a046e1795d3be72d0214e953a8c5fc 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.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/k8splugin/api/defhandler_test.go b/src/k8splugin/api/defhandler_test.go
index b83f0b7a..9739ab12 100644
--- a/src/k8splugin/api/defhandler_test.go
+++ b/src/k8splugin/api/defhandler_test.go
@@ -68,6 +68,10 @@ func (m *mockRBDefinition) Delete(id string) error {
return m.Err
}
+func (m *mockRBDefinition) Upload(id string, inp []byte) error {
+ return m.Err
+}
+
func TestRBDefCreateHandler(t *testing.T) {
testCases := []struct {
label string
@@ -334,3 +338,64 @@ func TestRBDefDeleteHandler(t *testing.T) {
})
}
}
+
+func TestRBDefUploadHandler(t *testing.T) {
+
+ testCases := []struct {
+ label string
+ inpUUID string
+ body io.Reader
+ expectedCode int
+ rbDefClient *mockRBDefinition
+ }{
+ {
+ label: "Upload Bundle Definition Content",
+ expectedCode: http.StatusOK,
+ inpUUID: "123e4567-e89b-12d3-a456-426655441111",
+ body: bytes.NewBuffer([]byte{
+ 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0xff, 0xf2, 0x48, 0xcd,
+ }),
+ rbDefClient: &mockRBDefinition{},
+ },
+ {
+ label: "Upload Invalid Bundle Definition Content",
+ expectedCode: http.StatusInternalServerError,
+ inpUUID: "123e4567-e89b-12d3-a456-426655440000",
+ body: bytes.NewBuffer([]byte{
+ 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0xff, 0xf2, 0x48, 0xcd,
+ }),
+ rbDefClient: &mockRBDefinition{
+ Err: pkgerrors.New("Internal Error"),
+ },
+ },
+ {
+ label: "Upload Empty Body Content",
+ expectedCode: http.StatusBadRequest,
+ inpUUID: "123e4567-e89b-12d3-a456-426655440000",
+ rbDefClient: &mockRBDefinition{},
+ },
+ }
+
+ for _, testCase := range testCases {
+ t.Run(testCase.label, func(t *testing.T) {
+ vh := rbDefinitionHandler{client: testCase.rbDefClient}
+ req, err := http.NewRequest("POST",
+ "/v1/resource/definition/"+testCase.inpUUID+"/content", testCase.body)
+
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ rr := httptest.NewRecorder()
+ hr := http.HandlerFunc(vh.uploadHandler)
+
+ hr.ServeHTTP(rr, req)
+ //Check returned code
+ if rr.Code != testCase.expectedCode {
+ t.Fatalf("Expected %d; Got: %d", testCase.expectedCode, rr.Code)
+ }
+ })
+ }
+}