Repository: deis/deis

Issue:
"make test-style" should use "gofmt -l" to verify formatting
In our coding standards we ask for all go code to be run through `gofmt`. We could probably enforce this using `gofmt -l ./...` and checking the output or return code in the appropriate Makefiles.



Discussion:
[Here is one way](https://github.com/coreos/rocket/blob/master/test#L49-L54) to implement `gofmt` checking in a build script.


Resolving patch:
diff --git a/client/deis.py b/client/deis.py
--- a/client/deis.py
+++ b/client/deis.py
@@ -47,7 +47,6 @@
 from itertools import cycle
 from threading import Event
 from threading import Thread
-import base64
 import glob
 import json
 import locale
@@ -175,17 +174,6 @@ def __init__(self):
         self._path = os.path.join(path, 'client.json')
         if not os.path.exists(self._path):
             settings = {}
-            # try once to convert the old settings file if it exists
-            # FIXME: this code can be removed in November 2014 or thereabouts, that's long enough.
-            old_path = os.path.join(path, 'client.yaml')
-            if os.path.exists(old_path):
-                try:
-                    with open(old_path, 'r') as f:
-                        txt = f.read().replace('{', '{"', 1).replace(':', '":', 1).replace("'", '"')
-                        settings = json.loads(txt)
-                        os.remove(old_path)
-                except:
-                    pass  # ignore errors, at least we tried to convert it
             with open(self._path, 'w') as f:
                 json.dump(settings, f)
         # load initial settings
@@ -638,6 +626,7 @@ def apps_logs(self, args):
                     log_tag = line.split(': ')[0].split(' ')[1]
                     # colorize the log based on the tag
                     color = sum([ord(ch) for ch in log_tag]) % 6
+
                     def f(x):
                         return {
                             0: 'green',
@@ -797,7 +786,6 @@ def auth_login(self, args):
         if not urlparse.urlparse(controller).scheme:
             controller = "http://{}".format(controller)
         username = args.get('--username')
-        headers = {}
         if not username:
             username = raw_input('username: ')
         password = args.get('--password')
@@ -810,7 +798,7 @@ def auth_login(self, args):
         payload = {'username': username, 'password': password}
         # post credentials to the login URL
         response = self._session.post(url, data=payload, allow_redirects=False,
-            verify=ssl_verify)
+                                      verify=ssl_verify)
         if response.status_code == requests.codes.ok:
             # retrieve and save the API token for future requests
             self._settings['controller'] = controller
@@ -1562,8 +1550,9 @@ def tags_set(self, args):
         """
         Sets tags for an application.
 
-        A tag is a key/value pair used to tag an application's containers and is passed to the scheduler.
-        This is often used to restrict workloads to specific hosts matching the scheduler-configured metadata.
+        A tag is a key/value pair used to tag an application's containers and is passed to the
+        scheduler. This is often used to restrict workloads to specific hosts matching the
+        scheduler-configured metadata.
 
         Usage: deis tags:set [options] <key>=<value>...
 


Test patch:
diff --git a/builder/utils_test.go b/builder/utils_test.go
--- a/builder/utils_test.go
+++ b/builder/utils_test.go
@@ -7,6 +7,7 @@ import (
 	"strings"
 	"testing"
 	"time"
+
 	dtime "github.com/deis/deis/pkg/time"
 )
 
diff --git a/tests/Makefile b/tests/Makefile
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,5 +1,14 @@
 include ../includes.mk
 
+# the filepath to this repository, relative to $GOPATH/src
+repo_path = github.com/deis/deis/tests
+
+GO_FILES = apps_test.go auth_test.go builds_test.go config_test.go integration_test.go \
+			keys_test.go limits_test.go main.go perms_test.go ps_test.go releases_test.go \
+			smoke_test.go tags_test.go
+GO_PACKAGES = dockercli etcdutils mock utils
+GO_PACKAGES_REPO_PATH = $(addprefix $(repo_path)/,$(GO_PACKAGES))
+
 MOCK_STORE_IMAGE = $(IMAGE_PREFIX)mock-store:latest
 
 test: test-smoke
@@ -30,8 +39,13 @@ mock-store:
 	docker build -t $(MOCK_STORE_IMAGE) fixtures/mock-store/
 
 test-style:
-	go vet -x ./...
-	-golint ./...
+# display output, then check
+	$(GOFMT) $(GO_PACKAGES) $(GO_FILES)
+	@$(GOFMT) $(GO_PACKAGES) $(GO_FILES) | read; if [ $$? == 0 ]; then echo "gofmt check failed."; exit 1; fi
+# FIXME: make this mandatory
+	-$(GOVET) $(repo_path) $(GO_PACKAGES_REPO_PATH)
+# FIXME: make this mandatory
+	-$(GOLINT) ./...
 
 nuke_from_orbit:
 	-docker kill `docker ps -q`
diff --git a/tests/bin/test-integration.sh b/tests/bin/test-integration.sh
--- a/tests/bin/test-integration.sh
+++ b/tests/bin/test-integration.sh
@@ -17,6 +17,10 @@ source $THIS_DIR/test-setup.sh
 trap cleanup EXIT
 trap dump_logs ERR
 
+log_phase "Running style tests"
+
+make test-style
+
 log_phase "Running documentation tests"
 
 # test building documentation