add gofmt checks to Vault and format existing code (#2745)

This commit is contained in:
emily
2017-05-19 05:34:17 -07:00
committed by Vishal Nayak
parent 3ba9486ba9
commit 38ffde5a9d
8 changed files with 37 additions and 19 deletions

View File

@@ -3,11 +3,12 @@ VETARGS?=-asmdecl -atomic -bool -buildtags -copylocks -methods -nilfunc -printf
EXTERNAL_TOOLS=\
github.com/mitchellh/gox
BUILD_TAGS?=vault
GOFMT_FILES?=$$(find . -name '*.go' | grep -v vendor)
default: dev
# bin generates the releaseable binaries for Vault
bin: generate
bin: fmtcheck generate
@CGO_ENABLED=0 BUILD_TAGS='$(BUILD_TAGS)' sh -c "'$(CURDIR)/scripts/build.sh'"
# dev creates binaries for testing Vault locally. These are put
@@ -15,22 +16,22 @@ bin: generate
# is only put into /bin/
quickdev: generate
@CGO_ENABLED=0 go build -i -tags='$(BUILD_TAGS)' -o bin/vault
dev: generate
dev: fmtcheck generate
@CGO_ENABLED=0 BUILD_TAGS='$(BUILD_TAGS)' VAULT_DEV_BUILD=1 sh -c "'$(CURDIR)/scripts/build.sh'"
dev-dynamic: generate
@CGO_ENABLED=1 BUILD_TAGS='$(BUILD_TAGS)' VAULT_DEV_BUILD=1 sh -c "'$(CURDIR)/scripts/build.sh'"
# test runs the unit tests and vets the code
test: generate
test: fmtcheck generate
CGO_ENABLED=0 VAULT_TOKEN= VAULT_ACC= go test -tags='$(BUILD_TAGS)' $(TEST) $(TESTARGS) -timeout=20m -parallel=4
testcompile: generate
testcompile: fmtcheck generate
@for pkg in $(TEST) ; do \
go test -v -c -tags='$(BUILD_TAGS)' $$pkg -parallel=4 ; \
done
# testacc runs acceptance tests
testacc: generate
testacc: fmtcheck generate
@if [ "$(TEST)" = "./..." ]; then \
echo "ERROR: Set TEST to a specific package"; \
exit 1; \
@@ -38,7 +39,7 @@ testacc: generate
VAULT_ACC=1 go test -tags='$(BUILD_TAGS)' $(TEST) -v $(TESTARGS) -timeout 45m
# testrace runs the race checker
testrace: generate
testrace: fmtcheck generate
CGO_ENABLED=1 VAULT_TOKEN= VAULT_ACC= go test -tags='$(BUILD_TAGS)' -race $(TEST) $(TESTARGS) -timeout=20m -parallel=4
cover:
@@ -71,4 +72,11 @@ proto:
protoc -I helper/forwarding -I vault -I ../../.. vault/*.proto --go_out=plugins=grpc:vault
protoc -I helper/forwarding -I vault -I ../../.. helper/forwarding/types.proto --go_out=plugins=grpc:helper/forwarding
.PHONY: bin default generate test vet bootstrap
fmtcheck:
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"
fmt:
gofmt -w $(GOFMT_FILES)
.PHONY: bin default generate test vet bootstrap fmt fmtcheck

View File

@@ -6,11 +6,11 @@ import (
"net/http"
"net/url"
"os"
"path"
"strconv"
"strings"
"sync"
"time"
"path"
"golang.org/x/net/http2"

View File

@@ -5,9 +5,9 @@ import (
"net/url"
"time"
"github.com/fatih/structs"
"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/logical/framework"
"github.com/fatih/structs"
)
func pathConfig(b *backend) *framework.Path {
@@ -37,7 +37,7 @@ API-compatible authentication server.`,
Callbacks: map[logical.Operation]framework.OperationFunc{
logical.UpdateOperation: b.pathConfigWrite,
logical.ReadOperation: b.pathConfigRead,
logical.ReadOperation: b.pathConfigRead,
},
}
}
@@ -77,10 +77,10 @@ func (b *backend) pathConfigWrite(
}
entry, err := logical.StorageEntryJSON("config", config{
Organization: organization,
BaseURL: baseURL,
TTL: ttl,
MaxTTL: maxTTL,
Organization: organization,
BaseURL: baseURL,
TTL: ttl,
MaxTTL: maxTTL,
})
if err != nil {

View File

@@ -72,7 +72,7 @@ func (c *AuditEnableCommand) Run(args []string) int {
}
err = client.Sys().EnableAuditWithOptions(path, &api.EnableAuditOptions{
Type: auditType,
Type: auditType,
Description: desc,
Options: opts,
Local: local,

View File

@@ -10,8 +10,8 @@ import (
"github.com/hashicorp/errwrap"
"github.com/hashicorp/vault/helper/consts"
"github.com/hashicorp/vault/helper/parseutil"
"github.com/hashicorp/vault/helper/jsonutil"
"github.com/hashicorp/vault/helper/parseutil"
"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/vault"
)

11
scripts/gofmtcheck.sh Executable file
View File

@@ -0,0 +1,11 @@
#!/usr/bin/env bash
echo "==> Checking that code complies with gofmt requirements..."
gofmt_files=$(gofmt -l `find . -name '*.go' | grep -v vendor`)
if [[ -n ${gofmt_files} ]]; then
echo 'gofmt needs running on the following files:'
echo "${gofmt_files}"
echo "You can use the command: \`make fmt\` to reformat code."
exit 1
fi

View File

@@ -98,7 +98,6 @@ func (v *BarrierView) Delete(key string) error {
return logical.ErrReadOnly
}
return v.barrier.Delete(expandedKey)
}