[HPR-1100] Add basic test for commonServer.ConfigSpec#176
Merged
Conversation
added 2 commits
April 21, 2023 11:43
The Packer SDK relies on encoding/gob for serializing hcldec.ObjectSpec
over RPC. The added test check that types implementing the HCL2Speccer
interface can be encoded/decoded without issue.
Starting in go-cty v1.11.0 support for encoding/gob was removed, which
causes the added tests to fail. This is expected and is meant to help
catch potential regressions moving forward.
Test results running go-cty v1.10.0
```
--- PASS: TestCommonServer_ConfigSpec (0.00s)
--- PASS: TestCommonServer_ConfigSpec/Builder_Component_Server (0.00s)
--- PASS: TestCommonServer_ConfigSpec/Datasource_Component_Server (0.00s)
--- PASS: TestCommonServer_ConfigSpec/Provisioner_Component_Server (0.00s)
=== RUN TestCommunicatorRPC
```
Test results running go-cty v1.13.1
```
2023/04/21 11:28:05 [WARN] Client is closing mux
--- FAIL: TestCommonServer_ConfigSpec (0.00s)
--- FAIL: TestCommonServer_ConfigSpec/Builder_Component_Server (0.00s)
panic: ConfigSpec failed: gob: type cty.Type has no exported fields [recovered]
panic: ConfigSpec failed: gob: type cty.Type has no exported fields
goroutine 299 [running]:
testing.tRunner.func1.2({0x10524fb60, 0x14000486530})
/usr/local/go/src/testing/testing.go:1389 +0x1c8
testing.tRunner.func1()
/usr/local/go/src/testing/testing.go:1392 +0x384
panic({0x10524fb60, 0x14000486530})
/usr/local/go/src/runtime/panic.go:838 +0x204
github.com/hashicorp/packer-plugin-sdk/rpc.(*commonClient).ConfigSpec(0x14000475f08)
/Users/dev/Development/packer-plugin-sdk/rpc/common.go:48 +0x24c
github.com/hashicorp/packer-plugin-sdk/rpc.TestCommonServer_ConfigSpec.func1(0x140004e5860)
/Users/dev/Development/packer-plugin-sdk/rpc/common_test.go:44 +0x10c
testing.tRunner(0x140004e5860, 0x14000483dd0)
/usr/local/go/src/testing/testing.go:1439 +0x110
created by testing.(*T).Run
/usr/local/go/src/testing/testing.go:1486 +0x300
FAIL github.com/hashicorp/packer-plugin-sdk/rpc 0.796s
```
```
~> go get github.com/zclconf/go-cty@v1.13.1
~> go test ./rpc/... -v -run=TestCommonServer
=== RUN TestCommonServer_ConfigSpec
=== RUN TestCommonServer_ConfigSpec/Builder_Component_Server
common_test.go:75: Call to ConfigSpec for Builder Component Server panicked: ConfigSpec failed: gob: type cty.Type has no exported fields
2023/04/21 14:31:27 [WARN] Shutting down mux conn in Server
2023/04/21 14:31:27 [WARN] Client is closing mux
=== RUN TestCommonServer_ConfigSpec/Datasource_Component_Server
common_test.go:75: Call to ConfigSpec for Datasource Component Server panicked: ConfigSpec failed: gob: type cty.Type has no exported fields
2023/04/21 14:31:27 [WARN] Shutting down mux conn in Server
2023/04/21 14:31:27 [WARN] Client is closing mux
=== RUN TestCommonServer_ConfigSpec/Provisioner_Component_Server
common_test.go:75: Call to ConfigSpec for Provisioner Component Server panicked: ConfigSpec failed: gob: type cty.Type has no exported fields
2023/04/21 14:31:27 [WARN] Shutting down mux conn in Server
2023/04/21 14:31:27 [WARN] Client is closing mux
--- FAIL: TestCommonServer_ConfigSpec (0.00s)
--- FAIL: TestCommonServer_ConfigSpec/Builder_Component_Server (0.00s)
--- FAIL: TestCommonServer_ConfigSpec/Datasource_Component_Server (0.00s)
--- FAIL: TestCommonServer_ConfigSpec/Provisioner_Component_Server (0.00s)
FAIL
FAIL github.com/hashicorp/packer-plugin-sdk/rpc 0.278s
FAIL
```
nywilken
commented
Apr 21, 2023
|
|
||
| defer func() { | ||
| if r := recover(); r != nil { | ||
| t.Errorf("Call to ConfigSpec for %s panicked: %v", tc.name, r) |
Contributor
Author
There was a problem hiding this comment.
I opted to recover from the panic and fail the test so that we can add a help message to developers with instructions on how to resolve the go-cty encoding issue. It also allows for all component types to be tested without completely bailing.
lbajolet-hashicorp
approved these changes
Apr 24, 2023
Contributor
lbajolet-hashicorp
left a comment
There was a problem hiding this comment.
Just left one comment, but aside from that, LGTM!
rpc/common_test.go
Outdated
| packersdk "github.com/hashicorp/packer-plugin-sdk/packer" | ||
| ) | ||
|
|
||
| var b testing.B |
Contributor
There was a problem hiding this comment.
This isn't used anywhere, is it?
Contributor
Author
There was a problem hiding this comment.
LOL - good catch. That is a left over from my empty test file.
nywilken
commented
Apr 24, 2023
4e5a784 to
0c383dd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Packer SDK relies on encoding/gob for serializing hcldec.ObjectSpec over RPC. The added test check that types implementing the HCL2Speccer interface can be encoded/decoded without issue.
Starting in go-cty v1.11.0 support for encoding/gob was removed, which causes the added tests to fail. This is expected and is meant to help catch potential regressions moving forward.
Test results running go-cty v1.10.0
Test results running go-cty v1.13.1
Using local fork of zclconf/go-ctyv1.12.1 with
encoding/gob