From 432bf7d99e5c24c074a1c2bac0f2fadc9891e0a0 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 2 Jun 2017 14:05:51 -0700 Subject: [PATCH] Fail if formatting is wrong in our CI tests. (#4459) We didn't fail before, we should helps in avoiding formatting issues to creep into the codebase. --- .travis.yml | 2 ++ Makefile | 62 +++++++++++++++----------------------- cmd/admin-handlers_test.go | 10 +++--- cmd/gateway-main.go | 5 +-- cmd/storage-rpc-client.go | 2 +- cmd/xl-v1-metadata_test.go | 2 +- 6 files changed, 37 insertions(+), 46 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2052a4fd6..e37f4da01 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,8 @@ env: script: ## Run all the tests - make +- diff -au <(gofmt -d cmd) <(printf "") +- diff -au <(gofmt -d pkg) <(printf "") - make test GOFLAGS="-timeout 15m -race -v" - make coverage diff --git a/Makefile b/Makefile index 4db4954ba..27a10392f 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ LDFLAGS := $(shell go run buildscripts/gen-ldflags.go) PWD := $(shell pwd) GOPATH := $(shell go env GOPATH) + BUILD_LDFLAGS := '$(LDFLAGS)' TAG := latest @@ -56,55 +57,43 @@ endif all: install checks: - @echo -n "Check deps: " + @echo "Check deps" @(env bash $(PWD)/buildscripts/checkdeps.sh) - @echo "Done." - @echo -n "Checking project is in GOPATH: " + @echo "Checking project is in GOPATH" @(env bash $(PWD)/buildscripts/checkgopath.sh) - @echo "Done." getdeps: checks - @echo -n "Installing golint: " && go get -u github.com/golang/lint/golint - @echo "Done." - @echo -n "Installing gocyclo: " && go get -u github.com/fzipp/gocyclo - @echo "Done." - @echo -n "Installing deadcode: " && go get -u github.com/remyoudompheng/go-misc/deadcode - @echo "Done." - @echo -n "Installing misspell: " && go get -u github.com/client9/misspell/cmd/misspell - @echo "Done." - @echo -n "Installing ineffassign: " && go get -u github.com/gordonklaus/ineffassign - @echo "Done." + @echo "Installing golint" && go get -u github.com/golang/lint/golint + @echo "Installing gocyclo" && go get -u github.com/fzipp/gocyclo + @echo "Installing deadcode" && go get -u github.com/remyoudompheng/go-misc/deadcode + @echo "Installing misspell" && go get -u github.com/client9/misspell/cmd/misspell + @echo "Installing ineffassign" && go get -u github.com/gordonklaus/ineffassign verifiers: vet fmt lint cyclo spelling vet: - @echo -n "Running $@: " + @echo "Running $@" @go tool vet -atomic -bool -copylocks -nilfunc -printf -shadow -rangeloops -unreachable -unsafeptr -unusedresult cmd @go tool vet -atomic -bool -copylocks -nilfunc -printf -shadow -rangeloops -unreachable -unsafeptr -unusedresult pkg - @echo "Done." fmt: - @echo -n "Running $@: " - @gofmt -s -l cmd - @gofmt -s -l pkg - @echo "Done." + @echo "Running $@" + @gofmt -d cmd + @gofmt -d pkg lint: - @echo -n "Running $@: " + @echo "Running $@" @${GOPATH}/bin/golint -set_exit_status github.com/minio/minio/cmd... @${GOPATH}/bin/golint -set_exit_status github.com/minio/minio/pkg... - @echo "Done." ineffassign: - @echo -n "Running $@: " + @echo "Running $@" @${GOPATH}/bin/ineffassign . - @echo "Done." cyclo: - @echo -n "Running $@: " + @echo "Running $@" @${GOPATH}/bin/gocyclo -over 100 cmd @${GOPATH}/bin/gocyclo -over 100 pkg - @echo "Done." build: getdeps verifiers $(UI_ASSETS) @@ -117,30 +106,30 @@ spelling: @${GOPATH}/bin/misspell -error `find docs/` test: build - @echo -n "Running all minio testing: " + @echo "Running all minio testing" @go test $(GOFLAGS) . @go test $(GOFLAGS) github.com/minio/minio/cmd... @go test $(GOFLAGS) github.com/minio/minio/pkg... - @echo "Done." coverage: build - @echo "Running all coverage for minio: " + @echo "Running all coverage for minio" @./buildscripts/go-coverage.sh - @echo "Done." gomake-all: build - @echo -n "Installing minio at $(GOPATH)/bin/minio: " + @echo "Installing minio at $(GOPATH)/bin/minio" @go build --ldflags $(BUILD_LDFLAGS) -o $(GOPATH)/bin/minio - @echo "Done." pkg-add: - ${GOPATH}/bin/govendor add $(PKG) + @echo "Adding new package $(PKG)" + @${GOPATH}/bin/govendor add $(PKG) pkg-update: - ${GOPATH}/bin/govendor update $(PKG) + @echo "Updating new package $(PKG)" + @${GOPATH}/bin/govendor update $(PKG) pkg-remove: - ${GOPATH}/bin/govendor remove $(PKG) + @echo "Remove new package $(PKG)" + @${GOPATH}/bin/govendor remove $(PKG) pkg-list: @$(GOPATH)/bin/govendor list @@ -154,8 +143,7 @@ experimental: verifiers @MINIO_RELEASE=EXPERIMENTAL ./buildscripts/build.sh clean: - @echo -n "Cleaning up all the generated files: " + @echo "Cleaning up all the generated files" @find . -name '*.test' | xargs rm -fv @rm -rf build @rm -rf release - @echo "Done." diff --git a/cmd/admin-handlers_test.go b/cmd/admin-handlers_test.go index deba24f5b..f737a1a6f 100644 --- a/cmd/admin-handlers_test.go +++ b/cmd/admin-handlers_test.go @@ -731,7 +731,7 @@ func TestListObjectsHealHandler(t *testing.T) { } defer adminTestBed.TearDown() - err = adminTestBed.objLayer.MakeBucketWithLocation("mybucket","") + err = adminTestBed.objLayer.MakeBucketWithLocation("mybucket", "") if err != nil { t.Fatalf("Failed to make bucket - %v", err) } @@ -859,7 +859,7 @@ func TestHealBucketHandler(t *testing.T) { } defer adminTestBed.TearDown() - err = adminTestBed.objLayer.MakeBucketWithLocation("mybucket","") + err = adminTestBed.objLayer.MakeBucketWithLocation("mybucket", "") if err != nil { t.Fatalf("Failed to make bucket - %v", err) } @@ -936,7 +936,7 @@ func TestHealObjectHandler(t *testing.T) { // Create an object myobject under bucket mybucket. bucketName := "mybucket" objName := "myobject" - err = adminTestBed.objLayer.MakeBucketWithLocation(bucketName,"") + err = adminTestBed.objLayer.MakeBucketWithLocation(bucketName, "") if err != nil { t.Fatalf("Failed to make bucket %s - %v", bucketName, err) } @@ -1067,7 +1067,7 @@ func TestHealUploadHandler(t *testing.T) { // Create an object myobject under bucket mybucket. bucketName := "mybucket" objName := "myobject" - err = adminTestBed.objLayer.MakeBucketWithLocation(bucketName,"") + err = adminTestBed.objLayer.MakeBucketWithLocation(bucketName, "") if err != nil { t.Fatalf("Failed to make bucket %s - %v", bucketName, err) } @@ -1455,7 +1455,7 @@ func TestListHealUploadsHandler(t *testing.T) { } defer adminTestBed.TearDown() - err = adminTestBed.objLayer.MakeBucketWithLocation("mybucket","") + err = adminTestBed.objLayer.MakeBucketWithLocation("mybucket", "") if err != nil { t.Fatalf("Failed to make bucket - %v", err) } diff --git a/cmd/gateway-main.go b/cmd/gateway-main.go index cd48525b6..254d02ec9 100644 --- a/cmd/gateway-main.go +++ b/cmd/gateway-main.go @@ -99,7 +99,7 @@ func mustGetGatewayCredsFromEnv() (accessKey, secretKey string) { } // Set browser setting from environment variables -func mustSetBrowserSettingFromEnv(){ +func mustSetBrowserSettingFromEnv() { if browser := os.Getenv("MINIO_BROWSER"); browser != "" { browserFlag, err := ParseBrowserFlag(browser) if err != nil { @@ -112,6 +112,7 @@ func mustSetBrowserSettingFromEnv(){ globalIsBrowserEnabled = bool(browserFlag) } } + // Initialize gateway layer depending on the backend type. // Supported backend types are // @@ -192,7 +193,7 @@ func gatewayMain(ctx *cli.Context) { mustSetBrowserSettingFromEnv() // Initialize new gateway config. - + newGatewayConfig(accessKey, secretKey, globalMinioDefaultRegion) // Get quiet flag from command line argument. diff --git a/cmd/storage-rpc-client.go b/cmd/storage-rpc-client.go index ee31587b1..982e5e158 100644 --- a/cmd/storage-rpc-client.go +++ b/cmd/storage-rpc-client.go @@ -28,7 +28,7 @@ import ( ) type networkStorage struct { - rpcClient *AuthRPCClient + rpcClient *AuthRPCClient } const ( diff --git a/cmd/xl-v1-metadata_test.go b/cmd/xl-v1-metadata_test.go index 028d116ea..fa7f35543 100644 --- a/cmd/xl-v1-metadata_test.go +++ b/cmd/xl-v1-metadata_test.go @@ -113,7 +113,7 @@ func testXLReadMetaParts(obj ObjectLayer, instanceType string, disks []string, t // objectNames[0]. // uploadIds [0]. // Create bucket before intiating NewMultipartUpload. - err := obj.MakeBucketWithLocation(bucketNames[0] ,"") + err := obj.MakeBucketWithLocation(bucketNames[0], "") if err != nil { // Failed to create newbucket, abort. t.Fatalf("%s : %s", instanceType, err.Error())