diff options
Diffstat (limited to 'src/k8splugin/api/defhandler_test.go')
-rw-r--r-- | src/k8splugin/api/defhandler_test.go | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/k8splugin/api/defhandler_test.go b/src/k8splugin/api/defhandler_test.go index 9739ab12..3dbd1aa4 100644 --- a/src/k8splugin/api/defhandler_test.go +++ b/src/k8splugin/api/defhandler_test.go @@ -24,6 +24,7 @@ import ( "net/http" "net/http/httptest" "reflect" + "sort" "testing" pkgerrors "github.com/pkg/errors" @@ -116,7 +117,7 @@ func TestRBDefCreateHandler(t *testing.T) { 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.reader) + req, err := http.NewRequest("POST", "/v1/rb/definition", testCase.reader) if err != nil { t.Fatal(err) @@ -193,7 +194,7 @@ func TestRBDefListHandler(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { vh := rbDefinitionHandler{client: testCase.rbDefClient} - req, err := http.NewRequest("GET", "/v1/resource/definition", nil) + req, err := http.NewRequest("GET", "/v1/rb/definition", nil) if err != nil { t.Fatal(err) } @@ -212,6 +213,17 @@ func TestRBDefListHandler(t *testing.T) { got := []rb.Definition{} json.NewDecoder(rr.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].UUID < got[i].UUID + }) + // 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].UUID < testCase.expected[i].UUID + }) + if reflect.DeepEqual(testCase.expected, got) == false { t.Errorf("listHandler returned unexpected body: got %v;"+ " expected %v", got, testCase.expected) @@ -267,7 +279,7 @@ func TestRBDefGetHandler(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { vh := rbDefinitionHandler{client: testCase.rbDefClient} - req, err := http.NewRequest("GET", "/v1/resource/definition/"+testCase.inpUUID, nil) + req, err := http.NewRequest("GET", "/v1/rb/definition/"+testCase.inpUUID, nil) if err != nil { t.Fatal(err) } @@ -322,7 +334,7 @@ func TestRBDefDeleteHandler(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { vh := rbDefinitionHandler{client: testCase.rbDefClient} - req, err := http.NewRequest("GET", "/v1/resource/definition/"+testCase.inpUUID, nil) + req, err := http.NewRequest("GET", "/v1/rb/definition/"+testCase.inpUUID, nil) if err != nil { t.Fatal(err) } @@ -382,7 +394,7 @@ func TestRBDefUploadHandler(t *testing.T) { 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) + "/v1/rb/definition/"+testCase.inpUUID+"/content", testCase.body) if err != nil { t.Fatal(err) |