have mockProvider always check it was configured

We do this already for other calls, but skipped UpgradeResourceState
since it wasn't previously possible to configure during a destroy plan.
pull/31176/head
James Bardin 4 years ago
parent 38d70a1c3d
commit 619fa61f0b

@ -121,6 +121,9 @@ func TestNodeAbstractResource_ReadResourceInstanceState(t *testing.T) {
},
},
})
// This test does not configure the provider, but the mock provider will
// check that this was called and report errors.
mockProvider.ConfigureProviderCalled = true
tests := map[string]struct {
State *states.State
@ -158,6 +161,7 @@ func TestNodeAbstractResource_ReadResourceInstanceState(t *testing.T) {
ctx.StateState = test.State.SyncWrapper()
ctx.PathPath = addrs.RootModuleInstance
ctx.ProviderSchemaSchema = mockProvider.ProviderSchema()
ctx.ProviderProvider = providers.Interface(mockProvider)
got, readDiags := test.Node.readResourceInstanceState(ctx, test.Node.Addr.Resource.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance))
@ -183,6 +187,9 @@ func TestNodeAbstractResource_ReadResourceInstanceStateDeposed(t *testing.T) {
},
},
})
// This test does not configure the provider, but the mock provider will
// check that this was called and report errors.
mockProvider.ConfigureProviderCalled = true
tests := map[string]struct {
State *states.State

@ -218,6 +218,11 @@ func (p *MockProvider) UpgradeResourceState(r providers.UpgradeResourceStateRequ
p.Lock()
defer p.Unlock()
if !p.ConfigureProviderCalled {
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("Configure not called before UpgradeResourceState %q", r.TypeName))
return resp
}
schema, ok := p.getProviderSchema().ResourceTypes[r.TypeName]
if !ok {
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("no schema found for %q", r.TypeName))

Loading…
Cancel
Save