From 0ca5eab545a9f8bfaf22fb091a280758d1fa4529 Mon Sep 17 00:00:00 2001 From: Chris Marchesi Date: Sat, 24 Jun 2017 22:41:12 -0700 Subject: [PATCH] core: Context-level test for stub EvalDiff Added a new test that ensures that pre/post-diff hooks are not called when EvalDiff is run with Stub set, tested through a full refresh run. This helps test the expected behaviour of EvalDiff itself, versus the end result of the diff being counted in a plan, which is what the TestLocal_planScaleOutNoDupeCount test in backend/local checks. --- terraform/context_refresh_test.go | 60 +++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/terraform/context_refresh_test.go b/terraform/context_refresh_test.go index 0a977b4cc..22b959315 100644 --- a/terraform/context_refresh_test.go +++ b/terraform/context_refresh_test.go @@ -1049,3 +1049,63 @@ func TestContext2Validate(t *testing.T) { t.Fatalf("bad: %s", e) } } + +// TestContext2Refresh_noDiffHookOnScaleOut tests to make sure that +// pre/post-diff hooks are not called when running EvalDiff on scale-out nodes +// (nodes with no state). The effect here is to make sure that the diffs - +// which only exist for interpolation of parallel resources or data sources - +// do not end up being counted in the UI. +func TestContext2Refresh_noDiffHookOnScaleOut(t *testing.T) { + h := new(MockHook) + p := testProvider("aws") + m := testModule(t, "refresh-resource-scale-inout") + p.RefreshFn = nil + + state := &State{ + Modules: []*ModuleState{ + &ModuleState{ + Path: rootModulePath, + Resources: map[string]*ResourceState{ + "aws_instance.foo.0": &ResourceState{ + Type: "aws_instance", + Deposed: []*InstanceState{ + &InstanceState{ + ID: "foo", + }, + }, + }, + "aws_instance.foo.1": &ResourceState{ + Type: "aws_instance", + Deposed: []*InstanceState{ + &InstanceState{ + ID: "bar", + }, + }, + }, + }, + }, + }, + } + + ctx := testContext2(t, &ContextOpts{ + Module: m, + Hooks: []Hook{h}, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), + State: state, + }) + + _, err := ctx.Refresh() + if err != nil { + t.Fatalf("bad: %s", err) + } + if h.PreDiffCalled { + t.Fatal("PreDiff should not have been called") + } + if h.PostDiffCalled { + t.Fatal("PostDiff should not have been called") + } +}