backend/local refresh tests refactor
This commit is contained in:
parent
e84def1e29
commit
64f696d9b3
|
@ -5,6 +5,8 @@ import (
|
|||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/providers"
|
||||
|
||||
"github.com/hashicorp/terraform/backend"
|
||||
"github.com/hashicorp/terraform/configs/configload"
|
||||
"github.com/hashicorp/terraform/configs/configschema"
|
||||
|
@ -19,8 +21,10 @@ func TestLocal_refresh(t *testing.T) {
|
|||
p := TestLocalProvider(t, b, "test", refreshFixtureSchema())
|
||||
terraform.TestStateFile(t, b.StatePath, testRefreshState())
|
||||
|
||||
// p.RefreshFn = nil
|
||||
// p.RefreshReturn = &terraform.InstanceState{ID: "yes"}
|
||||
p.ReadResourceFn = nil
|
||||
p.ReadResourceResponse = providers.ReadResourceResponse{NewState: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("yes"),
|
||||
})}
|
||||
|
||||
op, configCleanup := testOperationRefresh(t, "./test-fixtures/refresh")
|
||||
defer configCleanup()
|
||||
|
@ -45,11 +49,12 @@ test_instance.foo:
|
|||
func TestLocal_refreshNoConfig(t *testing.T) {
|
||||
b, cleanup := TestLocal(t)
|
||||
defer cleanup()
|
||||
p := TestLocalProvider(t, b, "test", &terraform.ProviderSchema{})
|
||||
p := TestLocalProvider(t, b, "test", refreshFixtureSchema())
|
||||
terraform.TestStateFile(t, b.StatePath, testRefreshState())
|
||||
|
||||
// p.RefreshFn = nil
|
||||
// p.RefreshReturn = &terraform.InstanceState{ID: "yes"}
|
||||
p.ReadResourceFn = nil
|
||||
p.ReadResourceResponse = providers.ReadResourceResponse{NewState: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("yes"),
|
||||
})}
|
||||
|
||||
op, configCleanup := testOperationRefresh(t, "./test-fixtures/empty")
|
||||
defer configCleanup()
|
||||
|
@ -75,11 +80,12 @@ test_instance.foo:
|
|||
func TestLocal_refreshNilModuleWithInput(t *testing.T) {
|
||||
b, cleanup := TestLocal(t)
|
||||
defer cleanup()
|
||||
p := TestLocalProvider(t, b, "test", &terraform.ProviderSchema{})
|
||||
p := TestLocalProvider(t, b, "test", refreshFixtureSchema())
|
||||
terraform.TestStateFile(t, b.StatePath, testRefreshState())
|
||||
|
||||
// p.RefreshFn = nil
|
||||
// p.RefreshReturn = &terraform.InstanceState{ID: "yes"}
|
||||
p.ReadResourceFn = nil
|
||||
p.ReadResourceResponse = providers.ReadResourceResponse{NewState: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("yes"),
|
||||
})}
|
||||
|
||||
b.OpInput = true
|
||||
|
||||
|
@ -106,7 +112,7 @@ test_instance.foo:
|
|||
func TestLocal_refreshInput(t *testing.T) {
|
||||
b, cleanup := TestLocal(t)
|
||||
defer cleanup()
|
||||
p := TestLocalProvider(t, b, "test", nil)
|
||||
p := TestLocalProvider(t, b, "test", refreshFixtureSchema())
|
||||
terraform.TestStateFile(t, b.StatePath, testRefreshState())
|
||||
|
||||
p.GetSchemaReturn = &terraform.ProviderSchema{
|
||||
|
@ -119,10 +125,15 @@ func TestLocal_refreshInput(t *testing.T) {
|
|||
"test_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
"id": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
p.ReadResourceFn = nil
|
||||
p.ReadResourceResponse = providers.ReadResourceResponse{NewState: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("yes"),
|
||||
})}
|
||||
p.ConfigureFn = func(c *terraform.ResourceConfig) error {
|
||||
if v, ok := c.Get("value"); !ok || v != "bar" {
|
||||
return fmt.Errorf("no value set")
|
||||
|
@ -131,9 +142,6 @@ func TestLocal_refreshInput(t *testing.T) {
|
|||
return nil
|
||||
}
|
||||
|
||||
// p.RefreshFn = nil
|
||||
// p.RefreshReturn = &terraform.InstanceState{ID: "yes"}
|
||||
|
||||
// Enable input asking since it is normally disabled by default
|
||||
b.OpInput = true
|
||||
b.ContextOpts.UIInput = &terraform.MockUIInput{InputReturnString: "bar"}
|
||||
|
@ -164,9 +172,10 @@ func TestLocal_refreshValidate(t *testing.T) {
|
|||
defer cleanup()
|
||||
p := TestLocalProvider(t, b, "test", refreshFixtureSchema())
|
||||
terraform.TestStateFile(t, b.StatePath, testRefreshState())
|
||||
|
||||
// p.RefreshFn = nil
|
||||
// p.RefreshReturn = &terraform.InstanceState{ID: "yes"}
|
||||
p.ReadResourceFn = nil
|
||||
p.ReadResourceResponse = providers.ReadResourceResponse{NewState: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("yes"),
|
||||
})}
|
||||
|
||||
// Enable validation
|
||||
b.OpValidation = true
|
||||
|
@ -234,6 +243,7 @@ func refreshFixtureSchema() *terraform.ProviderSchema {
|
|||
"test_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"ami": {Type: cty.String, Optional: true},
|
||||
"id": {Type: cty.String, Computed: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue