From 1f374dc446c7b250ee6fd9fe0fa619826bcb38da Mon Sep 17 00:00:00 2001 From: James Bardin Date: Mon, 24 Sep 2018 15:27:03 -0400 Subject: [PATCH] fix refresh test provider schema must be defined before initializing the context --- terraform/context_refresh_test.go | 49 ++++++++++++++++--------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/terraform/context_refresh_test.go b/terraform/context_refresh_test.go index 17032b604..14c42440a 100644 --- a/terraform/context_refresh_test.go +++ b/terraform/context_refresh_test.go @@ -777,6 +777,31 @@ func TestContext2Refresh_output(t *testing.T) { func TestContext2Refresh_outputPartial(t *testing.T) { p := testProvider("aws") m := testModule(t, "refresh-output-partial") + + // 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.DiffFn = testDiffFn + + p.GetSchemaReturn = &ProviderSchema{ + Provider: &configschema.Block{}, + ResourceTypes: map[string]*configschema.Block{ + "aws_instance": { + Attributes: map[string]*configschema.Attribute{ + "foo": { + Type: cty.String, + Computed: true, + }, + }, + }, + }, + } + + p.ReadResourceFn = nil + p.ReadResourceResponse = providers.ReadResourceResponse{ + NewState: cty.NullVal(p.GetSchemaReturn.ResourceTypes["aws_instance"].ImpliedType()), + } + ctx := testContext2(t, &ContextOpts{ Config: m, ProviderResolver: providers.ResolverFixed( @@ -802,30 +827,6 @@ func TestContext2Refresh_outputPartial(t *testing.T) { }), }) - p.ReadResourceFn = nil - p.ReadResourceResponse = providers.ReadResourceResponse{ - NewState: cty.NullVal(p.GetSchemaReturn.ResourceTypes["aws_instance"].ImpliedType()), - } - - // 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.DiffFn = testDiffFn - - p.GetSchemaReturn = &ProviderSchema{ - Provider: &configschema.Block{}, - ResourceTypes: map[string]*configschema.Block{ - "aws_instance": { - Attributes: map[string]*configschema.Attribute{ - "foo": { - Type: cty.String, - Computed: true, - }, - }, - }, - }, - } - s, diags := ctx.Refresh() if diags.HasErrors() { t.Fatalf("refresh errors: %s", diags.Err())