summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2019-04-04 09:54:59 -0700
committerKiran Kamineni <kiran.k.kamineni@intel.com>2019-04-04 09:55:04 -0700
commit99928f9cef81b627c2b22fcf6d7c0ca7ebe2cb0e (patch)
treedc8d044f8bd37faf381093918944ad191e9f0602
parent9906b9777553cd076812f9b8944d64b6e050d09e (diff)
Use common code for executeRequest
Use the common executeRequest function instead of multiple copies of the same lines for test requests Issue-ID: MULTICLOUD-557 Change-Id: Icde498b55592333af265fc348f3a286a59b9b61c Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
-rw-r--r--src/k8splugin/api/defhandler_test.go20
-rw-r--r--src/k8splugin/api/profilehandler_test.go16
2 files changed, 9 insertions, 27 deletions
diff --git a/src/k8splugin/api/defhandler_test.go b/src/k8splugin/api/defhandler_test.go
index 0015d070..28bf1479 100644
--- a/src/k8splugin/api/defhandler_test.go
+++ b/src/k8splugin/api/defhandler_test.go
@@ -138,9 +138,7 @@ func TestRBDefCreateHandler(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.label, func(t *testing.T) {
request := httptest.NewRequest("POST", "/v1/rb/definition", testCase.reader)
- recorder := httptest.NewRecorder()
- NewRouter("", testCase.rbDefClient, nil).ServeHTTP(recorder, request)
- resp := recorder.Result()
+ resp := executeRequest(request, NewRouter(testCase.rbDefClient, nil, nil))
//Check returned code
if resp.StatusCode != testCase.expectedCode {
@@ -209,9 +207,7 @@ func TestRBDefListVersionsHandler(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.label, func(t *testing.T) {
request := httptest.NewRequest("GET", "/v1/rb/definition/testresourcebundle", nil)
- recorder := httptest.NewRecorder()
- NewRouter("", testCase.rbDefClient, nil).ServeHTTP(recorder, request)
- resp := recorder.Result()
+ resp := executeRequest(request, NewRouter(testCase.rbDefClient, nil, nil))
//Check returned code
if resp.StatusCode != testCase.expectedCode {
@@ -291,9 +287,7 @@ func TestRBDefGetHandler(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.label, func(t *testing.T) {
request := httptest.NewRequest("GET", "/v1/rb/definition/"+testCase.name+"/"+testCase.version, nil)
- recorder := httptest.NewRecorder()
- NewRouter("", testCase.rbDefClient, nil).ServeHTTP(recorder, request)
- resp := recorder.Result()
+ resp := executeRequest(request, NewRouter(testCase.rbDefClient, nil, nil))
//Check returned code
if resp.StatusCode != testCase.expectedCode {
@@ -344,9 +338,7 @@ func TestRBDefDeleteHandler(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.label, func(t *testing.T) {
request := httptest.NewRequest("DELETE", "/v1/rb/definition/"+testCase.name+"/"+testCase.version, nil)
- recorder := httptest.NewRecorder()
- NewRouter("", testCase.rbDefClient, nil).ServeHTTP(recorder, request)
- resp := recorder.Result()
+ resp := executeRequest(request, NewRouter(testCase.rbDefClient, nil, nil))
//Check returned code
if resp.StatusCode != testCase.expectedCode {
@@ -403,9 +395,7 @@ func TestRBDefUploadHandler(t *testing.T) {
t.Run(testCase.label, func(t *testing.T) {
request := httptest.NewRequest("POST",
"/v1/rb/definition/"+testCase.name+"/"+testCase.version+"/content", testCase.body)
- recorder := httptest.NewRecorder()
- NewRouter("", testCase.rbDefClient, nil).ServeHTTP(recorder, request)
- resp := recorder.Result()
+ resp := executeRequest(request, NewRouter(testCase.rbDefClient, nil, nil))
//Check returned code
if resp.StatusCode != testCase.expectedCode {
diff --git a/src/k8splugin/api/profilehandler_test.go b/src/k8splugin/api/profilehandler_test.go
index 02325487..932a0247 100644
--- a/src/k8splugin/api/profilehandler_test.go
+++ b/src/k8splugin/api/profilehandler_test.go
@@ -117,9 +117,7 @@ func TestRBProfileCreateHandler(t *testing.T) {
t.Run(testCase.label, func(t *testing.T) {
request := httptest.NewRequest("POST", "/v1/rb/definition/test-rbdef/v1/profile",
testCase.reader)
- recorder := httptest.NewRecorder()
- NewRouter("", nil, testCase.rbProClient).ServeHTTP(recorder, request)
- resp := recorder.Result()
+ resp := executeRequest(request, NewRouter(nil, testCase.rbProClient, nil))
//Check returned code
if resp.StatusCode != testCase.expectedCode {
@@ -190,9 +188,7 @@ func TestRBProfileGetHandler(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.label, func(t *testing.T) {
request := httptest.NewRequest("GET", "/v1/rb/definition/test-rbdef/v1/profile/"+testCase.prname, nil)
- recorder := httptest.NewRecorder()
- NewRouter("", nil, testCase.rbProClient).ServeHTTP(recorder, request)
- resp := recorder.Result()
+ resp := executeRequest(request, NewRouter(nil, testCase.rbProClient, nil))
//Check returned code
if resp.StatusCode != testCase.expectedCode {
@@ -240,9 +236,7 @@ func TestRBProfileDeleteHandler(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.label, func(t *testing.T) {
request := httptest.NewRequest("DELETE", "/v1/rb/definition/test-rbdef/v1/profile/"+testCase.prname, nil)
- recorder := httptest.NewRecorder()
- NewRouter("", nil, testCase.rbProClient).ServeHTTP(recorder, request)
- resp := recorder.Result()
+ resp := executeRequest(request, NewRouter(nil, testCase.rbProClient, nil))
//Check returned code
if resp.StatusCode != testCase.expectedCode {
@@ -295,9 +289,7 @@ func TestRBProfileUploadHandler(t *testing.T) {
t.Run(testCase.label, func(t *testing.T) {
request := httptest.NewRequest("POST",
"/v1/rb/definition/test-rbdef/v1/profile/"+testCase.prname+"/content", testCase.body)
- recorder := httptest.NewRecorder()
- NewRouter("", nil, testCase.rbProClient).ServeHTTP(recorder, request)
- resp := recorder.Result()
+ resp := executeRequest(request, NewRouter(nil, testCase.rbProClient, nil))
//Check returned code
if resp.StatusCode != testCase.expectedCode {