From ac629404f499a34d71db71b995d79893d5aff565 Mon Sep 17 00:00:00 2001 From: Guillaume Herail Date: Fri, 24 Nov 2017 16:07:17 +0100 Subject: [PATCH] test: Switch to goimports instead of gofmt see https://github.com/purpleidea/mgmt/pull/256#issuecomment-346360414 --- Makefile | 4 +++- prometheus/prometheus_test.go | 8 ++++---- resources/aws_ec2.go | 2 +- test/test-gofmt.sh | 11 +++++++++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index a8dc3871..fbc1ab92 100644 --- a/Makefile +++ b/Makefile @@ -124,7 +124,9 @@ test: ./test.sh gofmt: - find . -maxdepth 3 -type f -name '*.go' -not -path './old/*' -not -path './tmp/*' -exec gofmt -w {} \; + # TODO: remove gofmt once goimports has a -s option + find . -maxdepth 3 -type f -name '*.go' -not -path './old/*' -not -path './tmp/*' -exec gofmt -s -w {} \; + find . -maxdepth 3 -type f -name '*.go' -not -path './old/*' -not -path './tmp/*' -exec goimports -w {} \; yamlfmt: find . -maxdepth 3 -type f -name '*.yaml' -not -path './old/*' -not -path './tmp/*' -not -path './omv.yaml' -exec ruby -e "require 'yaml'; x=YAML.load_file('{}').to_yaml.each_line.map(&:rstrip).join(10.chr)+10.chr; File.open('{}', 'w').write x" \; diff --git a/prometheus/prometheus_test.go b/prometheus/prometheus_test.go index d4b396a4..3b6f5c58 100644 --- a/prometheus/prometheus_test.go +++ b/prometheus/prometheus_test.go @@ -44,16 +44,16 @@ func TestInitKindMetrics(t *testing.T) { // values are expected and actual count of metrics with // that name. expectedMetrics := map[string][2]int{ - "mgmt_checkapply_total": [2]int{ + "mgmt_checkapply_total": { 16, 0, }, - "mgmt_failures_total": [2]int{ + "mgmt_failures_total": { 4, 0, }, - "mgmt_failures": [2]int{ + "mgmt_failures": { 4, 0, }, - "mgmt_resources": [2]int{ + "mgmt_resources": { 2, 0, }, } diff --git a/resources/aws_ec2.go b/resources/aws_ec2.go index fed5416e..1737265f 100644 --- a/resources/aws_ec2.go +++ b/resources/aws_ec2.go @@ -692,7 +692,7 @@ func (obj *AwsEc2Res) CheckApply(apply bool) (checkOK bool, err error) { _, err = obj.client.CreateTags(&ec2.CreateTagsInput{ Resources: []*string{runResult.Instances[0].InstanceId}, Tags: []*ec2.Tag{ - &ec2.Tag{ + { Key: aws.String("Name"), Value: aws.String(obj.prependName()), }, diff --git a/test/test-gofmt.sh b/test/test-gofmt.sh index dd101deb..ed3f323a 100755 --- a/test/test-gofmt.sh +++ b/test/test-gofmt.sh @@ -22,9 +22,16 @@ find_files() { git ls-files | grep '\.go$' } -GOFMT="gofmt" # we prefer to not use the -s flag, which is pretty annoying... +# gofmt -s -l +GOFMT="gofmt" +bad_files=$(find_files | xargs $GOFMT -s -l) +if [[ -n "${bad_files}" ]]; then + fail_test "The following golang files are not properly formatted (gofmt -s -l): ${bad_files}" +fi +#goimports -l +GOFMT="goimports" bad_files=$(find_files | xargs $GOFMT -l) if [[ -n "${bad_files}" ]]; then - fail_test "The following golang files are not properly formatted: ${bad_files}" + fail_test "The following golang files are not properly formatted (goimports -l): ${bad_files}" fi echo 'PASS'