add backend refresh test with provider config

This commit is contained in:
Ben Drucker 2020-12-06 10:02:26 -08:00
parent 7e11b97923
commit 2549e53aed
2 changed files with 57 additions and 0 deletions

View File

@ -142,6 +142,56 @@ test_instance.foo:
`)
}
func TestLocal_refreshValidateProviderConfigured(t *testing.T) {
b, cleanup := TestLocal(t)
defer cleanup()
schema := &terraform.ProviderSchema{
Provider: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"value": {Type: cty.String, Optional: true},
},
},
ResourceTypes: map[string]*configschema.Block{
"test_instance": {
Attributes: map[string]*configschema.Attribute{
"id": {Type: cty.String, Computed: true},
"ami": {Type: cty.String, Optional: true},
},
},
},
}
p := TestLocalProvider(t, b, "test", schema)
testStateFile(t, b.StatePath, testRefreshState())
p.ReadResourceFn = nil
p.ReadResourceResponse = providers.ReadResourceResponse{NewState: cty.ObjectVal(map[string]cty.Value{
"id": cty.StringVal("yes"),
})}
// Enable validation
b.OpValidation = true
op, configCleanup := testOperationRefresh(t, "./testdata/refresh-provider-config")
defer configCleanup()
run, err := b.Operation(context.Background(), op)
if err != nil {
t.Fatalf("bad: %s", err)
}
<-run.Done()
if !p.PrepareProviderConfigCalled {
t.Fatal("Prepare provider config should be called")
}
checkState(t, b.StateOutPath, `
test_instance.foo:
ID = yes
provider = provider["registry.terraform.io/hashicorp/test"]
`)
}
// This test validates the state lacking behavior when the inner call to
// Context() fails
func TestLocal_refresh_context_error(t *testing.T) {

View File

@ -0,0 +1,7 @@
resource "test_instance" "foo" {
ami = "bar"
}
provider "test" {
value = "foo"
}