From f1657bb3e35acad90f6aff79110c593b9462cc4d Mon Sep 17 00:00:00 2001 From: James Bardin Date: Mon, 24 Sep 2018 19:25:40 -0400 Subject: [PATCH] update some graph builder tests Reduce the graphs, as they are too ungainly to compare without reduction. We also depend on reduction in all use cases, so we should be testing the graph as we use it anyway. --- terraform/graph_builder_apply_test.go | 40 +++++++++++++-------------- terraform/graph_test.go | 1 + 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/terraform/graph_builder_apply_test.go b/terraform/graph_builder_apply_test.go index bad77ced5d..fc7599c204 100644 --- a/terraform/graph_builder_apply_test.go +++ b/terraform/graph_builder_apply_test.go @@ -45,11 +45,10 @@ func TestApplyGraphBuilder(t *testing.T) { } b := &ApplyGraphBuilder{ - Config: testModule(t, "graph-builder-apply-basic"), - Changes: changes, - Components: simpleMockComponentFactory(), - Schemas: simpleTestSchemas(), - DisableReduce: true, + Config: testModule(t, "graph-builder-apply-basic"), + Changes: changes, + Components: simpleMockComponentFactory(), + Schemas: simpleTestSchemas(), } g, err := b.Build(addrs.RootModuleInstance) @@ -62,6 +61,7 @@ func TestApplyGraphBuilder(t *testing.T) { } actual := strings.TrimSpace(g.String()) + expected := strings.TrimSpace(testApplyGraphBuilderStr) if actual != expected { t.Fatalf("wrong result\n\ngot:\n%s\n\nwant:\n%s", actual, expected) @@ -89,18 +89,16 @@ func TestApplyGraphBuilder_depCbd(t *testing.T) { } b := &ApplyGraphBuilder{ - Config: testModule(t, "graph-builder-apply-dep-cbd"), - Changes: changes, - Components: simpleMockComponentFactory(), - Schemas: simpleTestSchemas(), - DisableReduce: true, + Config: testModule(t, "graph-builder-apply-dep-cbd"), + Changes: changes, + Components: simpleMockComponentFactory(), + Schemas: simpleTestSchemas(), } g, err := b.Build(addrs.RootModuleInstance) if err != nil { t.Fatalf("err: %s", err) } - t.Logf("Graph: %s", g.String()) if g.Path.String() != addrs.RootModuleInstance.String() { t.Fatalf("wrong path %q", g.Path.String()) @@ -123,10 +121,9 @@ func TestApplyGraphBuilder_depCbd(t *testing.T) { t.Fatalf("no deposed instance node in the graph; want one") } - destroyName := fmt.Sprintf("test_object.A (deposed %s)", dk) + destroyName := fmt.Sprintf("test_object.A (destroy deposed %s)", dk) // Create A, Modify B, Destroy A - testGraphHappensBefore( t, g, "test_object.A", @@ -444,25 +441,22 @@ func TestApplyGraphBuilder_targetModule(t *testing.T) { const testApplyGraphBuilderStr = ` meta.count-boundary (EachMode fixup) - module.child.provisioner.test - module.child.test_object.create module.child.test_object.other - provider.test - test_object.create test_object.other module.child.provisioner.test module.child.test_object.create + module.child.test_object.create (prepare state) +module.child.test_object.create (prepare state) module.child.provisioner.test provider.test module.child.test_object.other module.child.test_object.create + module.child.test_object.other (prepare state) +module.child.test_object.other (prepare state) provider.test provider.test provider.test (close) - module.child.test_object.create module.child.test_object.other - provider.test - test_object.create test_object.other provisioner.test (close) module.child.test_object.create @@ -471,10 +465,14 @@ root provider.test (close) provisioner.test (close) test_object.create + test_object.create (prepare state) +test_object.create (prepare state) provider.test test_object.other - provider.test test_object.create + test_object.other (prepare state) +test_object.other (prepare state) + provider.test ` const testApplyGraphBuilderDoubleCBDStr = ` diff --git a/terraform/graph_test.go b/terraform/graph_test.go index 91f5774de9..7dac808e8a 100644 --- a/terraform/graph_test.go +++ b/terraform/graph_test.go @@ -35,6 +35,7 @@ func testGraphNotContains(t *testing.T, g *Graph, name string) { // testGraphHappensBefore is an assertion helper that tests that node // A (dag.VertexName value) happens before node B. func testGraphHappensBefore(t *testing.T, g *Graph, A, B string) { + t.Helper() // Find the B vertex var vertexB dag.Vertex for _, v := range g.Vertices() {