Fix some plan tests with planned data

Start fixing plan tests that don't expect data sources to be in the
plan. A few were just checking that Read was never called, and some
expected the data source to be nil.
This commit is contained in:
James Bardin 2020-05-05 11:45:33 -04:00
parent 7df0f6c1fc
commit 924162923a
1 changed files with 13 additions and 23 deletions

View File

@ -1892,10 +1892,9 @@ func TestContext2Plan_computedInFunction(t *testing.T) {
_, diags = ctx.Plan() // should do nothing with data resource in this step, since it was already read
assertNoErrors(t, diags)
if p.ReadDataSourceCalled {
t.Fatalf("ReadDataSource was called on provider during plan; should not have been called")
if !p.ReadDataSourceCalled {
t.Fatalf("ReadDataSource should have been called")
}
}
func TestContext2Plan_computedDataCountResource(t *testing.T) {
@ -4992,8 +4991,10 @@ func TestContext2Plan_createBeforeDestroy_depends_datasource(t *testing.T) {
}
}
p.ReadDataSourceFn = func(req providers.ReadDataSourceRequest) providers.ReadDataSourceResponse {
cfg := req.Config.AsValueMap()
cfg["id"] = cty.StringVal("data_id")
return providers.ReadDataSourceResponse{
Diagnostics: tfdiags.Diagnostics(nil).Append(fmt.Errorf("ReadDataSource called, but should not have been")),
State: cty.ObjectVal(cfg),
}
}
@ -5010,9 +5011,6 @@ func TestContext2Plan_createBeforeDestroy_depends_datasource(t *testing.T) {
// thus the plan call below is forced to produce a deferred read action.
plan, diags := ctx.Plan()
if p.ReadDataSourceCalled {
t.Errorf("ReadDataSource was called on the provider, but should not have been because we didn't refresh")
}
if diags.HasErrors() {
t.Fatalf("unexpected errors: %s", diags.Err())
}
@ -5042,7 +5040,7 @@ func TestContext2Plan_createBeforeDestroy_depends_datasource(t *testing.T) {
}
checkVals(t, objectVal(t, schema, map[string]cty.Value{
"num": cty.StringVal("2"),
"computed": cty.UnknownVal(cty.String),
"computed": cty.StringVal("data_id"),
}), ric.After)
case "aws_instance.foo[1]":
if res.Action != plans.Create {
@ -5050,30 +5048,22 @@ func TestContext2Plan_createBeforeDestroy_depends_datasource(t *testing.T) {
}
checkVals(t, objectVal(t, schema, map[string]cty.Value{
"num": cty.StringVal("2"),
"computed": cty.UnknownVal(cty.String),
"computed": cty.StringVal("data_id"),
}), ric.After)
case "data.aws_vpc.bar[0]":
if res.Action != plans.Read {
t.Fatalf("resource %s should be read, got %s", ric.Addr, ric.Action)
if res.Action != plans.Update {
t.Fatalf("resource %s should be update, got %s", ric.Addr, ric.Action)
}
checkVals(t, objectVal(t, schema, map[string]cty.Value{
// In a normal flow we would've read an exact value in
// ReadDataSource, but because this test doesn't run
// cty.Refresh we have no opportunity to do that lookup
// and a deferred read is forced.
"id": cty.UnknownVal(cty.String),
"id": cty.StringVal("data_id"),
"foo": cty.StringVal("0"),
}), ric.After)
case "data.aws_vpc.bar[1]":
if res.Action != plans.Read {
t.Fatalf("resource %s should be read, got %s", ric.Addr, ric.Action)
if res.Action != plans.Update {
t.Fatalf("resource %s should be update, got %s", ric.Addr, ric.Action)
}
checkVals(t, objectVal(t, schema, map[string]cty.Value{
// In a normal flow we would've read an exact value in
// ReadDataSource, but because this test doesn't run
// cty.Refresh we have no opportunity to do that lookup
// and a deferred read is forced.
"id": cty.UnknownVal(cty.String),
"id": cty.StringVal("data_id"),
"foo": cty.StringVal("1"),
}), ric.After)
default: