Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
issue #113: update router tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed Oct 16, 2018
1 parent a4dc71e commit ad598ab
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/server/router/chi/router.go
Expand Up @@ -24,7 +24,7 @@ func NewRouter(api router.Server) http.Handler {
r.Route("/{ID}", func(r chi.Router) {
r.Use(ctxPacker(common.Schema, "ID"))
r.Get("/", common.Encoder(api.GetV1))
r.Post("/", api.HandleInput)
r.Post("/", api.Input)
})
})
r.Route("/api/v2", func(r chi.Router) {
Expand Down
9 changes: 5 additions & 4 deletions pkg/server/router/chi/router_test.go
@@ -1,5 +1,5 @@
//go:generate echo $PWD/$GOPACKAGE/$GOFILE
//go:generate mockgen -package chi_test -destination $PWD/pkg/server/router/chi/mock_contract_test.go github.com/kamilsk/form-api/pkg/server/router Server
//go:generate mockgen -package chi_test -destination $PWD/pkg/server/router/chi/mock_server_test.go github.com/kamilsk/form-api/pkg/server/router Server
package chi_test

import (
Expand All @@ -11,8 +11,9 @@ import (
"github.com/go-chi/chi/middleware"
"github.com/golang/mock/gomock"
"github.com/kamilsk/form-api/pkg/domain"
"github.com/kamilsk/form-api/pkg/server/router/chi"
"github.com/stretchr/testify/assert"

. "github.com/kamilsk/form-api/pkg/server/router/chi"
)

const UUID domain.ID = "41ca5e09-3ce2-4094-b108-3ecc257c6fa4"
Expand All @@ -25,7 +26,7 @@ func TestChiRouter(t *testing.T) {

var (
api = NewMockServer(ctrl)
router = chi.NewRouter(api)
router = NewRouter(api)
)

tests := []struct {
Expand All @@ -47,7 +48,7 @@ func TestChiRouter(t *testing.T) {
Scheme: "http", Host: "dev", Path: "/api/v1/" + UUID.String(),
}}
api.EXPECT().
PostV1(gomock.Any(), gomock.Any()).
Input(gomock.Any(), gomock.Any()).
Do(func(rw http.ResponseWriter, _ *http.Request) { rw.WriteHeader(http.StatusFound) })
return request
}, http.StatusFound},
Expand Down
4 changes: 2 additions & 2 deletions pkg/server/router/contract.go
Expand Up @@ -6,6 +6,6 @@ import "net/http"
type Server interface {
// GetV1 is responsible for `GET /api/v1/{Schema.ID}` request handling.
GetV1(http.ResponseWriter, *http.Request)
// HandleInput is responsible for `POST /api/v1/{Schema.ID}` request handling.
HandleInput(http.ResponseWriter, *http.Request)
// Input is responsible for `POST /api/v1/{Schema.ID}` request handling.
Input(http.ResponseWriter, *http.Request)
}
4 changes: 2 additions & 2 deletions pkg/server/server.go
Expand Up @@ -47,8 +47,8 @@ func (s *Server) GetV1(rw http.ResponseWriter, req *http.Request) {
encoder.Encode(resp.Schema)
}

// HandleInput is responsible for `POST /api/v1/{Schema.ID}` request handling.
func (s *Server) HandleInput(rw http.ResponseWriter, req *http.Request) {
// Input is responsible for `POST /api/v1/{Schema.ID}` request handling.
func (s *Server) Input(rw http.ResponseWriter, req *http.Request) {
if err := req.ParseForm(); err != nil {
rw.WriteHeader(http.StatusBadRequest)
return
Expand Down

0 comments on commit ad598ab

Please sign in to comment.