From bc6107508de265847452405a177bc5dd48bc0b51 Mon Sep 17 00:00:00 2001 From: James Nugent Date: Wed, 17 Feb 2016 11:39:12 -0800 Subject: [PATCH] Fix additional vet warnings --- Makefile | 2 +- .../resource_aws_iam_group_membership_test.go | 4 ++-- .../resource_vsphere_virtual_machine.go | 4 ++-- terraform/state_test.go | 9 --------- terraform/state_v1_test.go | 13 +++++++++++-- terraform/terraform_test.go | 19 ------------------- 6 files changed, 16 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index ccddba6d7..1666d0967 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ TEST?=$$(GO15VENDOREXPERIMENT=1 go list ./... | grep -v /vendor/) -VETARGS?=-asmdecl -atomic -bool -buildtags -composites -copylocks -methods -nilfunc -printf -rangeloops -shift -structtags -unsafeptr -unusedresult +VETARGS?=-asmdecl -atomic -bool -buildtags -composites -copylocks -methods -nilfunc -printf -rangeloops -shift -structtags -unreachable -unsafeptr -unusedresult default: test diff --git a/builtin/providers/aws/resource_aws_iam_group_membership_test.go b/builtin/providers/aws/resource_aws_iam_group_membership_test.go index cf63a0588..9fd65b5a6 100644 --- a/builtin/providers/aws/resource_aws_iam_group_membership_test.go +++ b/builtin/providers/aws/resource_aws_iam_group_membership_test.go @@ -18,7 +18,7 @@ func TestAccAWSGroupMembership_basic(t *testing.T) { rString := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha) configBase := fmt.Sprintf(testAccAWSGroupMemberConfig, rString, rString, rString) - configUpdate := fmt.Sprintf(testAccAWSGroupMemberConfigUpdate, rString, rString, rString, rString) + configUpdate := fmt.Sprintf(testAccAWSGroupMemberConfigUpdate, rString, rString, rString, rString, rString) configUpdateDown := fmt.Sprintf(testAccAWSGroupMemberConfigUpdateDown, rString, rString, rString) testUser := fmt.Sprintf("test-user-%s", rString) @@ -115,7 +115,7 @@ func testAccCheckAWSGroupMembershipExists(n string, g *iam.GetGroupOutput) resou func testAccCheckAWSGroupMembershipAttributes(group *iam.GetGroupOutput, users []string) resource.TestCheckFunc { return func(s *terraform.State) error { if !strings.Contains(*group.Group.GroupName, "test-group") { - return fmt.Errorf("Bad group membership: expected %d, got %d", "test-group", *group.Group.GroupName) + return fmt.Errorf("Bad group membership: expected %s, got %s", "test-group", *group.Group.GroupName) } uc := len(users) diff --git a/builtin/providers/vsphere/resource_vsphere_virtual_machine.go b/builtin/providers/vsphere/resource_vsphere_virtual_machine.go index 517872d54..2b0667427 100644 --- a/builtin/providers/vsphere/resource_vsphere_virtual_machine.go +++ b/builtin/providers/vsphere/resource_vsphere_virtual_machine.go @@ -922,7 +922,7 @@ func (vm *virtualMachine) createVirtualMachine(c *govmomi.Client) error { if d.Type == "StoragePod" { sp := object.StoragePod{ - object.NewFolder(c.Client, d), + Folder: object.NewFolder(c.Client, d), } sps := buildStoragePlacementSpecCreate(dcFolders, resourcePool, sp, configSpec) datastore, err = findDatastore(c, sps) @@ -1054,7 +1054,7 @@ func (vm *virtualMachine) deployVirtualMachine(c *govmomi.Client) error { if d.Type == "StoragePod" { sp := object.StoragePod{ - object.NewFolder(c.Client, d), + Folder: object.NewFolder(c.Client, d), } sps := buildStoragePlacementSpecClone(c, dcFolders, template, resourcePool, sp) datastore, err = findDatastore(c, sps) diff --git a/terraform/state_test.go b/terraform/state_test.go index 181360138..8351dc6ae 100644 --- a/terraform/state_test.go +++ b/terraform/state_test.go @@ -795,9 +795,6 @@ func TestReadWriteState(t *testing.T) { }, } - // Checksum before the write - chksum := checksumStruct(t, state) - buf := new(bytes.Buffer) if err := WriteState(state, buf); err != nil { t.Fatalf("err: %s", err) @@ -808,12 +805,6 @@ func TestReadWriteState(t *testing.T) { t.Fatalf("bad version number: %d", state.Version) } - // Checksum after the write - chksumAfter := checksumStruct(t, state) - if chksumAfter != chksum { - t.Fatalf("structure changed during serialization!") - } - actual, err := ReadState(buf) if err != nil { t.Fatalf("err: %s", err) diff --git a/terraform/state_v1_test.go b/terraform/state_v1_test.go index 0e7bc3aa1..c959e6efe 100644 --- a/terraform/state_v1_test.go +++ b/terraform/state_v1_test.go @@ -8,6 +8,8 @@ import ( "reflect" "sync" "testing" + + "github.com/mitchellh/hashstructure" ) func TestReadWriteStateV1(t *testing.T) { @@ -25,7 +27,10 @@ func TestReadWriteStateV1(t *testing.T) { } // Checksum before the write - chksum := checksumStruct(t, state) + chksum, err := hashstructure.Hash(state, nil) + if err != nil { + t.Fatalf("hash: %s", err) + } buf := new(bytes.Buffer) if err := testWriteStateV1(state, buf); err != nil { @@ -33,7 +38,11 @@ func TestReadWriteStateV1(t *testing.T) { } // Checksum after the write - chksumAfter := checksumStruct(t, state) + chksumAfter, err := hashstructure.Hash(state, nil) + if err != nil { + t.Fatalf("hash: %s", err) + } + if chksumAfter != chksum { t.Fatalf("structure changed during serialization!") } diff --git a/terraform/terraform_test.go b/terraform/terraform_test.go index 0fc0b71fe..09fb2370c 100644 --- a/terraform/terraform_test.go +++ b/terraform/terraform_test.go @@ -1,10 +1,6 @@ package terraform import ( - "bytes" - "crypto/sha1" - "encoding/gob" - "encoding/hex" "fmt" "io/ioutil" "os" @@ -21,21 +17,6 @@ import ( // This is the directory where our test fixtures are. const fixtureDir = "./test-fixtures" -func checksumStruct(t *testing.T, i interface{}) string { - // TODO(mitchellh): write a library to do this because gob is not - // deterministic in order - return "foo" - - buf := new(bytes.Buffer) - enc := gob.NewEncoder(buf) - if err := enc.Encode(i); err != nil { - t.Fatalf("err: %s", err) - } - - sum := sha1.Sum(buf.Bytes()) - return hex.EncodeToString(sum[:]) -} - func tempDir(t *testing.T) string { dir, err := ioutil.TempDir("", "tf") if err != nil {