remove unneeded testDiffFn and testApplyFn calls

Remove any calls to testDiffFn and testApplyFn which don't effect the
test result. This way we have more tests using predictable provider
behavior, which is more likely to uncover legitimate regressions as the
particular behavior of the legacy mock provider logic does not need to
be taken into account.
This commit is contained in:
James Bardin 2021-01-13 17:36:32 -05:00
parent 0a086030b1
commit e075c8ab8b
6 changed files with 65 additions and 242 deletions

File diff suppressed because it is too large Load Diff

View File

@ -17,8 +17,6 @@ import (
func TestContext2Input_provider(t *testing.T) {
m := testModule(t, "input-provider")
p := testProvider("aws")
p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
@ -89,8 +87,6 @@ func TestContext2Input_providerMulti(t *testing.T) {
m := testModule(t, "input-provider-multi")
p := testProvider("aws")
p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
@ -158,8 +154,6 @@ func TestContext2Input_providerMulti(t *testing.T) {
func TestContext2Input_providerOnce(t *testing.T) {
m := testModule(t, "input-provider-once")
p := testProvider("aws")
p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Config: m,
Providers: map[addrs.Provider]providers.Factory{
@ -178,8 +172,6 @@ func TestContext2Input_providerId(t *testing.T) {
m := testModule(t, "input-provider")
p := testProvider("aws")
p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
@ -241,10 +233,7 @@ func TestContext2Input_providerOnly(t *testing.T) {
input := new(MockUIInput)
m := testModule(t, "input-provider-vars")
p := testProvider("aws")
p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
@ -317,8 +306,6 @@ func TestContext2Input_providerVars(t *testing.T) {
input := new(MockUIInput)
m := testModule(t, "input-provider-with-vars")
p := testProvider("aws")
p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Config: m,
Providers: map[addrs.Provider]providers.Factory{
@ -363,8 +350,6 @@ func TestContext2Input_providerVarsModuleInherit(t *testing.T) {
input := new(MockUIInput)
m := testModule(t, "input-provider-with-vars-and-module")
p := testProvider("aws")
p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Config: m,
Providers: map[addrs.Provider]providers.Factory{
@ -383,8 +368,6 @@ func TestContext2Input_submoduleTriggersInvalidCount(t *testing.T) {
input := new(MockUIInput)
m := testModule(t, "input-submodule-count")
p := testProvider("aws")
p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Config: m,
Providers: map[addrs.Provider]providers.Factory{

View File

@ -3830,7 +3830,6 @@ func TestContext2Plan_taintIgnoreChanges(t *testing.T) {
},
},
})
p.ApplyResourceChangeFn = testApplyFn
state := states.NewState()
root := state.EnsureModule(addrs.RootModuleInstance)
@ -4701,7 +4700,6 @@ func TestContext2Plan_moduleMapLiteral(t *testing.T) {
},
},
})
p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) {
s := req.ProposedNewState.AsValueMap()
m := s["tags"].AsValueMap()
@ -4964,7 +4962,6 @@ func TestContext2Plan_createBeforeDestroy_depends_datasource(t *testing.T) {
func TestContext2Plan_listOrder(t *testing.T) {
m := testModule(t, "plan-list-order")
p := testProvider("aws")
p.ApplyResourceChangeFn = testApplyFn
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{
"aws_instance": {
@ -6101,7 +6098,6 @@ data "test_data_source" "foo" {}
// for_each can reference a resource with 0 instances
func TestContext2Plan_scaleInForEach(t *testing.T) {
p := testProvider("test")
p.ApplyResourceChangeFn = testApplyFn
m := testModuleInline(t, map[string]string{
"main.tf": `
@ -6237,7 +6233,6 @@ data "test_data_source" "d" {
func TestContext2Plan_dataReferencesResource(t *testing.T) {
p := testProvider("test")
p.ApplyResourceChangeFn = testApplyFn
p.ReadDataSourceFn = func(req providers.ReadDataSourceRequest) (resp providers.ReadDataSourceResponse) {
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("data source should not be read"))
@ -6285,7 +6280,6 @@ data "test_data_source" "e" {
func TestContext2Plan_skipRefresh(t *testing.T) {
p := testProvider("test")
p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn
m := testModuleInline(t, map[string]string{
@ -6331,7 +6325,6 @@ resource "test_instance" "a" {
func TestContext2Plan_dataInModuleDependsOn(t *testing.T) {
p := testProvider("test")
p.ApplyResourceChangeFn = testApplyFn
readDataSourceB := false
p.ReadDataSourceFn = func(req providers.ReadDataSourceRequest) (resp providers.ReadDataSourceResponse) {
@ -6625,7 +6618,6 @@ resource "test_resource" "foo" {
})
p := testProvider("test")
p.ApplyResourceChangeFn = testApplyFn
ctx := testContext2(t, &ContextOpts{
Config: m,

View File

@ -48,11 +48,9 @@ func TestContext2Refresh(t *testing.T) {
t.Fatal(err)
}
p.ReadResourceFn = nil
p.ReadResourceResponse = &providers.ReadResourceResponse{
NewState: readState,
}
p.PlanResourceChangeFn = testDiffFn
s, diags := ctx.Refresh()
if diags.HasErrors() {
@ -282,7 +280,6 @@ func TestContext2Refresh_targeted(t *testing.T) {
NewState: req.PriorState,
}
}
p.PlanResourceChangeFn = testDiffFn
_, diags := ctx.Refresh()
if diags.HasErrors() {
@ -361,7 +358,6 @@ func TestContext2Refresh_targetedCount(t *testing.T) {
NewState: req.PriorState,
}
}
p.PlanResourceChangeFn = testDiffFn
_, diags := ctx.Refresh()
if diags.HasErrors() {
@ -448,7 +444,6 @@ func TestContext2Refresh_targetedCountIndex(t *testing.T) {
NewState: req.PriorState,
}
}
p.PlanResourceChangeFn = testDiffFn
_, diags := ctx.Refresh()
if diags.HasErrors() {
@ -480,7 +475,6 @@ func TestContext2Refresh_moduleComputedVar(t *testing.T) {
},
},
})
p.PlanResourceChangeFn = testDiffFn
m := testModule(t, "refresh-module-computed-var")
ctx := testContext2(t, &ContextOpts{
@ -513,11 +507,9 @@ func TestContext2Refresh_delete(t *testing.T) {
State: state,
})
p.ReadResourceFn = nil
p.ReadResourceResponse = &providers.ReadResourceResponse{
NewState: cty.NullVal(p.GetSchemaResponse.ResourceTypes["aws_instance"].Block.ImpliedType()),
}
p.PlanResourceChangeFn = testDiffFn
s, diags := ctx.Refresh()
if diags.HasErrors() {
@ -541,13 +533,11 @@ func TestContext2Refresh_ignoreUncreated(t *testing.T) {
State: nil,
})
p.ReadResourceFn = nil
p.ReadResourceResponse = &providers.ReadResourceResponse{
NewState: cty.ObjectVal(map[string]cty.Value{
"id": cty.StringVal("foo"),
}),
}
p.PlanResourceChangeFn = testDiffFn
_, diags := ctx.Refresh()
if diags.HasErrors() {
@ -561,7 +551,6 @@ func TestContext2Refresh_ignoreUncreated(t *testing.T) {
func TestContext2Refresh_hook(t *testing.T) {
h := new(MockHook)
p := testProvider("aws")
p.PlanResourceChangeFn = testDiffFn
m := testModule(t, "refresh-basic")
state := states.NewState()
@ -623,7 +612,6 @@ func TestContext2Refresh_modules(t *testing.T) {
NewState: new,
}
}
p.PlanResourceChangeFn = testDiffFn
s, diags := ctx.Refresh()
if diags.HasErrors() {
@ -640,7 +628,6 @@ func TestContext2Refresh_modules(t *testing.T) {
func TestContext2Refresh_moduleInputComputedOutput(t *testing.T) {
m := testModule(t, "refresh-module-input-computed-output")
p := testProvider("aws")
p.PlanResourceChangeFn = testDiffFn
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{},
ResourceTypes: map[string]*configschema.Block{
@ -675,7 +662,6 @@ func TestContext2Refresh_moduleInputComputedOutput(t *testing.T) {
func TestContext2Refresh_moduleVarModule(t *testing.T) {
m := testModule(t, "refresh-module-var-module")
p := testProvider("aws")
p.PlanResourceChangeFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Config: m,
Providers: map[addrs.Provider]providers.Factory{
@ -699,13 +685,11 @@ func TestContext2Refresh_noState(t *testing.T) {
},
})
p.ReadResourceFn = nil
p.ReadResourceResponse = &providers.ReadResourceResponse{
NewState: cty.ObjectVal(map[string]cty.Value{
"id": cty.StringVal("foo"),
}),
}
p.PlanResourceChangeFn = testDiffFn
if _, diags := ctx.Refresh(); diags.HasErrors() {
t.Fatalf("refresh errs: %s", diags.Err())
@ -714,6 +698,7 @@ func TestContext2Refresh_noState(t *testing.T) {
func TestContext2Refresh_output(t *testing.T) {
p := testProvider("aws")
p.PlanResourceChangeFn = testDiffFn
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{},
ResourceTypes: map[string]*configschema.Block{
@ -732,7 +717,6 @@ func TestContext2Refresh_output(t *testing.T) {
},
},
})
p.PlanResourceChangeFn = testDiffFn
m := testModule(t, "refresh-output")
@ -768,7 +752,6 @@ func TestContext2Refresh_outputPartial(t *testing.T) {
// Refresh creates a partial plan for any instances that don't have
// remote objects yet, to get stub values for interpolation. Therefore
// we need to make DiffFn available to let that complete.
p.PlanResourceChangeFn = testDiffFn
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{},
@ -784,7 +767,6 @@ func TestContext2Refresh_outputPartial(t *testing.T) {
},
})
p.ReadResourceFn = nil
p.ReadResourceResponse = &providers.ReadResourceResponse{
NewState: cty.NullVal(p.GetSchemaResponse.ResourceTypes["aws_instance"].Block.ImpliedType()),
}
@ -839,8 +821,6 @@ func TestContext2Refresh_stateBasic(t *testing.T) {
t.Fatal(err)
}
p.ReadResourceFn = nil
p.PlanResourceChangeFn = testDiffFn
p.ReadResourceResponse = &providers.ReadResourceResponse{
NewState: readStateVal,
}
@ -949,7 +929,6 @@ func TestContext2Refresh_dataState(t *testing.T) {
State: readStateVal,
}
}
p.PlanResourceChangeFn = testDiffFn
s, diags := ctx.Refresh()
if diags.HasErrors() {
@ -1015,7 +994,6 @@ func TestContext2Refresh_dataStateRefData(t *testing.T) {
State: cty.ObjectVal(m),
}
}
p.PlanResourceChangeFn = testDiffFn
s, diags := ctx.Refresh()
if diags.HasErrors() {
@ -1053,7 +1031,6 @@ func TestContext2Refresh_tainted(t *testing.T) {
NewState: cty.ObjectVal(m),
}
}
p.PlanResourceChangeFn = testDiffFn
s, diags := ctx.Refresh()
if diags.HasErrors() {
@ -1076,9 +1053,6 @@ func TestContext2Refresh_tainted(t *testing.T) {
// Providers was _empty_.
func TestContext2Refresh_unknownProvider(t *testing.T) {
m := testModule(t, "refresh-unknown-provider")
p := testProvider("aws")
p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn
state := states.NewState()
root := state.EnsureModule(addrs.RootModuleInstance)
@ -1140,8 +1114,6 @@ func TestContext2Refresh_vars(t *testing.T) {
t.Fatal(err)
}
p.ReadResourceFn = nil
p.PlanResourceChangeFn = testDiffFn
p.ReadResourceResponse = &providers.ReadResourceResponse{
NewState: readStateVal,
}
@ -1195,7 +1167,6 @@ func TestContext2Refresh_orphanModule(t *testing.T) {
NewState: req.PriorState,
}
}
p.PlanResourceChangeFn = testDiffFn
state := states.NewState()
root := state.EnsureModule(addrs.RootModuleInstance)
@ -1265,7 +1236,6 @@ func TestContext2Validate(t *testing.T) {
},
},
})
p.PlanResourceChangeFn = testDiffFn
m := testModule(t, "validate-good")
c := testContext2(t, &ContextOpts{
@ -1284,8 +1254,6 @@ func TestContext2Validate(t *testing.T) {
func TestContext2Refresh_updateProviderInState(t *testing.T) {
m := testModule(t, "update-resource-provider")
p := testProvider("aws")
p.PlanResourceChangeFn = testDiffFn
p.ApplyResourceChangeFn = testApplyFn
state := states.NewState()
root := state.EnsureModule(addrs.RootModuleInstance)
@ -1338,7 +1306,6 @@ func TestContext2Refresh_schemaUpgradeFlatmap(t *testing.T) {
"name": cty.StringVal("foo"),
}),
}
p.PlanResourceChangeFn = testDiffFn
s := states.BuildState(func(s *states.SyncState) {
s.SetResourceInstanceCurrent(
@ -1425,7 +1392,6 @@ func TestContext2Refresh_schemaUpgradeJSON(t *testing.T) {
"name": cty.StringVal("foo"),
}),
}
p.PlanResourceChangeFn = testDiffFn
s := states.BuildState(func(s *states.SyncState) {
s.SetResourceInstanceCurrent(
@ -1503,7 +1469,6 @@ data "aws_data_source" "foo" {
resp.State = req.Config
return
}
p.PlanResourceChangeFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Config: m,
@ -1544,7 +1509,6 @@ func TestContext2Refresh_dataResourceDependsOn(t *testing.T) {
},
},
})
p.PlanResourceChangeFn = testDiffFn
p.ReadDataSourceResponse = &providers.ReadDataSourceResponse{
State: cty.ObjectVal(map[string]cty.Value{
"compute": cty.StringVal("value"),
@ -1653,8 +1617,6 @@ resource "aws_instance" "foo" {
})
p := testProvider("aws")
p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Config: m,
@ -1722,8 +1684,6 @@ resource "aws_instance" "bar" {
})
p := testProvider("aws")
p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Config: m,

View File

@ -1024,8 +1024,6 @@ func TestContext2Validate_targetedDestroy(t *testing.T) {
m := testModule(t, "validate-targeted")
p := testProvider("aws")
pr := simpleMockProvisioner()
p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn
p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]providers.Schema{
"aws_instance": {
@ -1117,8 +1115,6 @@ func TestContext2Validate_interpolateVar(t *testing.T) {
m := testModule(t, "input-interpolate-var")
p := testProvider("null")
p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn
p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]providers.Schema{
"template_file": {
@ -1152,8 +1148,6 @@ func TestContext2Validate_interpolateComputedModuleVarDef(t *testing.T) {
m := testModule(t, "validate-computed-module-var-ref")
p := testProvider("aws")
p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn
p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]providers.Schema{
"aws_instance": {
@ -1186,8 +1180,6 @@ func TestContext2Validate_interpolateMap(t *testing.T) {
m := testModule(t, "issue-9549")
p := testProvider("template")
p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Config: m,
@ -1691,7 +1683,6 @@ resource "aws_instance" "foo" {
})
p := testProvider("aws")
p.PlanResourceChangeFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Config: m,
Providers: map[addrs.Provider]providers.Factory{
@ -1720,7 +1711,6 @@ resource "aws_instance" "foo" {
})
p := testProvider("aws")
p.PlanResourceChangeFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Config: m,
Providers: map[addrs.Provider]providers.Factory{
@ -1752,7 +1742,6 @@ resource "aws_instance" "foo" {
})
p := testProvider("aws")
p.PlanResourceChangeFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Config: m,
Providers: map[addrs.Provider]providers.Factory{
@ -1835,7 +1824,6 @@ output "out" {
})
p := testProvider("aws")
p.PlanResourceChangeFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Config: m,
Providers: map[addrs.Provider]providers.Factory{

View File

@ -248,10 +248,10 @@ func (h *HookRecordApplyOrder) PreApply(addr addrs.AbsResourceInstance, gen stat
const testTerraformInputProviderOnlyStr = `
aws_instance.foo:
ID = foo
ID =
provider = provider["registry.terraform.io/hashicorp/aws"]
foo = us-west-2
type = aws_instance
type =
`
const testTerraformApplyStr = `