mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-17 12:12:59 -06:00
add backend refresh test with provider config
This commit is contained in:
parent
7e11b97923
commit
2549e53aed
@ -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) {
|
||||
|
7
backend/local/testdata/refresh-provider-config/main.tf
vendored
Normal file
7
backend/local/testdata/refresh-provider-config/main.tf
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
resource "test_instance" "foo" {
|
||||
ami = "bar"
|
||||
}
|
||||
|
||||
provider "test" {
|
||||
value = "foo"
|
||||
}
|
Loading…
Reference in New Issue
Block a user