Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/graph: Fix failing E2E tests #261

Merged
merged 1 commit into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 79 additions & 4 deletions tfexec/internal/e2etest/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(expectedGraphOutput(tfv), graphOutput); diff != "" {
t.Fatalf("Graph output does not match: %s", diff)
}
})
}

func expectedGraphOutput(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)"
}
}

`
}
12 changes: 7 additions & 5 deletions tfexec/internal/e2etest/providers_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
}

Expand Down