Skip to content

Commit

Permalink
Update test data to account for v1.1+ changes
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Jun 23, 2021
1 parent 4913e4c commit 1ec9c82
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 16 deletions.
40 changes: 30 additions & 10 deletions tfexec/internal/e2etest/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import (
"github.com/hashicorp/terraform-exec/tfexec/internal/testutil"
)

var (
v1_1_0 = version.Must(version.NewVersion("1.1.0"))
)

func TestShow(t *testing.T) {
runTest(t, "basic_with_state", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {

Expand All @@ -30,8 +34,15 @@ func TestShow(t *testing.T) {
providerName = "null"
}

formatVersion := "0.1"
var sensitiveValues json.RawMessage
if tfv.Core().GreaterThanOrEqual(v1_1_0) {
formatVersion = "0.2"
sensitiveValues = json.RawMessage([]byte("{}"))
}

expected := &tfjson.State{
FormatVersion: "0.1",
FormatVersion: formatVersion,
// TerraformVersion is ignored to facilitate latest version testing
Values: &tfjson.StateValues{
RootModule: &tfjson.StateModule{
Expand All @@ -41,10 +52,11 @@ func TestShow(t *testing.T) {
"id": "5510719323588825107",
"triggers": nil,
},
Mode: tfjson.ManagedResourceMode,
Type: "null_resource",
Name: "foo",
ProviderName: providerName,
SensitiveValues: sensitiveValues,
Mode: tfjson.ManagedResourceMode,
Type: "null_resource",
Name: "foo",
ProviderName: providerName,
}},
},
},
Expand Down Expand Up @@ -523,8 +535,15 @@ func TestShowBigInt(t *testing.T) {
providerName = "random"
}

formatVersion := "0.1"
var sensitiveValues json.RawMessage
if tfv.Core().GreaterThanOrEqual(v1_1_0) {
formatVersion = "0.2"
sensitiveValues = json.RawMessage([]byte("{}"))
}

expected := &tfjson.State{
FormatVersion: "0.1",
FormatVersion: formatVersion,
// TerraformVersion is ignored to facilitate latest version testing
Values: &tfjson.StateValues{
RootModule: &tfjson.StateModule{
Expand All @@ -538,10 +557,11 @@ func TestShowBigInt(t *testing.T) {
"seed": "12345",
"keepers": nil,
},
Mode: tfjson.ManagedResourceMode,
Type: "random_integer",
Name: "bigint",
ProviderName: providerName,
SensitiveValues: sensitiveValues,
Mode: tfjson.ManagedResourceMode,
Type: "random_integer",
Name: "bigint",
ProviderName: providerName,
}},
},
},
Expand Down
19 changes: 14 additions & 5 deletions tfexec/internal/e2etest/state_mv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package e2etest

import (
"context"
"encoding/json"
"testing"

"github.com/hashicorp/go-version"
Expand All @@ -28,9 +29,16 @@ func TestStateMv(t *testing.T) {
t.Fatalf("error running StateMv: %s", err)
}

formatVersion := "0.1"
var sensitiveValues json.RawMessage
if tfv.Core().GreaterThanOrEqual(v1_1_0) {
formatVersion = "0.2"
sensitiveValues = json.RawMessage([]byte("{}"))
}

// test that the new state is as expected
expected := &tfjson.State{
FormatVersion: "0.1",
FormatVersion: formatVersion,
// TerraformVersion is ignored to facilitate latest version testing
Values: &tfjson.StateValues{
RootModule: &tfjson.StateModule{
Expand All @@ -40,10 +48,11 @@ func TestStateMv(t *testing.T) {
"id": "5510719323588825107",
"triggers": nil,
},
Mode: tfjson.ManagedResourceMode,
Type: "null_resource",
Name: "bar",
ProviderName: providerName,
SensitiveValues: sensitiveValues,
Mode: tfjson.ManagedResourceMode,
Type: "null_resource",
Name: "bar",
ProviderName: providerName,
}},
},
},
Expand Down
7 changes: 6 additions & 1 deletion tfexec/internal/e2etest/state_rm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ func TestStateRm(t *testing.T) {
t.Fatalf("error running StateRm: %s", err)
}

formatVersion := "0.1"
if tfv.Core().GreaterThanOrEqual(v1_1_0) {
formatVersion = "0.2"
}

// test that the new state is as expected
expected := &tfjson.State{
FormatVersion: "0.1",
FormatVersion: formatVersion,
// TerraformVersion is ignored to facilitate latest version testing
Values: nil,
}
Expand Down

0 comments on commit 1ec9c82

Please sign in to comment.