Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve get specific router API response #31

Merged
merged 1 commit into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/client/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func (r *RouterAPIService) GetAllRouter(
func (r *RouterAPIService) GetSpecificRouter(
ctx context.Context,
routerID int,
) (models.GetNetworkRouter, error) {
routerResp := models.GetNetworkRouter{}
) (models.GetSpecificRouterResp, error) {
routerResp := models.GetSpecificRouterResp{}
routerAPI := &api{
compatibleVersion: routerCompatibleVersion,
method: "GET",
Expand Down
58 changes: 10 additions & 48 deletions pkg/client/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ func TestRouterAPIService_GetSpecificRouter(t *testing.T) {
name string
routerID int
given func(m *MockAPIClientHandler)
want models.GetNetworkRouter
want models.GetSpecificRouterResp
wantErr bool
}{
{
Expand All @@ -506,8 +506,10 @@ func TestRouterAPIService_GetSpecificRouter(t *testing.T) {
req, _ := http.NewRequest(method, path, nil)
respBody := ioutil.NopCloser(bytes.NewReader([]byte(`
{
"id": 1,
"name": "test_template_get_a_specific_router"
"networkRouter":{
"id": 1,
"name": "test_template_get_a_specific_router"
}
}
`)))
m.EXPECT().getVersion().Return(999999)
Expand All @@ -519,54 +521,14 @@ func TestRouterAPIService_GetSpecificRouter(t *testing.T) {
Body: respBody,
}, nil)
},
want: models.GetNetworkRouter{
ID: 1,
Name: templateName,
want: models.GetSpecificRouterResp{
NetworkRouter: models.GetNetworkRouter{
ID: 1,
Name: templateName,
},
},
wantErr: false,
},
{
name: "Failed Test case 2: Error in prepare request",
routerID: 1,
given: func(m *MockAPIClientHandler) {
path := mockHost + "/v1beta1/networks/routers/1"
method := "GET"
headers := getDefaultHeaders()
m.EXPECT().getVersion().Return(999999)
m.EXPECT().prepareRequest(gomock.Any(), path, method, nil, headers,
getURLValues(nil), url.Values{}, "", nil).Return(nil, errors.New("prepare error request"))
},
want: models.GetNetworkRouter{},
wantErr: true,
},
{
name: "Failed Test case 3: Error in callAPI",
routerID: 1,
given: func(m *MockAPIClientHandler) {
path := mockHost + "/v1beta1/networks/routers/1"
method := "GET"
headers := getDefaultHeaders()
req, _ := http.NewRequest(method, path, nil)
respBody := ioutil.NopCloser(bytes.NewReader([]byte(`
{
"message": "Internal Server Error",
"recommendedActions": [
"Unknown error occurred. Please contact the administrator"
]
}
`)))
m.EXPECT().getVersion().Return(999999)
m.EXPECT().prepareRequest(gomock.Any(), path, method, nil, headers,
getURLValues(nil), url.Values{}, "", nil).Return(req, nil)

m.EXPECT().callAPI(req).Return(&http.Response{
StatusCode: 500,
Body: respBody,
}, nil)
},
want: models.GetNetworkRouter{},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down