Skip to content

Commit

Permalink
Added tests for mock routes generator
Browse files Browse the repository at this point in the history
  • Loading branch information
evg4b committed Oct 16, 2022
1 parent 1808e5c commit 58ffa57
Show file tree
Hide file tree
Showing 3 changed files with 377 additions and 75 deletions.
21 changes: 18 additions & 3 deletions internal/mock/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,28 @@ package mock
import "github.com/gorilla/mux"

func MakeMockedRoutes(router *mux.Router, mocks []Mock) {
var defaultMocks []Mock

for _, mock := range mocks {
if len(mock.Queries) > 0 || len(mock.Headers) > 0 || len(mock.Method) > 0 {
route := router.NewRoute()

setPath(route, mock.Path)
setMethod(route, mock.Method)
setQueries(route, mock.Queries)
setHeaders(route, mock.Headers)

handler := NewMockHandler(WithMock(mock))
route.Handler(handler)
} else {
defaultMocks = append(defaultMocks, mock)
}
}

for _, mock := range defaultMocks {
route := router.NewRoute()

setPath(route, mock.Path)
setMethod(route, mock.Method)
setQueries(route, mock.Queries)
setHeaders(route, mock.Headers)

handler := NewMockHandler(WithMock(mock))
route.Handler(handler)
Expand Down
Loading

0 comments on commit 58ffa57

Please sign in to comment.