2 more tests that weren't correct

Found 2 more tests that still had dangling empty modules, which are now
fixed.
This commit is contained in:
James Bardin 2020-04-24 10:43:53 -04:00
parent f915c5d957
commit 98cf28b02d
3 changed files with 6 additions and 48 deletions

View File

@ -2637,7 +2637,7 @@ func TestContext2Apply_orphanResource(t *testing.T) {
Type: "test_thing",
Name: "one",
}.Absolute(addrs.RootModuleInstance)
s.SetResourceMeta(oneAddr, states.EachList, providerAddr)
s.SetResourceProvider(oneAddr, providerAddr)
s.SetResourceInstanceCurrent(oneAddr.Instance(addrs.IntKey(0)), &states.ResourceInstanceObjectSrc{
Status: states.ObjectReady,
AttrsJSON: []byte(`{}`),
@ -6111,9 +6111,7 @@ func TestContext2Apply_destroyWithModuleVariableAndCount(t *testing.T) {
//Test that things were destroyed
actual := strings.TrimSpace(state.String())
expected := strings.TrimSpace(`
<no state>
module.child:
<no state>`)
<no state>`)
if actual != expected {
t.Fatalf("expected: \n%s\n\nbad: \n%s", expected, actual)
}
@ -6269,9 +6267,7 @@ func TestContext2Apply_destroyWithModuleVariableAndCountNested(t *testing.T) {
//Test that things were destroyed
actual := strings.TrimSpace(state.String())
expected := strings.TrimSpace(`
<no state>
module.child.child2:
<no state>`)
<no state>`)
if actual != expected {
t.Fatalf("expected: \n%s\n\nbad: \n%s", expected, actual)
}

View File

@ -475,7 +475,7 @@ func (n *EvalWriteResourceState) Eval(ctx EvalContext) (interface{}, error) {
return nil, diags.Err()
}
state.SetResourceMeta(n.Addr, states.EachList, n.ProviderAddr)
state.SetResourceProvider(n.Addr, n.ProviderAddr)
expander.SetResourceCount(n.Addr.Module, n.Addr.Resource, count)
case n.Config.ForEach != nil:
@ -487,11 +487,11 @@ func (n *EvalWriteResourceState) Eval(ctx EvalContext) (interface{}, error) {
// This method takes care of all of the business logic of updating this
// while ensuring that any existing instances are preserved, etc.
state.SetResourceMeta(n.Addr, states.EachMap, n.ProviderAddr)
state.SetResourceProvider(n.Addr, n.ProviderAddr)
expander.SetResourceForEach(n.Addr.Module, n.Addr.Resource, forEach)
default:
state.SetResourceMeta(n.Addr, states.NoEach, n.ProviderAddr)
state.SetResourceProvider(n.Addr, n.ProviderAddr)
expander.SetResourceSingle(n.Addr.Module, n.Addr.Resource)
}

View File

@ -4,7 +4,6 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"
"sync"
"github.com/agext/levenshtein"
@ -803,43 +802,6 @@ func (d *evaluationStateData) getResourceSchema(addr addrs.Resource, providerAdd
return schema
}
// coerceInstanceKey attempts to convert the given key to the type expected
// for the given EachMode.
//
// If the key is already of the correct type or if it cannot be converted then
// it is returned verbatim. If conversion is required and possible, the
// converted value is returned. Callers should not try to determine if
// conversion was possible, should instead just check if the result is of
// the expected type.
func (d *evaluationStateData) coerceInstanceKey(key addrs.InstanceKey, mode states.EachMode) addrs.InstanceKey {
if key == addrs.NoKey {
// An absent key can't be converted
return key
}
switch mode {
case states.NoEach:
// No conversions possible at all
return key
case states.EachMap:
if intKey, isInt := key.(addrs.IntKey); isInt {
return addrs.StringKey(strconv.Itoa(int(intKey)))
}
return key
case states.EachList:
if strKey, isStr := key.(addrs.StringKey); isStr {
i, err := strconv.Atoi(string(strKey))
if err != nil {
return key
}
return addrs.IntKey(i)
}
return key
default:
return key
}
}
func (d *evaluationStateData) GetTerraformAttr(addr addrs.TerraformAttr, rng tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics) {
var diags tfdiags.Diagnostics
switch addr.Name {