Skip to content

Commit 1b5ab25

Browse files
author
Matthew Fisher
committed
test(*): enforce gofmt
This PR enforces and suggests that the codebase should follow a specific style using a combination of `gofmt`, `golint` and `go vet`. `gofmt` is enforced; the latter are suggested and displayed.
1 parent 5e951c7 commit 1b5ab25

18 files changed

Lines changed: 223 additions & 65 deletions

File tree

Makefile

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
include includes.mk
66

7+
# the filepath to this repository, relative to $GOPATH/src
8+
repo_path = github.com/deis/deis
9+
10+
GO_PACKAGES = pkg/time version
11+
GO_PACKAGES_REPO_PATH = $(addprefix $(repo_path)/,$(GO_PACKAGES))
12+
713
COMPONENTS=builder cache controller database logger logspout publisher registry router store
814
START_ORDER=publisher store logger logspout database cache registry controller builder router
915
CLIENTS=client deisctl
@@ -67,7 +73,7 @@ release: check-registry
6773

6874
deploy: build dev-release restart
6975

70-
test: test-unit test-functional push test-integration
76+
test: test-style test-unit test-functional push test-integration
7177

7278
test-functional:
7379
@$(foreach C, $(COMPONENTS), $(MAKE) -C $(C) test-functional &&) echo done
@@ -81,3 +87,16 @@ test-integration:
8187

8288
test-smoke:
8389
$(MAKE) -C tests/ test-smoke
90+
91+
test-style:
92+
# display output, then check
93+
$(GOFMT) $(GO_PACKAGES)
94+
@$(GOFMT) $(GO_PACKAGES) | read; if [ $$? == 0 ]; then echo "gofmt check failed."; exit 1; fi
95+
# FIXME: make this mandatory
96+
-$(GOVET) $(GO_PACKAGES_REPO_PATH)
97+
# FIXME: make this mandatory
98+
@for i in $(addsuffix /...,$(GO_PACKAGES)); do \
99+
$(GOLINT) $$i; \
100+
done
101+
@$(foreach C, $(COMPONENTS), $(MAKE) -C $(C) test-style &&) echo done
102+
@$(foreach C, $(CLIENTS), $(MAKE) -C $(C) test-style &&) echo done

builder/Makefile

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
include ../includes.mk
22

3-
COMPONENT = builder
3+
# the filepath to this repository, relative to $GOPATH/src
4+
repo_path = github.com/deis/deis/builder
5+
6+
GO_FILES = types.go utils.go utils_test.go
7+
GO_PACKAGES = bin
8+
GO_PACKAGES_REPO_PATH = $(addprefix $(repo_path)/,$(GO_PACKAGES))
9+
10+
COMPONENT = $(notdir $(repo_path))
411
IMAGE = $(IMAGE_PREFIX)$(COMPONENT):$(BUILD_TAG)
512
DEV_IMAGE = $(DEV_REGISTRY)/$(IMAGE)
613
BINARIES := extract-domain extract-types extract-version generate-buildhook get-app-config get-app-values publish-release-controller yaml2json-procfile
@@ -51,7 +58,7 @@ release:
5158

5259
deploy: build dev-release restart
5360

54-
test: test-unit test-functional
61+
test: test-style test-unit test-functional
5562

5663
test-unit:
5764
godep go test -v .
@@ -60,6 +67,15 @@ test-functional:
6067
@docker history deis/test-etcd >/dev/null 2>&1 || docker pull deis/test-etcd:latest
6168
GOPATH=`cd ../tests/ && godep path`:$(GOPATH) go test -v ./tests/...
6269

70+
test-style:
71+
# display output, then check
72+
$(GOFMT) $(GO_PACKAGES) $(GO_FILES)
73+
@$(GOFMT) $(GO_PACKAGES) $(GO_FILES) | read; if [ $$? == 0 ]; then echo "gofmt check failed."; exit 1; fi
74+
# FIXME: make this mandatory
75+
-$(GOVET) $(repo_path) $(GO_PACKAGES_REPO_PATH)
76+
# FIXME: make this mandatory
77+
-$(GOLINT) ./...
78+
6379
cedarish/build:
6480
mkdir -p build
6581
docker pull progrium/cedarish:latest

builder/utils_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88
"testing"
99
"time"
10+
1011
dtime "github.com/deis/deis/pkg/time"
1112
)
1213

cache/Makefile

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
include ../includes.mk
22

3-
COMPONENT = cache
3+
# the filepath to this repository, relative to $GOPATH/src
4+
repo_path = github.com/deis/deis/cache
5+
6+
GO_PACKAGES = image
7+
GO_PACKAGES_REPO_PATH = $(addprefix $(repo_path)/,$(GO_PACKAGES))
8+
9+
COMPONENT = $(notdir $(repo_path))
410
IMAGE = $(IMAGE_PREFIX)$(COMPONENT):$(BUILD_TAG)
511
DEV_IMAGE = $(DEV_REGISTRY)/$(IMAGE)
612
BUILD_IMAGE = $(COMPONENT)-build
@@ -50,11 +56,20 @@ release:
5056

