update tests

Some tests could not handle reading orphaned resources. It also turns
out the ReadResource mock never returned the correct state in the
default case at all.
This commit is contained in:
James Bardin 2020-10-22 09:32:47 -04:00
parent ddb2bbf4e9
commit 72e81de0fc
3 changed files with 13 additions and 7 deletions

View File

@ -267,7 +267,6 @@ func TestContext2Apply_resourceDependsOnModule(t *testing.T) {
}
if !reflect.DeepEqual(order, []string{"child", "parent"}) {
fmt.Println("ORDER:", order)
t.Fatal("resources applied out of order")
}

View File

@ -33,6 +33,7 @@ func TestNodeResourcePlanOrphanExecute(t *testing.T) {
p := simpleMockProvider()
ctx := &MockEvalContext{
StateState: state.SyncWrapper(),
RefreshStateState: state.SyncWrapper(),
InstanceExpanderExpander: instances.NewExpander(),
ProviderProvider: p,
ProviderSchemaSchema: &ProviderSchema{

View File

@ -242,14 +242,20 @@ func (p *MockProvider) ReadResource(r providers.ReadResourceRequest) providers.R
return p.ReadResourceFn(r)
}
resp := p.ReadResourceResponse
if resp.NewState != cty.NilVal {
// make sure the NewState fits the schema
newState, err := p.GetSchemaReturn.ResourceTypes[r.TypeName].CoerceValue(p.ReadResourceResponse.NewState)
// This isn't always the case for the existing tests
newState, err := p.GetSchemaReturn.ResourceTypes[r.TypeName].CoerceValue(resp.NewState)
if err != nil {
panic(err)
}
resp := p.ReadResourceResponse
resp.NewState = newState
return resp
}
// just return the same state we received
resp.NewState = r.PriorState
return resp
}