From 16fc138b3663ac0e9d744d1b490bf0366ed31ea5 Mon Sep 17 00:00:00 2001 From: Katy Moe Date: Thu, 17 Dec 2020 11:47:05 +0000 Subject: [PATCH 1/2] add test for bigint json.Number representation --- tfexec/internal/e2etest/show_test.go | 58 ++++++++++++++++++- .../internal/e2etest/testdata/bigint/main.tf | 13 +++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 tfexec/internal/e2etest/testdata/bigint/main.tf diff --git a/tfexec/internal/e2etest/show_test.go b/tfexec/internal/e2etest/show_test.go index 565b6d5a..e40c78b6 100644 --- a/tfexec/internal/e2etest/show_test.go +++ b/tfexec/internal/e2etest/show_test.go @@ -2,6 +2,7 @@ package e2etest import ( "context" + "encoding/json" "errors" "io/ioutil" "runtime" @@ -462,7 +463,6 @@ func TestShowPlanFileRaw014(t *testing.T) { if err != nil { t.Fatal(err) } - if strings.TrimSpace(actual) != strings.TrimSpace(string(expected)) { dmp := diffmatchpatch.New() diffs := dmp.DiffMain(strings.TrimSpace(actual), strings.TrimSpace(string(expected)), false) @@ -470,3 +470,59 @@ func TestShowPlanFileRaw014(t *testing.T) { } }) } + +func TestShowBigInt(t *testing.T) { + runTest(t, "bigint", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) { + if tfv.LessThan(showMinVersion) { + t.Skip("terraform show was added in Terraform 0.12, so test is not valid") + } + + providerName := "registry.terraform.io/hashicorp/random" + if tfv.LessThan(providerAddressMinVersion) { + providerName = "random" + } + + expected := &tfjson.State{ + FormatVersion: "0.1", + // TerraformVersion is ignored to facilitate latest version testing + Values: &tfjson.StateValues{ + RootModule: &tfjson.StateModule{ + Resources: []*tfjson.StateResource{{ + Address: "random_integer.bigint", + AttributeValues: map[string]interface{}{ + "id": "7227701560655103598", + "max": json.Number("7227701560655103598"), + "min": json.Number("7227701560655103597"), + "result": json.Number("7227701560655103598"), + "seed": "12345", + "keepers": nil, + }, + Mode: tfjson.ManagedResourceMode, + Type: "random_integer", + Name: "bigint", + ProviderName: providerName, + }}, + }, + }, + } + + err := tf.Init(context.Background()) + if err != nil { + t.Fatalf("error running Init in test directory: %s", err) + } + + err = tf.Apply(context.Background()) + if err != nil { + t.Fatalf("error running Apply in test directory: %s", err) + } + + actual, err := tf.Show(context.Background()) + if err != nil { + t.Fatal(err) + } + + if diff := diffState(expected, actual); diff != "" { + t.Fatalf("mismatch (-want +got):\n%s", diff) + } + }) +} diff --git a/tfexec/internal/e2etest/testdata/bigint/main.tf b/tfexec/internal/e2etest/testdata/bigint/main.tf new file mode 100644 index 00000000..fe0e5977 --- /dev/null +++ b/tfexec/internal/e2etest/testdata/bigint/main.tf @@ -0,0 +1,13 @@ +terraform { + required_providers { + random = { + version = "3.0.0" + } + } +} + +resource "random_integer" "bigint" { + max = 7227701560655103598 + min = 7227701560655103597 + seed = 12345 +} From 51d32b586d9b9c2bfe3ff5fc2a7370f968413413 Mon Sep 17 00:00:00 2001 From: Katy Moe Date: Tue, 12 Jan 2021 15:46:03 +0000 Subject: [PATCH 2/2] update to fixed version of provider --- tfexec/internal/e2etest/testdata/bigint/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tfexec/internal/e2etest/testdata/bigint/main.tf b/tfexec/internal/e2etest/testdata/bigint/main.tf index fe0e5977..26ab3b77 100644 --- a/tfexec/internal/e2etest/testdata/bigint/main.tf +++ b/tfexec/internal/e2etest/testdata/bigint/main.tf @@ -1,7 +1,7 @@ terraform { required_providers { random = { - version = "3.0.0" + version = "3.0.1" } } }