hashicorp / packer-plugin-vsphere

Packer plugin for VMware vSphere Builder
https://www.packer.io/docs/builders/vsphere
Mozilla Public License 2.0
93 stars 91 forks source link

refactor(tests): standardize messages #448

Closed tenthirtyam closed 1 week ago

tenthirtyam commented 2 weeks ago

Description

Standardizes the messages returned in tests.

Examples:

if err != nil {
-    t.Fatalf("should not fail: %s", err.Error())
+    t.Fatalf("unexpected error: '%s'", err)
}
if action := c.step.Run(context.TODO(), state); action != c.expectedAction {
-    t.Fatalf("unexpected action %v", action)
+    t.Fatalf("unexpected action: expected '%#v', but returned '%#v'", c.expectedAction, action)
}
if c.fail {
-    t.Fatalf("expected to fail but it didn't")
+    t.Fatal("unexpected success: expected failure")
}
if !driverMock.DatastoreMock.UploadFileCalled {
-    t.Fatalf("datastore.UploadFile should be called.")
+    t.Fatalf("unexpected result: '%s' should be called", "UploadFile")
}

Testing

packer-plugin-vsphere on  refactor(tests)/standardize-messages
➜ go fmt ./...

packer-plugin-vsphere on  refactor(tests)/standardize-messages
➜ make build

packer-plugin-vsphere on  refactor(tests)/standardize-messages
➜ make generate
2024/06/24 10:18:02 Copying "docs" to ".docs/"
2024/06/24 10:18:02 Replacing @include '...' calls in .docs/
Compiling MDX docs in '.docs' to Markdown in '.web-docs'...

packer-plugin-vsphere on  refactor(tests)/standardize-messages
➜ make test
?       github.com/hashicorp/packer-plugin-vsphere      [no test files]
?       github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/common/testing       [no test files]
ok      github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/clone        2.360s
?       github.com/hashicorp/packer-plugin-vsphere/examples/driver      [no test files]
?       github.com/hashicorp/packer-plugin-vsphere/version      [no test files]
ok      github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/common       5.195s
ok      github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/driver       7.213s
ok      github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/iso  5.585s
ok      github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/supervisor   8.741s
ok      github.com/hashicorp/packer-plugin-vsphere/post-processor/vsphere       3.655s
ok      github.com/hashicorp/packer-plugin-vsphere/post-processor/vsphere-template      4.749s

packer-plugin-vsphere on  refactor(tests)/standardize-messages
➜ make dev
packer plugins install --path packer-plugin-vsphere "github.com/hashicorp/vsphere"
Successfully installed plugin github.com/hashicorp/vsphere from /Users/johnsonryan/Library/Mobile Documents/com~apple~CloudDocs/Code/Work/packer-plugin-vsphere/packer-plugin-vsphere to /Users/johnsonryan/.packer.d/plugins/github.com/hashicorp/vsphere/packer-plugin-vsphere_v1.3.1-dev_x5.0_darwin_amd64
tenthirtyam commented 2 weeks ago

Ah! An update from the SDK change! Doh!

tenthirtyam commented 2 weeks ago

I missed that because Lucas and were needing to do that in #431 last week.