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:
parent
ddb2bbf4e9
commit
72e81de0fc
|
@ -267,7 +267,6 @@ func TestContext2Apply_resourceDependsOnModule(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(order, []string{"child", "parent"}) {
|
if !reflect.DeepEqual(order, []string{"child", "parent"}) {
|
||||||
fmt.Println("ORDER:", order)
|
|
||||||
t.Fatal("resources applied out of order")
|
t.Fatal("resources applied out of order")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ func TestNodeResourcePlanOrphanExecute(t *testing.T) {
|
||||||
p := simpleMockProvider()
|
p := simpleMockProvider()
|
||||||
ctx := &MockEvalContext{
|
ctx := &MockEvalContext{
|
||||||
StateState: state.SyncWrapper(),
|
StateState: state.SyncWrapper(),
|
||||||
|
RefreshStateState: state.SyncWrapper(),
|
||||||
InstanceExpanderExpander: instances.NewExpander(),
|
InstanceExpanderExpander: instances.NewExpander(),
|
||||||
ProviderProvider: p,
|
ProviderProvider: p,
|
||||||
ProviderSchemaSchema: &ProviderSchema{
|
ProviderSchemaSchema: &ProviderSchema{
|
||||||
|
|
|
@ -242,14 +242,20 @@ func (p *MockProvider) ReadResource(r providers.ReadResourceRequest) providers.R
|
||||||
return p.ReadResourceFn(r)
|
return p.ReadResourceFn(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resp := p.ReadResourceResponse
|
||||||
|
if resp.NewState != cty.NilVal {
|
||||||
// make sure the NewState fits the schema
|
// 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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
resp := p.ReadResourceResponse
|
|
||||||
resp.NewState = newState
|
resp.NewState = newState
|
||||||
|
return resp
|
||||||
|
}
|
||||||
|
|
||||||
|
// just return the same state we received
|
||||||
|
resp.NewState = r.PriorState
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue