Fix type conversion panic

etcdv3 acceptance tests fail due to attempting to pass slices of strings
for the endpoints config to HCL2ValueFromConfigValue() which does not
handle that type.

Not a pretty solution but a helper function that converts the endpoints to a slice of
empty interfaces satisfies the requirements of the
HCL2ValueFromConfigValue function.

fixes https://github.com/hashicorp/terraform/issues/28096
This commit is contained in:
Jason Smith 2021-03-15 16:09:44 -05:00
parent 0750a16cce
commit 3e8ebd6f40
2 changed files with 16 additions and 8 deletions

View File

@ -60,12 +60,12 @@ func TestBackend(t *testing.T) {
// Get the backend. We need two to test locking. // Get the backend. We need two to test locking.
b1 := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{ b1 := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{
"endpoints": etcdv3Endpoints, "endpoints": stringsToInterfaces(etcdv3Endpoints),
"prefix": prefix, "prefix": prefix,
})) }))
b2 := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{ b2 := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{
"endpoints": etcdv3Endpoints, "endpoints": stringsToInterfaces(etcdv3Endpoints),
"prefix": prefix, "prefix": prefix,
})) }))
@ -83,13 +83,13 @@ func TestBackend_lockDisabled(t *testing.T) {
// Get the backend. We need two to test locking. // Get the backend. We need two to test locking.
b1 := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{ b1 := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{
"endpoints": etcdv3Endpoints, "endpoints": stringsToInterfaces(etcdv3Endpoints),
"prefix": prefix, "prefix": prefix,
"lock": false, "lock": false,
})) }))
b2 := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{ b2 := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{
"endpoints": etcdv3Endpoints, "endpoints": stringsToInterfaces(etcdv3Endpoints),
"prefix": prefix + "/" + "different", // Diff so locking test would fail if it was locking "prefix": prefix + "/" + "different", // Diff so locking test would fail if it was locking
"lock": false, "lock": false,
})) }))
@ -97,3 +97,11 @@ func TestBackend_lockDisabled(t *testing.T) {
// Test // Test
backend.TestBackendStateLocks(t, b1, b2) backend.TestBackendStateLocks(t, b1, b2)
} }
func stringsToInterfaces(strSlice []string) []interface{} {
var interfaceSlice []interface{}
for _, v := range strSlice {
interfaceSlice = append(interfaceSlice, v)
}
return interfaceSlice
}

View File

@ -23,7 +23,7 @@ func TestRemoteClient(t *testing.T) {
// Get the backend // Get the backend
b := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{ b := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{
"endpoints": etcdv3Endpoints, "endpoints": stringsToInterfaces(etcdv3Endpoints),
"prefix": prefix, "prefix": prefix,
})) }))
@ -45,7 +45,7 @@ func TestEtcdv3_stateLock(t *testing.T) {
// Get the backend // Get the backend
s1, err := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{ s1, err := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{
"endpoints": etcdv3Endpoints, "endpoints": stringsToInterfaces(etcdv3Endpoints),
"prefix": prefix, "prefix": prefix,
})).StateMgr(backend.DefaultStateName) })).StateMgr(backend.DefaultStateName)
if err != nil { if err != nil {
@ -53,7 +53,7 @@ func TestEtcdv3_stateLock(t *testing.T) {
} }
s2, err := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{ s2, err := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{
"endpoints": etcdv3Endpoints, "endpoints": stringsToInterfaces(etcdv3Endpoints),
"prefix": prefix, "prefix": prefix,
})).StateMgr(backend.DefaultStateName) })).StateMgr(backend.DefaultStateName)
if err != nil { if err != nil {
@ -71,7 +71,7 @@ func TestEtcdv3_destroyLock(t *testing.T) {
// Get the backend // Get the backend
b := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{ b := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{
"endpoints": etcdv3Endpoints, "endpoints": stringsToInterfaces(etcdv3Endpoints),
"prefix": prefix, "prefix": prefix,
})) }))