Skip to content

Commit

Permalink
swagger: add test to increase package coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Francisco Souza committed Dec 6, 2016
1 parent ee4abac commit 0295924
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions swagger/handler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package swagger

import (
"errors"
"net/http"
"testing"
)

func TestHandlerToJSONEndpoint(t *testing.T) {
errResp := NewErrorResponse(errors.New("something went wrong")).WithStatus(http.StatusGone)
handler := Handler(func(r *http.Request) GizmoJSONResponse {
return errResp
})
req, _ := http.NewRequest("GET", "/something", nil)
code, data, err := HandlerToJSONEndpoint(handler)(req)
if code != http.StatusGone {
t.Errorf("wrong status code returned, want %d, got %d", http.StatusGone, code)
}
if data != nil {
t.Errorf("unexpected non-nil data: %s", data)
}
if err != errResp {
t.Errorf("wrong error returned\nwant %#v\ngot %#v", errResp, err)
}
}

0 comments on commit 0295924

Please sign in to comment.