change mock return values to pointers
This allows up to detect an unset value from the zero value so that defaults can be implemented, while still allowing tests to return specific values of their choosing.
This commit is contained in:
parent
ae52190c01
commit
5fe848b642
|
@ -1418,7 +1418,7 @@ func TestContext2Apply_dataBasic(t *testing.T) {
|
|||
p := testProvider("null")
|
||||
p.ApplyResourceChangeFn = testApplyFn
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
p.ReadDataSourceResponse = providers.ReadDataSourceResponse{
|
||||
p.ReadDataSourceResponse = &providers.ReadDataSourceResponse{
|
||||
State: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("yo"),
|
||||
"foo": cty.NullVal(cty.String),
|
||||
|
@ -10402,13 +10402,12 @@ func TestContext2Apply_ProviderMeta_refresh_set(t *testing.T) {
|
|||
},
|
||||
}
|
||||
rrcPMs := map[string]cty.Value{}
|
||||
p.ReadResourceFn = func(req providers.ReadResourceRequest) providers.ReadResourceResponse {
|
||||
p.ReadResourceFn = func(req providers.ReadResourceRequest) (resp providers.ReadResourceResponse) {
|
||||
rrcPMs[req.TypeName] = req.ProviderMeta
|
||||
newState, err := p.GetSchemaReturn.ResourceTypes[req.TypeName].CoerceValue(p.ReadResourceResponse.NewState)
|
||||
newState, err := p.GetSchemaReturn.ResourceTypes[req.TypeName].CoerceValue(req.PriorState)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
resp := p.ReadResourceResponse
|
||||
resp.NewState = newState
|
||||
return resp
|
||||
}
|
||||
|
@ -10792,7 +10791,7 @@ func TestContext2Apply_ProviderMeta_refreshdata_setNoSchema(t *testing.T) {
|
|||
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
p.ReadDataSourceResponse = providers.ReadDataSourceResponse{
|
||||
p.ReadDataSourceResponse = &providers.ReadDataSourceResponse{
|
||||
State: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("yo"),
|
||||
"foo": cty.StringVal("bar"),
|
||||
|
@ -10848,7 +10847,7 @@ func TestContext2Apply_ProviderMeta_refreshdata_setInvalid(t *testing.T) {
|
|||
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
p.ReadDataSourceResponse = providers.ReadDataSourceResponse{
|
||||
p.ReadDataSourceResponse = &providers.ReadDataSourceResponse{
|
||||
State: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("yo"),
|
||||
"foo": cty.StringVal("bar"),
|
||||
|
@ -11497,7 +11496,7 @@ output "output" {
|
|||
nullP.ApplyResourceChangeFn = testApplyFn
|
||||
nullP.PlanResourceChangeFn = testDiffFn
|
||||
|
||||
nullP.ReadDataSourceResponse = providers.ReadDataSourceResponse{
|
||||
nullP.ReadDataSourceResponse = &providers.ReadDataSourceResponse{
|
||||
State: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("ID"),
|
||||
"output": cty.StringVal("valid"),
|
||||
|
|
|
@ -22,7 +22,7 @@ func TestContextImport_basic(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -63,7 +63,7 @@ func TestContextImport_countIndex(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -125,7 +125,7 @@ func TestContextImport_collision(t *testing.T) {
|
|||
}),
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -164,7 +164,7 @@ func TestContextImport_missingType(t *testing.T) {
|
|||
p := testProvider("aws")
|
||||
m := testModule(t, "import-provider")
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
State: cty.ObjectVal(map[string]cty.Value{
|
||||
|
@ -205,7 +205,7 @@ func TestContextImport_missingType(t *testing.T) {
|
|||
func TestContextImport_moduleProvider(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -269,7 +269,7 @@ func TestContextImport_providerModule(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -341,7 +341,7 @@ func TestContextImport_providerConfig(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -396,7 +396,7 @@ func TestContextImport_providerConfigResources(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -435,7 +435,7 @@ func TestContextImport_refresh(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -448,7 +448,7 @@ func TestContextImport_refresh(t *testing.T) {
|
|||
|
||||
p.ReadResourceFn = nil
|
||||
|
||||
p.ReadResourceResponse = providers.ReadResourceResponse{
|
||||
p.ReadResourceResponse = &providers.ReadResourceResponse{
|
||||
NewState: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("foo"),
|
||||
"foo": cty.StringVal("bar"),
|
||||
|
@ -486,7 +486,7 @@ func TestContextImport_refreshNil(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -534,7 +534,7 @@ func TestContextImport_module(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -576,7 +576,7 @@ func TestContextImport_moduleDepth2(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -618,7 +618,7 @@ func TestContextImport_moduleDiff(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -674,7 +674,7 @@ func TestContextImport_multiState(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -743,7 +743,7 @@ func TestContextImport_multiStateSame(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -844,7 +844,7 @@ resource "test_resource" "unused" {
|
|||
},
|
||||
}
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "test_resource",
|
||||
|
@ -854,7 +854,7 @@ resource "test_resource" "unused" {
|
|||
},
|
||||
},
|
||||
}
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "test_resource",
|
||||
|
|
|
@ -1873,7 +1873,7 @@ func TestContext2Plan_computedInFunction(t *testing.T) {
|
|||
},
|
||||
}
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
p.ReadDataSourceResponse = providers.ReadDataSourceResponse{
|
||||
p.ReadDataSourceResponse = &providers.ReadDataSourceResponse{
|
||||
State: cty.ObjectVal(map[string]cty.Value{
|
||||
"computed": cty.ListVal([]cty.Value{
|
||||
cty.StringVal("foo"),
|
||||
|
@ -2015,7 +2015,7 @@ func TestContext2Plan_dataResourceBecomesComputed(t *testing.T) {
|
|||
schema := p.GetSchemaReturn.DataSources["aws_data_source"]
|
||||
ty := schema.ImpliedType()
|
||||
|
||||
p.ReadDataSourceResponse = providers.ReadDataSourceResponse{
|
||||
p.ReadDataSourceResponse = &providers.ReadDataSourceResponse{
|
||||
// This should not be called, because the configuration for the
|
||||
// data resource contains an unknown value for "foo".
|
||||
Diagnostics: tfdiags.Diagnostics(nil).Append(fmt.Errorf("ReadDataSource called, but should not have been")),
|
||||
|
@ -5412,7 +5412,7 @@ output "out" {
|
|||
})
|
||||
|
||||
p := testProvider("aws")
|
||||
p.ReadDataSourceResponse = providers.ReadDataSourceResponse{
|
||||
p.ReadDataSourceResponse = &providers.ReadDataSourceResponse{
|
||||
State: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("data_id"),
|
||||
"foo": cty.StringVal("foo"),
|
||||
|
@ -5459,7 +5459,7 @@ resource "aws_instance" "foo" {
|
|||
})
|
||||
|
||||
p := testProvider("aws")
|
||||
p.ReadDataSourceResponse = providers.ReadDataSourceResponse{
|
||||
p.ReadDataSourceResponse = &providers.ReadDataSourceResponse{
|
||||
State: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("data_id"),
|
||||
"foo": cty.StringVal("foo"),
|
||||
|
@ -6114,7 +6114,7 @@ data "test_data_source" "foo" {}
|
|||
},
|
||||
}
|
||||
|
||||
p.ReadDataSourceResponse = providers.ReadDataSourceResponse{
|
||||
p.ReadDataSourceResponse = &providers.ReadDataSourceResponse{
|
||||
State: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("data_id"),
|
||||
"foo": cty.StringVal("foo"),
|
||||
|
@ -6261,7 +6261,7 @@ data "test_data_source" "d" {
|
|||
`})
|
||||
|
||||
p := testProvider("test")
|
||||
p.ReadDataSourceResponse = providers.ReadDataSourceResponse{
|
||||
p.ReadDataSourceResponse = &providers.ReadDataSourceResponse{
|
||||
State: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("this"),
|
||||
"foo": cty.NullVal(cty.String),
|
||||
|
|
|
@ -49,7 +49,7 @@ func TestContext2Refresh(t *testing.T) {
|
|||
}
|
||||
|
||||
p.ReadResourceFn = nil
|
||||
p.ReadResourceResponse = providers.ReadResourceResponse{
|
||||
p.ReadResourceResponse = &providers.ReadResourceResponse{
|
||||
NewState: readState,
|
||||
}
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
|
@ -514,7 +514,7 @@ func TestContext2Refresh_delete(t *testing.T) {
|
|||
})
|
||||
|
||||
p.ReadResourceFn = nil
|
||||
p.ReadResourceResponse = providers.ReadResourceResponse{
|
||||
p.ReadResourceResponse = &providers.ReadResourceResponse{
|
||||
NewState: cty.NullVal(p.GetSchemaReturn.ResourceTypes["aws_instance"].ImpliedType()),
|
||||
}
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
|
@ -542,7 +542,7 @@ func TestContext2Refresh_ignoreUncreated(t *testing.T) {
|
|||
})
|
||||
|
||||
p.ReadResourceFn = nil
|
||||
p.ReadResourceResponse = providers.ReadResourceResponse{
|
||||
p.ReadResourceResponse = &providers.ReadResourceResponse{
|
||||
NewState: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("foo"),
|
||||
}),
|
||||
|
@ -700,7 +700,7 @@ func TestContext2Refresh_noState(t *testing.T) {
|
|||
})
|
||||
|
||||
p.ReadResourceFn = nil
|
||||
p.ReadResourceResponse = providers.ReadResourceResponse{
|
||||
p.ReadResourceResponse = &providers.ReadResourceResponse{
|
||||
NewState: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("foo"),
|
||||
}),
|
||||
|
@ -785,7 +785,7 @@ func TestContext2Refresh_outputPartial(t *testing.T) {
|
|||
}
|
||||
|
||||
p.ReadResourceFn = nil
|
||||
p.ReadResourceResponse = providers.ReadResourceResponse{
|
||||
p.ReadResourceResponse = &providers.ReadResourceResponse{
|
||||
NewState: cty.NullVal(p.GetSchemaReturn.ResourceTypes["aws_instance"].ImpliedType()),
|
||||
}
|
||||
|
||||
|
@ -841,7 +841,7 @@ func TestContext2Refresh_stateBasic(t *testing.T) {
|
|||
|
||||
p.ReadResourceFn = nil
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
p.ReadResourceResponse = providers.ReadResourceResponse{
|
||||
p.ReadResourceResponse = &providers.ReadResourceResponse{
|
||||
NewState: readStateVal,
|
||||
}
|
||||
|
||||
|
@ -1142,7 +1142,7 @@ func TestContext2Refresh_vars(t *testing.T) {
|
|||
|
||||
p.ReadResourceFn = nil
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
p.ReadResourceResponse = providers.ReadResourceResponse{
|
||||
p.ReadResourceResponse = &providers.ReadResourceResponse{
|
||||
NewState: readStateVal,
|
||||
}
|
||||
|
||||
|
@ -1333,7 +1333,7 @@ func TestContext2Refresh_schemaUpgradeFlatmap(t *testing.T) {
|
|||
"test_thing": 5,
|
||||
},
|
||||
}
|
||||
p.UpgradeResourceStateResponse = providers.UpgradeResourceStateResponse{
|
||||
p.UpgradeResourceStateResponse = &providers.UpgradeResourceStateResponse{
|
||||
UpgradedState: cty.ObjectVal(map[string]cty.Value{
|
||||
"name": cty.StringVal("foo"),
|
||||
}),
|
||||
|
@ -1420,7 +1420,7 @@ func TestContext2Refresh_schemaUpgradeJSON(t *testing.T) {
|
|||
"test_thing": 5,
|
||||
},
|
||||
}
|
||||
p.UpgradeResourceStateResponse = providers.UpgradeResourceStateResponse{
|
||||
p.UpgradeResourceStateResponse = &providers.UpgradeResourceStateResponse{
|
||||
UpgradedState: cty.ObjectVal(map[string]cty.Value{
|
||||
"name": cty.StringVal("foo"),
|
||||
}),
|
||||
|
@ -1545,7 +1545,7 @@ func TestContext2Refresh_dataResourceDependsOn(t *testing.T) {
|
|||
},
|
||||
}
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
p.ReadDataSourceResponse = providers.ReadDataSourceResponse{
|
||||
p.ReadDataSourceResponse = &providers.ReadDataSourceResponse{
|
||||
State: cty.ObjectVal(map[string]cty.Value{
|
||||
"compute": cty.StringVal("value"),
|
||||
}),
|
||||
|
|
|
@ -398,7 +398,7 @@ func TestContext2Validate_moduleBadResource(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.ValidateResourceTypeConfigResponse = providers.ValidateResourceTypeConfigResponse{
|
||||
p.ValidateResourceTypeConfigResponse = &providers.ValidateResourceTypeConfigResponse{
|
||||
Diagnostics: tfdiags.Diagnostics{}.Append(fmt.Errorf("bad")),
|
||||
}
|
||||
|
||||
|
@ -582,7 +582,7 @@ func TestContext2Validate_providerConfig_bad(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.PrepareProviderConfigResponse = providers.PrepareProviderConfigResponse{
|
||||
p.PrepareProviderConfigResponse = &providers.PrepareProviderConfigResponse{
|
||||
Diagnostics: tfdiags.Diagnostics{}.Append(fmt.Errorf("bad")),
|
||||
}
|
||||
|
||||
|
@ -618,7 +618,7 @@ func TestContext2Validate_providerConfig_skippedEmpty(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.PrepareProviderConfigResponse = providers.PrepareProviderConfigResponse{
|
||||
p.PrepareProviderConfigResponse = &providers.PrepareProviderConfigResponse{
|
||||
Diagnostics: tfdiags.Diagnostics{}.Append(fmt.Errorf("should not be called")),
|
||||
}
|
||||
|
||||
|
@ -714,7 +714,7 @@ func TestContext2Validate_provisionerConfig_bad(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.PrepareProviderConfigResponse = providers.PrepareProviderConfigResponse{
|
||||
p.PrepareProviderConfigResponse = &providers.PrepareProviderConfigResponse{
|
||||
Diagnostics: tfdiags.Diagnostics{}.Append(fmt.Errorf("bad")),
|
||||
}
|
||||
|
||||
|
@ -878,7 +878,7 @@ func TestContext2Validate_resourceConfig_bad(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.ValidateResourceTypeConfigResponse = providers.ValidateResourceTypeConfigResponse{
|
||||
p.ValidateResourceTypeConfigResponse = &providers.ValidateResourceTypeConfigResponse{
|
||||
Diagnostics: tfdiags.Diagnostics{}.Append(fmt.Errorf("bad")),
|
||||
}
|
||||
|
||||
|
@ -1877,7 +1877,7 @@ resource "test_instance" "a" {
|
|||
},
|
||||
}
|
||||
|
||||
p.ValidateResourceTypeConfigResponse = providers.ValidateResourceTypeConfigResponse{
|
||||
p.ValidateResourceTypeConfigResponse = &providers.ValidateResourceTypeConfigResponse{
|
||||
Diagnostics: tfdiags.Diagnostics(nil).Append(tfdiags.SimpleWarning("don't frobble")),
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ func TestNodePlanDeposedResourceInstanceObject_Execute(t *testing.T) {
|
|||
)
|
||||
|
||||
p := testProvider("test")
|
||||
p.UpgradeResourceStateResponse = providers.UpgradeResourceStateResponse{
|
||||
p.UpgradeResourceStateResponse = &providers.UpgradeResourceStateResponse{
|
||||
UpgradedState: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("bar"),
|
||||
}),
|
||||
|
@ -86,7 +86,7 @@ func TestNodeDestroyDeposedResourceInstanceObject_Execute(t *testing.T) {
|
|||
)
|
||||
|
||||
p := testProvider("test")
|
||||
p.UpgradeResourceStateResponse = providers.UpgradeResourceStateResponse{
|
||||
p.UpgradeResourceStateResponse = &providers.UpgradeResourceStateResponse{
|
||||
UpgradedState: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("bar"),
|
||||
}),
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"errors"
|
||||
"sync"
|
||||
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
ctyjson "github.com/zclconf/go-cty/cty/json"
|
||||
"github.com/zclconf/go-cty/cty/msgpack"
|
||||
|
||||
|
@ -26,30 +25,30 @@ type MockProvider struct {
|
|||
GetSchemaReturn *ProviderSchema // This is using ProviderSchema directly rather than providers.GetSchemaResponse for compatibility with old tests
|
||||
|
||||
PrepareProviderConfigCalled bool
|
||||
PrepareProviderConfigResponse providers.PrepareProviderConfigResponse
|
||||
PrepareProviderConfigResponse *providers.PrepareProviderConfigResponse
|
||||
PrepareProviderConfigRequest providers.PrepareProviderConfigRequest
|
||||
PrepareProviderConfigFn func(providers.PrepareProviderConfigRequest) providers.PrepareProviderConfigResponse
|
||||
|
||||
ValidateResourceTypeConfigCalled bool
|
||||
ValidateResourceTypeConfigTypeName string
|
||||
ValidateResourceTypeConfigResponse providers.ValidateResourceTypeConfigResponse
|
||||
ValidateResourceTypeConfigResponse *providers.ValidateResourceTypeConfigResponse
|
||||
ValidateResourceTypeConfigRequest providers.ValidateResourceTypeConfigRequest
|
||||
ValidateResourceTypeConfigFn func(providers.ValidateResourceTypeConfigRequest) providers.ValidateResourceTypeConfigResponse
|
||||
|
||||
ValidateDataSourceConfigCalled bool
|
||||
ValidateDataSourceConfigTypeName string
|
||||
ValidateDataSourceConfigResponse providers.ValidateDataSourceConfigResponse
|
||||
ValidateDataSourceConfigResponse *providers.ValidateDataSourceConfigResponse
|
||||
ValidateDataSourceConfigRequest providers.ValidateDataSourceConfigRequest
|
||||
ValidateDataSourceConfigFn func(providers.ValidateDataSourceConfigRequest) providers.ValidateDataSourceConfigResponse
|
||||
|
||||
UpgradeResourceStateCalled bool
|
||||
UpgradeResourceStateTypeName string
|
||||
UpgradeResourceStateResponse providers.UpgradeResourceStateResponse
|
||||
UpgradeResourceStateResponse *providers.UpgradeResourceStateResponse
|
||||
UpgradeResourceStateRequest providers.UpgradeResourceStateRequest
|
||||
UpgradeResourceStateFn func(providers.UpgradeResourceStateRequest) providers.UpgradeResourceStateResponse
|
||||
|
||||
ConfigureCalled bool
|
||||
ConfigureResponse providers.ConfigureResponse
|
||||
ConfigureResponse *providers.ConfigureResponse
|
||||
ConfigureRequest providers.ConfigureRequest
|
||||
ConfigureFn func(providers.ConfigureRequest) providers.ConfigureResponse
|
||||
|
||||
|
@ -58,27 +57,27 @@ type MockProvider struct {
|
|||
StopResponse error
|
||||
|
||||
ReadResourceCalled bool
|
||||
ReadResourceResponse providers.ReadResourceResponse
|
||||
ReadResourceResponse *providers.ReadResourceResponse
|
||||
ReadResourceRequest providers.ReadResourceRequest
|
||||
ReadResourceFn func(providers.ReadResourceRequest) providers.ReadResourceResponse
|
||||
|
||||
PlanResourceChangeCalled bool
|
||||
PlanResourceChangeResponse providers.PlanResourceChangeResponse
|
||||
PlanResourceChangeResponse *providers.PlanResourceChangeResponse
|
||||
PlanResourceChangeRequest providers.PlanResourceChangeRequest
|
||||
PlanResourceChangeFn func(providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse
|
||||
|
||||
ApplyResourceChangeCalled bool
|
||||
ApplyResourceChangeResponse providers.ApplyResourceChangeResponse
|
||||
ApplyResourceChangeResponse *providers.ApplyResourceChangeResponse
|
||||
ApplyResourceChangeRequest providers.ApplyResourceChangeRequest
|
||||
ApplyResourceChangeFn func(providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse
|
||||
|
||||
ImportResourceStateCalled bool
|
||||
ImportResourceStateResponse providers.ImportResourceStateResponse
|
||||
ImportResourceStateResponse *providers.ImportResourceStateResponse
|
||||
ImportResourceStateRequest providers.ImportResourceStateRequest
|
||||
ImportResourceStateFn func(providers.ImportResourceStateRequest) providers.ImportResourceStateResponse
|
||||
|
||||
ReadDataSourceCalled bool
|
||||
ReadDataSourceResponse providers.ReadDataSourceResponse
|
||||
ReadDataSourceResponse *providers.ReadDataSourceResponse
|
||||
ReadDataSourceRequest providers.ReadDataSourceRequest
|
||||
ReadDataSourceFn func(providers.ReadDataSourceRequest) providers.ReadDataSourceResponse
|
||||
|
||||
|
@ -140,7 +139,7 @@ func (p *MockProvider) getDatasourceSchema(name string) providers.Schema {
|
|||
return dataSchema
|
||||
}
|
||||
|
||||
func (p *MockProvider) PrepareProviderConfig(r providers.PrepareProviderConfigRequest) providers.PrepareProviderConfigResponse {
|
||||
func (p *MockProvider) PrepareProviderConfig(r providers.PrepareProviderConfigRequest) (resp providers.PrepareProviderConfigResponse) {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
|
||||
|
@ -149,8 +148,13 @@ func (p *MockProvider) PrepareProviderConfig(r providers.PrepareProviderConfigRe
|
|||
if p.PrepareProviderConfigFn != nil {
|
||||
return p.PrepareProviderConfigFn(r)
|
||||
}
|
||||
p.PrepareProviderConfigResponse.PreparedConfig = r.Config
|
||||
return p.PrepareProviderConfigResponse
|
||||
|
||||
if p.PrepareProviderConfigResponse != nil {
|
||||
return *p.PrepareProviderConfigResponse
|
||||
}
|
||||
|
||||
resp.PreparedConfig = r.Config
|
||||
return resp
|
||||
}
|
||||
|
||||
func (p *MockProvider) ValidateResourceTypeConfig(r providers.ValidateResourceTypeConfigRequest) (resp providers.ValidateResourceTypeConfigResponse) {
|
||||
|
@ -173,7 +177,11 @@ func (p *MockProvider) ValidateResourceTypeConfig(r providers.ValidateResourceTy
|
|||
return p.ValidateResourceTypeConfigFn(r)
|
||||
}
|
||||
|
||||
return p.ValidateResourceTypeConfigResponse
|
||||
if p.ValidateResourceTypeConfigResponse != nil {
|
||||
return *p.ValidateResourceTypeConfigResponse
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
func (p *MockProvider) ValidateDataSourceConfig(r providers.ValidateDataSourceConfigRequest) (resp providers.ValidateDataSourceConfigResponse) {
|
||||
|
@ -195,10 +203,14 @@ func (p *MockProvider) ValidateDataSourceConfig(r providers.ValidateDataSourceCo
|
|||
return p.ValidateDataSourceConfigFn(r)
|
||||
}
|
||||
|
||||
return p.ValidateDataSourceConfigResponse
|
||||
if p.ValidateDataSourceConfigResponse != nil {
|
||||
return *p.ValidateDataSourceConfigResponse
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
func (p *MockProvider) UpgradeResourceState(r providers.UpgradeResourceStateRequest) providers.UpgradeResourceStateResponse {
|
||||
func (p *MockProvider) UpgradeResourceState(r providers.UpgradeResourceStateRequest) (resp providers.UpgradeResourceStateResponse) {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
|
||||
|
@ -213,31 +225,32 @@ func (p *MockProvider) UpgradeResourceState(r providers.UpgradeResourceStateRequ
|
|||
return p.UpgradeResourceStateFn(r)
|
||||
}
|
||||
|
||||
resp := p.UpgradeResourceStateResponse
|
||||
|
||||
if resp.UpgradedState == cty.NilVal {
|
||||
switch {
|
||||
case r.RawStateFlatmap != nil:
|
||||
v, err := hcl2shim.HCL2ValueFromFlatmap(r.RawStateFlatmap, schemaType)
|
||||
if err != nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
return resp
|
||||
}
|
||||
resp.UpgradedState = v
|
||||
case len(r.RawStateJSON) > 0:
|
||||
v, err := ctyjson.Unmarshal(r.RawStateJSON, schemaType)
|
||||
|
||||
if err != nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
return resp
|
||||
}
|
||||
resp.UpgradedState = v
|
||||
}
|
||||
if p.UpgradeResourceStateResponse != nil {
|
||||
return *p.UpgradeResourceStateResponse
|
||||
}
|
||||
|
||||
switch {
|
||||
case r.RawStateFlatmap != nil:
|
||||
v, err := hcl2shim.HCL2ValueFromFlatmap(r.RawStateFlatmap, schemaType)
|
||||
if err != nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
return resp
|
||||
}
|
||||
resp.UpgradedState = v
|
||||
case len(r.RawStateJSON) > 0:
|
||||
v, err := ctyjson.Unmarshal(r.RawStateJSON, schemaType)
|
||||
|
||||
if err != nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
return resp
|
||||
}
|
||||
resp.UpgradedState = v
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
func (p *MockProvider) Configure(r providers.ConfigureRequest) providers.ConfigureResponse {
|
||||
func (p *MockProvider) Configure(r providers.ConfigureRequest) (resp providers.ConfigureResponse) {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
|
||||
|
@ -248,7 +261,11 @@ func (p *MockProvider) Configure(r providers.ConfigureRequest) providers.Configu
|
|||
return p.ConfigureFn(r)
|
||||
}
|
||||
|
||||
return p.ConfigureResponse
|
||||
if p.ConfigureResponse != nil {
|
||||
return *p.ConfigureResponse
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
func (p *MockProvider) Stop() error {
|
||||
|
@ -265,7 +282,7 @@ func (p *MockProvider) Stop() error {
|
|||
return p.StopResponse
|
||||
}
|
||||
|
||||
func (p *MockProvider) ReadResource(r providers.ReadResourceRequest) providers.ReadResourceResponse {
|
||||
func (p *MockProvider) ReadResource(r providers.ReadResourceRequest) (resp providers.ReadResourceResponse) {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
|
||||
|
@ -276,24 +293,25 @@ func (p *MockProvider) ReadResource(r providers.ReadResourceRequest) providers.R
|
|||
return p.ReadResourceFn(r)
|
||||
}
|
||||
|
||||
resp := p.ReadResourceResponse
|
||||
if resp.NewState != cty.NilVal {
|
||||
// make sure the NewState fits the schema
|
||||
// This isn't always the case for the existing tests
|
||||
if p.ReadResourceResponse != nil {
|
||||
resp = *p.ReadResourceResponse
|
||||
|
||||
// Make sure the NewState conforms to the schema.
|
||||
// This isn't always the case for the existing tests.
|
||||
newState, err := p.GetSchemaReturn.ResourceTypes[r.TypeName].CoerceValue(resp.NewState)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
}
|
||||
resp.NewState = newState
|
||||
return resp
|
||||
}
|
||||
|
||||
// just return the same state we received
|
||||
// otherwise just return the same state we received
|
||||
resp.NewState = r.PriorState
|
||||
return resp
|
||||
}
|
||||
|
||||
func (p *MockProvider) PlanResourceChange(r providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse {
|
||||
func (p *MockProvider) PlanResourceChange(r providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
|
||||
|
@ -304,10 +322,14 @@ func (p *MockProvider) PlanResourceChange(r providers.PlanResourceChangeRequest)
|
|||
return p.PlanResourceChangeFn(r)
|
||||
}
|
||||
|
||||
return p.PlanResourceChangeResponse
|
||||
if p.PlanResourceChangeResponse != nil {
|
||||
return *p.PlanResourceChangeResponse
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
func (p *MockProvider) ApplyResourceChange(r providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse {
|
||||
func (p *MockProvider) ApplyResourceChange(r providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) {
|
||||
p.Lock()
|
||||
p.ApplyResourceChangeCalled = true
|
||||
p.ApplyResourceChangeRequest = r
|
||||
|
@ -317,7 +339,10 @@ func (p *MockProvider) ApplyResourceChange(r providers.ApplyResourceChangeReques
|
|||
return p.ApplyResourceChangeFn(r)
|
||||
}
|
||||
|
||||
return p.ApplyResourceChangeResponse
|
||||
if p.ApplyResourceChangeResponse != nil {
|
||||
return *p.ApplyResourceChangeResponse
|
||||
}
|
||||
return resp
|
||||
}
|
||||
|
||||
func (p *MockProvider) ImportResourceState(r providers.ImportResourceStateRequest) (resp providers.ImportResourceStateResponse) {
|
||||
|
@ -330,28 +355,31 @@ func (p *MockProvider) ImportResourceState(r providers.ImportResourceStateReques
|
|||
return p.ImportResourceStateFn(r)
|
||||
}
|
||||
|
||||
// fixup the cty value to match the schema
|
||||
for i, res := range p.ImportResourceStateResponse.ImportedResources {
|
||||
schema := p.GetSchemaReturn.ResourceTypes[res.TypeName]
|
||||
if schema == nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(errors.New("no schema found for " + res.TypeName))
|
||||
return resp
|
||||
}
|
||||
if p.ImportResourceStateResponse != nil {
|
||||
resp = *p.ImportResourceStateResponse
|
||||
// fixup the cty value to match the schema
|
||||
for i, res := range resp.ImportedResources {
|
||||
schema := p.GetSchemaReturn.ResourceTypes[res.TypeName]
|
||||
if schema == nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(errors.New("no schema found for " + res.TypeName))
|
||||
return resp
|
||||
}
|
||||
|
||||
var err error
|
||||
res.State, err = schema.CoerceValue(res.State)
|
||||
if err != nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
return resp
|
||||
}
|
||||
var err error
|
||||
res.State, err = schema.CoerceValue(res.State)
|
||||
if err != nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
return resp
|
||||
}
|
||||
|
||||
p.ImportResourceStateResponse.ImportedResources[i] = res
|
||||
resp.ImportedResources[i] = res
|
||||
}
|
||||
}
|
||||
|
||||
return p.ImportResourceStateResponse
|
||||
return resp
|
||||
}
|
||||
|
||||
func (p *MockProvider) ReadDataSource(r providers.ReadDataSourceRequest) providers.ReadDataSourceResponse {
|
||||
func (p *MockProvider) ReadDataSource(r providers.ReadDataSourceRequest) (resp providers.ReadDataSourceResponse) {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
|
||||
|
@ -362,7 +390,10 @@ func (p *MockProvider) ReadDataSource(r providers.ReadDataSourceRequest) provide
|
|||
return p.ReadDataSourceFn(r)
|
||||
}
|
||||
|
||||
return p.ReadDataSourceResponse
|
||||
if p.ReadDataSourceResponse != nil {
|
||||
resp = *p.ReadDataSourceResponse
|
||||
}
|
||||
return resp
|
||||
}
|
||||
|
||||
func (p *MockProvider) Close() error {
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
func TestGraphNodeImportStateExecute(t *testing.T) {
|
||||
state := states.NewState()
|
||||
provider := testProvider("aws")
|
||||
provider.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
provider.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
|
Loading…
Reference in New Issue