From a19b762c77c15f4ffe336d398ca49c8275cda269 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Tue, 14 Dec 2021 07:39:25 +0100 Subject: [PATCH] fix test --- tfexec/internal/e2etest/graph_test.go | 83 ++++++++++++++++++- .../internal/e2etest/providers_schema_test.go | 12 +-- 2 files changed, 86 insertions(+), 9 deletions(-) diff --git a/tfexec/internal/e2etest/graph_test.go b/tfexec/internal/e2etest/graph_test.go index 216134e4..8f9bafce 100644 --- a/tfexec/internal/e2etest/graph_test.go +++ b/tfexec/internal/e2etest/graph_test.go @@ -2,9 +2,9 @@ package e2etest import ( "context" - "strings" "testing" + "github.com/google/go-cmp/cmp" "github.com/hashicorp/go-version" "github.com/hashicorp/terraform-exec/tfexec" @@ -27,9 +27,84 @@ func TestGraph(t *testing.T) { t.Fatalf("error running Graph: %s", err) } - // Graph output differs slightly between versions, but resource subgraph remains consistent - if !strings.Contains(graphOutput, `"[root] null_resource.foo" [label = "null_resource.foo", shape = "box"]`) { - t.Fatalf("error running Graph. Graph output does not contain expected strings. Returned: %s", graphOutput) + if diff := cmp.Diff(expectedGgraphOutput(tfv), graphOutput); diff != "" { + t.Fatalf("Graph output does not match: %s", diff) } }) } + +func expectedGgraphOutput(tfv *version.Version) string { + v := tfv.Core() + + if v.LessThan(v0_12_0) { + // TF <=0.11.15 + return `digraph { + compound = "true" + newrank = "true" + subgraph "root" { + "[root] null_resource.foo" [label = "null_resource.foo", shape = "box"] + "[root] provider.null" [label = "provider.null", shape = "diamond"] + "[root] meta.count-boundary (count boundary fixup)" -> "[root] null_resource.foo" + "[root] null_resource.foo" -> "[root] provider.null" + "[root] provider.null (close)" -> "[root] null_resource.foo" + "[root] root" -> "[root] meta.count-boundary (count boundary fixup)" + "[root] root" -> "[root] provider.null (close)" + } +} + +` + } + + if v.GreaterThanOrEqual(v0_12_0) && v.LessThan(v0_13_0) { + // TF 0.12.20 - 0.12.31 + return `digraph { + compound = "true" + newrank = "true" + subgraph "root" { + "[root] null_resource.foo" [label = "null_resource.foo", shape = "box"] + "[root] provider.null" [label = "provider.null", shape = "diamond"] + "[root] meta.count-boundary (EachMode fixup)" -> "[root] null_resource.foo" + "[root] null_resource.foo" -> "[root] provider.null" + "[root] provider.null (close)" -> "[root] null_resource.foo" + "[root] root" -> "[root] meta.count-boundary (EachMode fixup)" + "[root] root" -> "[root] provider.null (close)" + } +} + +` + } + + if v.GreaterThanOrEqual(v0_13_0) && v.LessThan(v1_1) { + // 0.13.0 - 1.0.11 + return `digraph { + compound = "true" + newrank = "true" + subgraph "root" { + "[root] null_resource.foo (expand)" [label = "null_resource.foo", shape = "box"] + "[root] provider[\"registry.terraform.io/hashicorp/null\"]" [label = "provider[\"registry.terraform.io/hashicorp/null\"]", shape = "diamond"] + "[root] meta.count-boundary (EachMode fixup)" -> "[root] null_resource.foo (expand)" + "[root] null_resource.foo (expand)" -> "[root] provider[\"registry.terraform.io/hashicorp/null\"]" + "[root] provider[\"registry.terraform.io/hashicorp/null\"] (close)" -> "[root] null_resource.foo (expand)" + "[root] root" -> "[root] meta.count-boundary (EachMode fixup)" + "[root] root" -> "[root] provider[\"registry.terraform.io/hashicorp/null\"] (close)" + } +} + +` + } + + // 1.1.0+ + return `digraph { + compound = "true" + newrank = "true" + subgraph "root" { + "[root] null_resource.foo (expand)" [label = "null_resource.foo", shape = "box"] + "[root] provider[\"registry.terraform.io/hashicorp/null\"]" [label = "provider[\"registry.terraform.io/hashicorp/null\"]", shape = "diamond"] + "[root] null_resource.foo (expand)" -> "[root] provider[\"registry.terraform.io/hashicorp/null\"]" + "[root] provider[\"registry.terraform.io/hashicorp/null\"] (close)" -> "[root] null_resource.foo (expand)" + "[root] root" -> "[root] provider[\"registry.terraform.io/hashicorp/null\"] (close)" + } +} + +` +} diff --git a/tfexec/internal/e2etest/providers_schema_test.go b/tfexec/internal/e2etest/providers_schema_test.go index fafc051d..677a3a97 100644 --- a/tfexec/internal/e2etest/providers_schema_test.go +++ b/tfexec/internal/e2etest/providers_schema_test.go @@ -13,10 +13,12 @@ import ( ) var ( - providersSchemaJSONMinVersion = version.Must(version.NewVersion("0.12.0")) - v0_13_0 = version.Must(version.NewVersion("0.13.0")) - v0_15_0 = version.Must(version.NewVersion("0.15.0")) - v1_1 = version.Must(version.NewVersion("1.1.0")) + v0_12_0 = version.Must(version.NewVersion("0.12.0")) + v0_13_0 = version.Must(version.NewVersion("0.13.0")) + v0_14_0 = version.Must(version.NewVersion("0.14.0")) + v0_15_0 = version.Must(version.NewVersion("0.15.0")) + v1_0 = version.Must(version.NewVersion("1.0.0")) + v1_1 = version.Must(version.NewVersion("1.1.0")) ) func TestProvidersSchema(t *testing.T) { @@ -221,7 +223,7 @@ same can now be achieved using [locals](https://www.terraform.io/docs/language/v c := c t.Run(fmt.Sprintf("%d %s", i, c.fixtureDir), func(t *testing.T) { runTest(t, c.fixtureDir, func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) { - if tfv.Core().LessThan(providersSchemaJSONMinVersion) { + if tfv.Core().LessThan(v0_12_0) { t.Skip("providers schema -json was added in 0.12") }