5157
deploy: build dev-release restart
5258

53-
test: test-unit test-functional
59+
test: test-style test-unit test-functional
5460

5561
test-unit:
5662
@echo no unit tests
5763

64+
test-style:
65+
# display output, then check
66+
$(GOFMT) $(GO_PACKAGES)
67+
@$(GOFMT) $(GO_PACKAGES) | read; if [ $$? == 0 ]; then echo "gofmt check failed."; exit 1; fi
68+
# FIXME: make this mandatory
69+
-$(GOVET) $(GO_PACKAGES_REPO_PATH)
70+
# FIXME: make this mandatory
71+
-$(GOLINT) ./...
72+
5873
test-functional:
5974
@docker history deis/test-etcd >/dev/null 2>&1 || docker pull deis/test-etcd:latest
6075
GOPATH=`cd ../tests/ && godep path`:$(GOPATH) go test -v ./tests/...

client/deis.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
from itertools import cycle
4848
from threading import Event
4949
from threading import Thread
50-
import base64
5150
import glob
5251
import json
5352
import locale
@@ -181,7 +180,8 @@ def __init__(self):
181180
if os.path.exists(old_path):
182181
try:
183182
with open(old_path, 'r') as f:
184-
txt = f.read().replace('{', '{"', 1).replace(':', '":', 1).replace("'", '"')
183+
txt = f.read()
184+
txt = txt.replace('{', '{"', 1).replace(':', '":', 1).replace("'", '"')
185185
settings = json.loads(txt)
186186
os.remove(old_path)
187187
except:
@@ -638,6 +638,7 @@ def apps_logs(self, args):
638638
log_tag = line.split(': ')[0].split(' ')[1]
639639
# colorize the log based on the tag
640640
color = sum([ord(ch) for ch in log_tag]) % 6
641+
641642
def f(x):
642643
return {
643644
0: 'green',
@@ -797,7 +798,6 @@ def auth_login(self, args):
797798
if not urlparse.urlparse(controller).scheme:
798799
controller = "http://{}".format(controller)
799800
username = args.get('--username')
800-
headers = {}
801801
if not username:
802802
username = raw_input('username: ')
803803
password = args.get('--password')
@@ -810,7 +810,7 @@ def auth_login(self, args):
810810
payload = {'username': username, 'password': password}
811811
# post credentials to the login URL
812812
response = self._session.post(url, data=payload, allow_redirects=False,
813-
verify=ssl_verify)
813+
verify=ssl_verify)
814814
if response.status_code == requests.codes.ok:
815815
# retrieve and save the API token for future requests
816816
self._settings['controller'] = controller
@@ -1562,8 +1562,9 @@ def tags_set(self, args):
15621562
"""
15631563
Sets tags for an application.
15641564
1565-
A tag is a key/value pair used to tag an application's containers and is passed to the scheduler.
1566-
This is often used to restrict workloads to specific hosts matching the scheduler-configured metadata.
1565+
A tag is a key/value pair used to tag an application's containers and is passed to the
1566+
scheduler. This is often used to restrict workloads to specific hosts matching the
1567+
scheduler-configured metadata.
15671568
15681569
Usage: deis tags:set [options] <key>=<value>...
15691570

database/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,14 @@ release:
4343

4444
deploy: build dev-release restart
4545

46-
test: test-unit test-functional
46+
test: test-style test-unit test-functional
4747

4848
test-unit:
4949
@echo no unit tests
5050

51+
test-style:
52+
@echo no style tests
53+
5154
test-functional:
5255
@docker history deis/mock-store >/dev/null 2>&1 || $(MAKE) -C ../tests/ mock-store
5356
@docker history deis/test-etcd >/dev/null 2>&1 || docker pull deis/test-etcd:latest

deisctl/Makefile

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
include ../includes.mk
22

3-
COMPONENT = deisctl
3+
# the filepath to this repository, relative to $GOPATH/src
4+
repo_path = github.com/deis/deis/deisctl
5+
6+
GO_FILES = deisctl.go deisctl_test.go
7+
GO_PACKAGES = backend client cmd config utils
8+
GO_PACKAGES_REPO_PATH = $(addprefix $(repo_path)/,$(GO_PACKAGES))
9+
10+
COMPONENT = $(notdir $(repo_path))
411
IMAGE = $(IMAGE_PREFIX)/$(COMPONENT):$(BUILD_TAG)
512

613
build:
@@ -32,11 +39,16 @@ setup-root-gotools:
3239
setup-gotools:
3340
go get -v github.com/golang/lint/golint
3441

42+
test: test-style test-unit test-functional
43+
3544
test-style:
36-
go vet ./...
37-
-golint ./...
45+
# display output, then check
46+
$(GOFMT) $(GO_PACKAGES) $(GO_FILES)
47+
@$(GOFMT) $(GO_PACKAGES) $(GO_FILES) | read; if [ $$? == 0 ]; then echo "gofmt check failed."; exit 1; fi
48+
# FIXME: make this mandatory
49+
-$(GOVET) $(repo_path) $(GO_PACKAGES_REPO_PATH)
50+
# FIXME: make this mandatory
51+
-$(GOLINT) ./...
3852

3953
test-unit:
4054
godep go test -v -cover ./...
41-
42-
test: test-style test-unit

deisctl/backend/fleet/ssh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func runRemoteCommand(cmd string, addr string, timeout time.Duration) (exit int,
7373
defer sshClient.Close()
7474

7575
err, exit = ssh.Execute(sshClient, cmd)
76-
return
76+
return
7777
}
7878

7979
func machineState(machID string) (*machine.MachineState, error) {

includes.mk

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
1-
ifndef DEIS_NUM_INSTANCES
2-
DEIS_NUM_INSTANCES = 3
3-
endif
1+
SHELL = /bin/bash
42

5-
define echo_cyan
6-
@echo "\033[0;36m$(subst ",,$(1))\033[0m"
7-
endef
8-
9-
define echo_yellow
10-
@echo "\033[0;33m$(subst ",,$(1))\033[0m"
11-
endef
3+
GO = godep go
4+
GOFMT = gofmt -l
5+
GOLINT = golint
6+
GOTEST = $(GO) test --cover --race -v
7+
GOVET = $(GO) vet
128

139
SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
1410
DOCKER_HOST = $(shell echo $$DOCKER_HOST)
1511
REGISTRY = $(shell echo $$DEV_REGISTRY)
1612
GIT_SHA = $(shell git rev-parse --short HEAD)
13+
IMAGE_PREFIX := deis/
14+
1715
ifndef BUILD_TAG
1816
BUILD_TAG = git-$(GIT_SHA)
1917
endif
18+
2019
ifndef S3_BUCKET
2120
S3_BUCKET = deis-updates
2221
endif
23-
IMAGE_PREFIX := deis/
22+
23+
ifndef DEIS_NUM_INSTANCES
24+
DEIS_NUM_INSTANCES = 3
25+
endif
26+
27+
define echo_cyan
28+
@echo "\033[0;36m$(subst ",,$(1))\033[0m"
29+
endef
30+
31+
define echo_yellow
32+
@echo "\033[0;33m$(subst ",,$(1))\033[0m"
33+
endef
2434

2535
check-docker:
2636
@if [ -z $$(which docker) ]; then \

logger/Makefile

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
include ../includes.mk
22

3-
COMPONENT = logger
3+
# the filepath to this repository, relative to $GOPATH/src
4+
repo_path = github.com/deis/deis/logger
5+
6+
GO_FILES = main.go
7+
GO_PACKAGES = syslog syslogd
8+
GO_PACKAGES_REPO_PATH = $(addprefix $(repo_path)/,$(GO_PACKAGES))
9+
10+
COMPONENT = $(notdir $(repo_path))
411
IMAGE = $(IMAGE_PREFIX)$(COMPONENT):$(BUILD_TAG)
512
DEV_IMAGE = $(DEV_REGISTRY)/$(IMAGE)
613
BINARY_DEST_DIR = image/bin
@@ -46,8 +53,6 @@ release:
4653

4754
deploy: build dev-release restart
4855

49-
test: test-unit test-functional
50-
5156
setup-root-gotools:
5257
sudo GOPATH=/tmp/tmpGOPATH go get -u -v code.google.com/p/go.tools/cmd/cover
5358
sudo GOPATH=/tmp/tmpGOPATH go get -u -v code.google.com/p/go.tools/cmd/vet
@@ -56,17 +61,24 @@ setup-root-gotools:
5661
setup-gotools:
5762
go get -v github.com/golang/lint/golint
5863

59-
test-style:
60-
go vet -x ./...
61-
-golint ./...
62-
63-
test-unit: test-style
64-
go test -v -cover ./syslog
64+
test: test-style test-unit test-functional
6565

6666
test-functional:
6767
@docker history deis/test-etcd >/dev/null 2>&1 || docker pull deis/test-etcd:latest
6868
GOPATH=`cd ../tests/ && godep path`:$(GOPATH) go test -v ./tests/...
6969

70+
test-style:
71+
# display output, then check
72+
$(GOFMT) $(GO_PACKAGES) $(GO_FILES)
73+
@$(GOFMT) $(GO_PACKAGES) $(GO_FILES) | read; if [ $$? == 0 ]; then echo "gofmt check failed."; exit 1; fi
74+
# FIXME: make this mandatory
75+
-$(GOVET) $(repo_path) $(GO_PACKAGES_REPO_PATH)
76+
# FIXME: make this mandatory
77+
-$(GOLINT) ./...
78+
79+
test-unit: test-style
80+
$(GOTEST) $(GO_PACKAGES_REPO_PATH)
81+
7082
coverage:
7183
go test -coverprofile coverage.out ./syslog
7284
go tool cover -html=coverage.out

0 commit comments

Comments
 (0)