Skip to content

Commit a849301

Browse files
feat(makefile): add formating and linting tests (#394)
1 parent c102d81 commit a849301

6 files changed

Lines changed: 28 additions & 14 deletions

File tree

Makefile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ 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;
36+
3237
all:
3338
@echo "Use a Makefile to control top-level building of the project."
3439

@@ -45,7 +50,16 @@ build:
4550
${DEV_ENV_CMD} go build -ldflags ${LDFLAGS} -o ${BINARY_DEST_DIR}/boot boot.go
4651
${DEV_ENV_CMD} upx -9 ${BINARY_DEST_DIR}/boot
4752

48-
test:
53+
test: test-style test-unit
54+
55+
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
61+
62+
test-unit:
4963
${DEV_ENV_CMD} sh -c 'go test $$(glide nv)'
5064

5165
test-cover:

pkg/cleaner/cleaner_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212

1313
func TestGetDiff(t *testing.T) {
1414
nsList := []api.Namespace{
15-
api.Namespace{ObjectMeta: api.ObjectMeta{Name: "app1"}},
16-
api.Namespace{ObjectMeta: api.ObjectMeta{Name: "app2"}},
15+
{ObjectMeta: api.ObjectMeta{Name: "app1"}},
16+
{ObjectMeta: api.ObjectMeta{Name: "app2"}},
1717
}
1818
dirList := []string{"app1", "app3"}
1919
diff := getDiff(nsList, dirList)

pkg/gitreceive/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func build(
8484
}
8585
defer func() {
8686
if err := os.RemoveAll(tmpDir); err != nil {
87-
fmt.Errorf("unable to remove tmpdir %s (%s)", tmpDir, err)
87+
log.Info("unable to remove tmpdir %s (%s)", tmpDir, err)
8888
}
8989
}()
9090

pkg/gitreceive/config_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ type checkCase struct {
1313

1414
func TestCheckDurations(t *testing.T) {
1515
cases := map[checkCase]checkCase{
16-
checkCase{100, 300000, 500, 300000}: checkCase{100, 300000, 500, 300000},
17-
checkCase{0, 300000, 500, 300000}: checkCase{100, 300000, 500, 300000},
18-
checkCase{100, 300000, 0, 300000}: checkCase{100, 300000, 500, 300000},
19-
checkCase{300000, 300000, 500, 300000}: checkCase{100, 300000, 500, 300000},
20-
checkCase{100, 300000, 300000, 300000}: checkCase{100, 300000, 500, 300000},
16+
checkCase{100, 300000, 500, 300000}: {100, 300000, 500, 300000},
17+
checkCase{0, 300000, 500, 300000}: {100, 300000, 500, 300000},
18+
checkCase{100, 300000, 0, 300000}: {100, 300000, 500, 300000},
19+
checkCase{300000, 300000, 500, 300000}: {100, 300000, 500, 300000},
20+
checkCase{100, 300000, 300000, 300000}: {100, 300000, 500, 300000},
2121
}
2222

2323
var cnf Config

pkg/gitreceive/k8s_util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func buildPod(
114114
Spec: api.PodSpec{
115115
RestartPolicy: api.RestartPolicyNever,
116116
Containers: []api.Container{
117-
api.Container{
117+
{
118118
ImagePullPolicy: pullPolicy,
119119
},
120120
},
@@ -139,7 +139,7 @@ func buildPod(
139139
})
140140

141141
pod.Spec.Containers[0].VolumeMounts = []api.VolumeMount{
142-
api.VolumeMount{
142+
{
143143
Name: objectStore,
144144
MountPath: objectStorePath,
145145
ReadOnly: true,

pkg/k8s/pull_policy.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ var (
1010
emptyPullPolicy = api.PullPolicy("")
1111
// ValidPullPolicies is the set of pull policies that this package considers valid
1212
ValidPullPolicies = map[api.PullPolicy]struct{}{
13-
api.PullAlways: struct{}{},
14-
api.PullIfNotPresent: struct{}{},
15-
api.PullNever: struct{}{},
13+
api.PullAlways: {},
14+
api.PullIfNotPresent: {},
15+
api.PullNever: {},
1616
}
1717
)
1818

0 commit comments

Comments
 (0)