"net/http"
"net/http/httptest"
"reflect"
+ "sort"
"testing"
pkgerrors "github.com/pkg/errors"
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)
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)
}
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)
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)
}
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)
}
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)
import (
"k8splugin/db"
"reflect"
+ "sort"
"strings"
"testing"
pkgerrors "github.com/pkg/errors"
)
-func TestCreate(t *testing.T) {
+func TestCreateDefinition(t *testing.T) {
testCases := []struct {
label string
inp Definition
}
}
-func TestList(t *testing.T) {
+func TestListDefinition(t *testing.T) {
testCases := []struct {
label string
t.Fatalf("List returned an unexpected error %s", err)
}
} else {
+ // 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("List Resource Bundle returned unexpected body: got %v;"+
" expected %v", got, testCase.expected)
}
}
-func TestGet(t *testing.T) {
+func TestGetDefinition(t *testing.T) {
testCases := []struct {
label string
}
}
-func TestDelete(t *testing.T) {
+func TestDeleteDefinition(t *testing.T) {
testCases := []struct {
label string
}
}
-func TestUpload(t *testing.T) {
+func TestUploadDefinition(t *testing.T) {
testCases := []struct {
label string
inp string
"123e4567-e89b-12d3-a456-426655441111": []byte(
"{\"name\":\"testresourcebundle\"," +
"\"description\":\"testresourcebundle\"," +
- "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
+ "\"uuid\":\"123e4567-e89b-12d3-a456-426655441111\"," +
"\"service-type\":\"firewall\"}"),
},
},