forked from mirror/gin
Add Makefile to check the following thing (#947)
* Add Makefile to check the following thing. * vet check * fmt check * embedmd check * misspell check Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com> * remove unused variable. Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
9ff8786b3d
commit
1e1e4fc867
11
.travis.yml
11
.travis.yml
|
@ -10,13 +10,14 @@ git:
|
||||||
depth: 3
|
depth: 3
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- go get -v github.com/kardianos/govendor
|
- make install
|
||||||
- govendor sync
|
|
||||||
- go get -u github.com/campoy/embedmd
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- embedmd -d README.md
|
- make vet
|
||||||
- go test -v -covermode=count -coverprofile=coverage.out
|
- make fmt-check
|
||||||
|
- make embedmd
|
||||||
|
- make misspell-check
|
||||||
|
- make test
|
||||||
|
|
||||||
after_success:
|
after_success:
|
||||||
- bash <(curl -s https://codecov.io/bash)
|
- bash <(curl -s https://codecov.io/bash)
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
GOFMT ?= gofmt "-s"
|
||||||
|
PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
|
||||||
|
GOFILES := $(shell find . -name "*.go" -type f -not -path "./vendor/*")
|
||||||
|
|
||||||
|
all: build
|
||||||
|
|
||||||
|
install: deps
|
||||||
|
govendor sync
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
test:
|
||||||
|
go test -v -covermode=count -coverprofile=coverage.out
|
||||||
|
|
||||||
|
.PHONY: fmt
|
||||||
|
fmt:
|
||||||
|
$(GOFMT) -w $(GOFILES)
|
||||||
|
|
||||||
|
.PHONY: fmt-check
|
||||||
|
fmt-check:
|
||||||
|
# get all go files and run go fmt on them
|
||||||
|
@diff=$$($(GOFMT) -d $(GOFILES)); \
|
||||||
|
if [ -n "$$diff" ]; then \
|
||||||
|
echo "Please run 'make fmt' and commit the result:"; \
|
||||||
|
echo "$${diff}"; \
|
||||||
|
exit 1; \
|
||||||
|
fi;
|
||||||
|
|
||||||
|
vet:
|
||||||
|
go vet $(PACKAGES)
|
||||||
|
|
||||||
|
deps:
|
||||||
|
@hash govendor > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||||
|
go get -u github.com/kardianos/govendor; \
|
||||||
|
fi
|
||||||
|
@hash embedmd > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||||
|
go get -u github.com/campoy/embedmd; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
embedmd:
|
||||||
|
embedmd -d *.md
|
||||||
|
|
||||||
|
.PHONY: lint
|
||||||
|
lint:
|
||||||
|
@hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||||
|
go get -u github.com/golang/lint/golint; \
|
||||||
|
fi
|
||||||
|
for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
|
||||||
|
|
||||||
|
.PHONY: misspell-check
|
||||||
|
misspell-check:
|
||||||
|
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||||
|
go get -u github.com/client9/misspell/cmd/misspell; \
|
||||||
|
fi
|
||||||
|
misspell -error $(GOFILES)
|
||||||
|
|
||||||
|
.PHONY: misspell
|
||||||
|
misspell:
|
||||||
|
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||||
|
go get -u github.com/client9/misspell/cmd/misspell; \
|
||||||
|
fi
|
||||||
|
misspell -w $(GOFILES)
|
|
@ -152,7 +152,7 @@ func setTimeField(val string, structField reflect.StructField, value reflect.Val
|
||||||
if timeFormat == "" {
|
if timeFormat == "" {
|
||||||
return errors.New("Blank time format")
|
return errors.New("Blank time format")
|
||||||
}
|
}
|
||||||
|
|
||||||
if val == "" {
|
if val == "" {
|
||||||
value.Set(reflect.ValueOf(time.Time{}))
|
value.Set(reflect.ValueOf(time.Time{}))
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -87,7 +87,7 @@ func (c *Context) HandlerName() string {
|
||||||
|
|
||||||
// Handler returns the main handler.
|
// Handler returns the main handler.
|
||||||
func (c *Context) Handler() HandlerFunc {
|
func (c *Context) Handler() HandlerFunc {
|
||||||
return c.handlers.Last()
|
return c.handlers.Last()
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************/
|
/************************************/
|
||||||
|
|
|
@ -283,13 +283,12 @@ var handlerTest HandlerFunc = func(c *Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContextHandler(t *testing.T) {
|
func TestContextHandler(t *testing.T) {
|
||||||
c, _ := CreateTestContext(httptest.NewRecorder())
|
c, _ := CreateTestContext(httptest.NewRecorder())
|
||||||
c.handlers = HandlersChain{func(c *Context) {}, handlerTest}
|
c.handlers = HandlersChain{func(c *Context) {}, handlerTest}
|
||||||
|
|
||||||
assert.Equal(t, reflect.ValueOf(handlerTest).Pointer(), reflect.ValueOf(c.Handler()).Pointer())
|
assert.Equal(t, reflect.ValueOf(handlerTest).Pointer(), reflect.ValueOf(c.Handler()).Pointer())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func TestContextQuery(t *testing.T) {
|
func TestContextQuery(t *testing.T) {
|
||||||
c, _ := CreateTestContext(httptest.NewRecorder())
|
c, _ := CreateTestContext(httptest.NewRecorder())
|
||||||
c.Request, _ = http.NewRequest("GET", "http://example.com/?foo=bar&page=10&id=", nil)
|
c.Request, _ = http.NewRequest("GET", "http://example.com/?foo=bar&page=10&id=", nil)
|
||||||
|
|
|
@ -80,7 +80,7 @@ func (msg *Error) IsType(flags ErrorType) bool {
|
||||||
return (msg.Type & flags) > 0
|
return (msg.Type & flags) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a readonly copy filterd the byte.
|
// Returns a readonly copy filtered the byte.
|
||||||
// ie ByType(gin.ErrorTypePublic) returns a slice of errors with type=ErrorTypePublic
|
// ie ByType(gin.ErrorTypePublic) returns a slice of errors with type=ErrorTypePublic
|
||||||
func (a errorMsgs) ByType(typ ErrorType) errorMsgs {
|
func (a errorMsgs) ByType(typ ErrorType) errorMsgs {
|
||||||
if len(a) == 0 {
|
if len(a) == 0 {
|
||||||
|
|
|
@ -20,8 +20,8 @@ import (
|
||||||
|
|
||||||
func testRequest(t *testing.T, url string) {
|
func testRequest(t *testing.T, url string) {
|
||||||
resp, err := http.Get(url)
|
resp, err := http.Get(url)
|
||||||
defer resp.Body.Close()
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
body, ioerr := ioutil.ReadAll(resp.Body)
|
body, ioerr := ioutil.ReadAll(resp.Body)
|
||||||
assert.NoError(t, ioerr)
|
assert.NoError(t, ioerr)
|
||||||
|
|
Loading…
Reference in New Issue