Skip to content

Commit d300b23

Browse files
chore(*): upgrade docker-go-dev and switch to the new linter (#399)
1 parent f8cc20b commit d300b23

13 files changed

Lines changed: 81 additions & 97 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ sudo: required
1313
install:
1414
- make bootstrap
1515
script:
16-
- make test-cover build docker-build
16+
- make test-style test-cover build docker-build
1717
after_success:
1818
- bash <(curl -s https://codecov.io/bash)

Makefile

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export GO15VENDOREXPERIMENT=1
77

88
# dockerized development environment variables
99
REPO_PATH := github.com/deis/${SHORT_NAME}
10-
DEV_ENV_IMAGE := quay.io/deis/go-dev:0.14.0
10+
DEV_ENV_IMAGE := quay.io/deis/go-dev:0.16.0
1111
DEV_ENV_WORK_DIR := /go/src/${REPO_PATH}
1212
DEV_ENV_PREFIX := docker run --rm -e GO15VENDOREXPERIMENT=1 -v ${CURDIR}:${DEV_ENV_WORK_DIR} -w ${DEV_ENV_WORK_DIR}
1313
DEV_ENV_CMD := ${DEV_ENV_PREFIX} ${DEV_ENV_IMAGE}
@@ -29,10 +29,7 @@ BINDIR := ./rootfs
2929

3030
DEIS_REGISTRY ?= ${DEV_REGISTRY}/
3131

32-
GO_FILES = $(wildcard *.go)
33-
GO_PACKAGES := $(shell find pkg -maxdepth 1 -type d)
34-
GO_PACKAGES_REPO_PATH = $(addprefix $(REPO_PATH)/,$(GO_PACKAGES))
35-
GOFMT = gofmtresult=$$(gofmt -e -l -s ${GO_FILES} ${GO_PACKAGES}); if [[ -n $$gofmtresult ]]; then echo "gofmt errors found in the following files: $${gofmtresult}"; false; fi;
32+
GOTEST := go test --race
3633

3734
all:
3835
@echo "Use a Makefile to control top-level building of the project."
@@ -53,14 +50,10 @@ build:
5350
test: test-style test-unit
5451

5552
test-style:
56-
${DEV_ENV_CMD} bash -c '${GOFMT}'
57-
${DEV_ENV_CMD} sh -c 'go vet $(repo_path) $(GO_PACKAGES_REPO_PATH)'
58-
@for i in $(addsuffix /...,$(GO_PACKAGES)); do \
59-
${DEV_ENV_CMD} golint $$i; \
60-
done
53+
${DEV_ENV_CMD} lint
6154

6255
test-unit:
63-
${DEV_ENV_CMD} sh -c 'go test $$(glide nv)'
56+
${DEV_ENV_CMD} sh -c '${GOTEST} $$(glide nv)'
6457

6558
test-cover:
6659
${DEV_ENV_CMD} test-cover.sh

pkg/controller/utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ type UserInfo struct {
2727
Apps []string
2828
}
2929

30-
// ControllerURLStr returns the url for connecting to deis controller
31-
func ControllerURLStr(additionalPath ...string) (string, error) {
30+
// URLStr returns the url of the controller with the given path prepended.
31+
func URLStr(additionalPath ...string) (string, error) {
3232
host := os.Getenv(hostEnvName)
3333
port := os.Getenv(portEnvName)
3434

@@ -66,7 +66,7 @@ func fingerprint(key ssh.PublicKey) string {
6666
// UserInfoFromKey makes a request to the controller to get the user info from they given key.
6767
func UserInfoFromKey(key ssh.PublicKey) (*UserInfo, error) {
6868
fp := fingerprint(key)
69-
url, err := ControllerURLStr("v2", "hooks", "key", fp)
69+
url, err := URLStr("v2", "hooks", "key", fp)
7070
if err != nil {
7171
return nil, err
7272
}

pkg/git/sha.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ import (
55
"regexp"
66
)
77

8-
const (
9-
// this constant represents the length of a shortened git sha - 8 characters long
10-
shortShaIdx = 8
11-
)
8+
// this constant represents the length of a shortened git sha - 8 characters long
9+
const shortShaIdx = 8
1210

1311
var shaRegex = regexp.MustCompile(`^[\da-f]{40}$`)
1412

@@ -33,7 +31,7 @@ func NewSha(rawSha string) (*SHA, error) {
3331
if !shaRegex.MatchString(rawSha) {
3432
return nil, ErrInvalidGitSha{sha: rawSha}
3533
}
36-
return &SHA{full: rawSha, short: rawSha[0:8]}, nil
34+
return &SHA{full: rawSha, short: rawSha[0:shortShaIdx]}, nil
3735
}
3836

3937
// Full returns the full git sha.

pkg/gitreceive/run.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ func Run(conf *Config, fs sys.FS, env sys.Env, storageDriver storagedriver.Stora
5858
}
5959
}
6060
}
61-
if err := scanner.Err(); err != nil {
62-
return err
63-
}
64-
return nil
61+
62+
return scanner.Err()
6563
}

pkg/healthsrv/buckets_lister.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,6 @@ type BucketLister interface {
1111
List(ctx context.Context, opath string) ([]string, error)
1212
}
1313

14-
type emptyBucketLister struct{}
15-
16-
func (e emptyBucketLister) List(ctx context.Context, opath string) ([]string, error) {
17-
return nil, nil
18-
}
19-
20-
type errBucketLister struct {
21-
err error
22-
}
23-
24-
func (e errBucketLister) List(ctx context.Context, opath string) ([]string, error) {
25-
return nil, e.err
26-
}
27-
2814
// listBuckets calls bl.ListBuckets(...) and sends the results back on the various given channels.
2915
// This func is intended to be run in a goroutine and communicates via the channels it's passed.
3016
//

pkg/healthsrv/controller_state.go

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package healthsrv
22

33
import (
44
"fmt"
5-
"io/ioutil"
65
"net/http"
7-
"strings"
86

97
"github.com/deis/builder/pkg/controller"
108
)
@@ -15,36 +13,8 @@ type GetClient interface {
1513
Get(string) (*http.Response, error)
1614
}
1715

18-
type successGetClient struct{}
19-
20-
func (e successGetClient) Get(url string) (*http.Response, error) {
21-
resp := &http.Response{
22-
Body: ioutil.NopCloser(strings.NewReader("")),
23-
StatusCode: http.StatusOK,
24-
}
25-
return resp, nil
26-
}
27-
28-
type failureGetClient struct{}
29-
30-
func (e failureGetClient) Get(url string) (*http.Response, error) {
31-
resp := &http.Response{
32-
Body: ioutil.NopCloser(strings.NewReader("")),
33-
StatusCode: http.StatusServiceUnavailable,
34-
}
35-
return resp, nil
36-
}
37-
38-
type errGetClient struct {
39-
err error
40-
}
41-
42-
func (e errGetClient) Get(url string) (*http.Response, error) {
43-
return nil, e.err
44-
}
45-
4616
func controllerState(client GetClient, succCh chan<- string, errCh chan<- error, stopCh <-chan struct{}) {
47-
url, err := controller.ControllerURLStr("healthz")
17+
url, err := controller.URLStr("healthz")
4818
if err != nil {
4919
select {
5020
case errCh <- err:

pkg/healthsrv/healthz_handler_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@ package healthsrv
33
import (
44
"bytes"
55
"errors"
6+
"io/ioutil"
67
"net/http"
78
"net/http/httptest"
89
"os"
10+
"strings"
911
"testing"
1012

13+
"k8s.io/kubernetes/pkg/api"
14+
15+
"github.com/docker/distribution/context"
16+
1117
"github.com/arschles/assert"
1218
"github.com/deis/builder/pkg/sshd"
1319
)
@@ -16,6 +22,62 @@ var (
1622
errTest = errors.New("test error")
1723
)
1824

25+
type emptyBucketLister struct{}
26+
27+
func (e emptyBucketLister) List(ctx context.Context, opath string) ([]string, error) {
28+
return nil, nil
29+
}
30+
31+
type errBucketLister struct {
32+
err error
33+
}
34+
35+
func (e errBucketLister) List(ctx context.Context, opath string) ([]string, error) {
36+
return nil, e.err
37+
}
38+
39+
type successGetClient struct{}
40+
41+
func (e successGetClient) Get(url string) (*http.Response, error) {
42+
resp := &http.Response{
43+
Body: ioutil.NopCloser(strings.NewReader("")),
44+
StatusCode: http.StatusOK,
45+
}
46+
return resp, nil
47+
}
48+
49+
type failureGetClient struct{}
50+
51+
func (e failureGetClient) Get(url string) (*http.Response, error) {
52+
resp := &http.Response{
53+
Body: ioutil.NopCloser(strings.NewReader("")),
54+
StatusCode: http.StatusServiceUnavailable,
55+
}
56+
return resp, nil
57+
}
58+
59+
type errGetClient struct {
60+
err error
61+
}
62+
63+
func (e errGetClient) Get(url string) (*http.Response, error) {
64+
return nil, e.err
65+
}
66+
67+
type emptyNamespaceLister struct{}
68+
69+
func (n emptyNamespaceLister) List(opts api.ListOptions) (*api.NamespaceList, error) {
70+
return &api.NamespaceList{}, nil
71+
}
72+
73+
type errNamespaceLister struct {
74+
err error
75+
}
76+
77+
func (e errNamespaceLister) List(opts api.ListOptions) (*api.NamespaceList, error) {
78+
return nil, e.err
79+
}
80+
1981
func TestHealthZCircuitOpen(t *testing.T) {
2082
bLister := emptyBucketLister{}
2183
c := sshd.NewCircuit()

pkg/healthsrv/namespace_lister.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,6 @@ type NamespaceLister interface {
1414
List(opts api.ListOptions) (*api.NamespaceList, error)
1515
}
1616

17-
type emptyNamespaceLister struct{}
18-
19-
func (n emptyNamespaceLister) List(opts api.ListOptions) (*api.NamespaceList, error) {
20-
return &api.NamespaceList{}, nil
21-
}
22-
23-
type errNamespaceLister struct {
24-
err error
25-
}
26-
27-
func (e errNamespaceLister) List(opts api.ListOptions) (*api.NamespaceList, error) {
28-
return nil, e.err
29-
}
30-
3117
// listNamespaces calls nl.List(...) and sends the results back on the various given channels.
3218
// This func is intended to be run in a goroutine and communicates via the channels it's passed.
3319
//

pkg/sshd/lock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type inMemoryRepoLock struct {
6363
timeout time.Duration
6464
}
6565

66-
// Lock aquires a lock associated with the specified name.
66+
// Lock acquires a lock associated with the specified name.
6767
func (rl *inMemoryRepoLock) Lock(repoName string) error {
6868
rl.mutex.Lock()
6969
defer rl.mutex.Unlock()

0 commit comments

Comments
 (0)