Skip to content

Commit 1bf6ff1

Browse files
author
Matthew Fisher
committed
Merge pull request #2966 from bacongobbler/enforce-style-tests
test(*): enforce go fmt
2 parents 76cd8cf + 6d313a6 commit 1bf6ff1

22 files changed

Lines changed: 227 additions & 106 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ logspout/build/
4747
logspout/image/logspout
4848
logspout/Godeps/
4949
publisher/Godeps/
50+
publisher/image/bin/publisher
5051
router/Godeps/
5152

5253
# coverage reports

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: 5 additions & 16 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
@@ -175,17 +174,6 @@ def __init__(self):
175174
self._path = os.path.join(path, 'client.json')
176175
if not os.path.exists(self._path):
177176
settings = {}
178-
# try once to convert the old settings file if it exists
179-
# FIXME: this code can be removed in November 2014 or thereabouts, that's long enough.
180-
old_path = os.path.join(path, 'client.yaml')
181-
if os.path.exists(old_path):
182-
try:
183-
with open(old_path, 'r') as f:
184-
txt = f.read().replace('{', '{"', 1).replace(':', '":', 1).replace("'", '"')
185-
settings = json.loads(txt)
186-
os.remove(old_path)
187-
except:
188-
pass # ignore errors, at least we tried to convert it
189177
with open(self._path, 'w') as f:
190178
json.dump(settings, f)
191179
# load initial settings
@@ -638,6 +626,7 @@ def apps_logs(self, args):
638626
log_tag = line.split(': ')[0].split(' ')[1]
639627
# colorize the log based on the tag
640628
color = sum([ord(ch) for ch in log_tag]) % 6
629+
641630
def f(x):
642631
return {
643632
0: 'green',
@@ -797,7 +786,6 @@ def auth_login(self, args):
797786
if not urlparse.urlparse(controller).scheme:
798787
controller = "http://{}".format(controller)
799788
username = args.get('--username')
800-
headers = {}
801789
if not username:
802790
username = raw_input('username: ')
803791
password = args.get('--password')
@@ -810,7 +798,7 @@ def auth_login(self, args):
810798
payload = {'username': username, 'password': password}
811799
# post credentials to the login URL
812800
response = self._session.post(url, data=payload, allow_redirects=False,
813-
verify=ssl_verify)
801+
verify=ssl_verify)
814802
if response.status_code == requests.codes.ok:
815803
# retrieve and save the API token for future requests
816804
self._settings['controller'] = controller
@@ -1562,8 +1550,9 @@ def tags_set(self, args):
15621550
"""
15631551
Sets tags for an application.
15641552
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.
1553+
A tag is a key/value pair used to tag an application's containers and is passed to the
1554+
scheduler. This is often used to restrict workloads to specific hosts matching the
1555+
scheduler-configured metadata.
15671556
15681557
Usage: deis tags:set [options] <key>=<value>...
15691558

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 \

0 commit comments

Comments
 (0)