Skip to content

Commit

Permalink
Add more check tools, and fix reported things
Browse files Browse the repository at this point in the history
  • Loading branch information
tbruyelle committed Oct 20, 2016
1 parent 0a56834 commit bba574c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
25 changes: 2 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
SRC_DIR=./hipchat
VETARGS=-asmdecl -atomic -bool -buildtags -copylocks -methods -nilfunc -printf -rangeloops -shift -structtags -unsafeptr

all: test testrace vet
include checks.mk

default: test
default: test checks

# test runs the unit tests and vets the code
test:
go test -v $(SRC_DIR) $(TESTARGS) -timeout=30s -parallel=4

# testrace runs the race checker
testrace:
go test -race $(SRC_DIR) $(TESTARGS)

# vet runs the Go source code static analysis tool `vet` to find
# any common errors
vet:
@go tool vet 2>/dev/null ; if [ $$? -eq 3 ]; then \
go get golang.org/x/tools/cmd/vet; \
fi
@echo "go tool vet $(VETARGS) $(SRC_DIR) "
@go tool vet $(VETARGS) $(SRC_DIR) ; if [ $$? -eq 1 ]; then \
echo ""; \
echo "Vet found suspicious constructs. Please check the reported constructs"; \
echo "and fix them if necessary before submitting the code for review."; \
exit 1; \
fi

.PHONY: all default test vet
18 changes: 18 additions & 0 deletions checks.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
checks:
go test -race $(SRC_DIR)
@$(call checkbin,go tool vet,golang.org/x/tools/cms/vet)
go tool vet $(SRC_DIR)
@$(call checkbin,golint,github.com/golang/lint/golint)
golint -set_exit_status $(SRC_DIR)
@$(call checkbin,errcheck,github.com/kisielk/errcheck)
errcheck -ignore 'Close' -ignoretests $(SRC_DIR)
@$(call checkbin,structcheck,github.com/opennota/check/cmd/structcheck)
structcheck $(SRC_DIR)
@$(call checkbin,varcheck,github.com/opennota/check/cmd/varcheck)
varcheck $(SRC_DIR)

checkbin = $1 2> /dev/null; if [ $$? -eq 127 ]; then\
echo "Retrieving missing tool $1...";\
go get $2; \
fi;

7 changes: 5 additions & 2 deletions hipchat/hipchat.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,10 @@ func (c *Client) NewFileUploadRequest(method, urlStr string, v interface{}) (*ht
"--hipfileboundary\n"

b := &bytes.Buffer{}
b.Write([]byte(body))
_, err = b.Write([]byte(body))
if err != nil {
return nil, err
}

req, err := http.NewRequest(method, u.String(), b)
if err != nil {
Expand Down Expand Up @@ -263,7 +266,7 @@ func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error) {
if v != nil {
defer resp.Body.Close()
if w, ok := v.(io.Writer); ok {
io.Copy(w, resp.Body)
_, err = io.Copy(w, resp.Body)
} else {
err = json.NewDecoder(resp.Body).Decode(v)
}
Expand Down
4 changes: 2 additions & 2 deletions hipchat/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ func (c *Client) GenerateToken(credentials ClientCredentials, scopes []string) (
content, err := ioutil.ReadAll(resp.Body)

var token OAuthAccessToken
json.Unmarshal(content, &token)
err = json.Unmarshal(content, &token)

return &token, resp, nil
return &token, resp, err
}

const (
Expand Down

0 comments on commit bba574c

Please sign in to comment.