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

e2e test for bigint json.Number representation #114

Merged
merged 2 commits into from
Jan 14, 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
58 changes: 57 additions & 1 deletion tfexec/internal/e2etest/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package e2etest

import (
"context"
"encoding/json"
"errors"
"io/ioutil"
"runtime"
Expand Down Expand Up @@ -462,11 +463,66 @@ 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)
t.Fatalf("actual:\n\n%s\n\nexpected:\n\n%s\n\ndiff:\n\n%s", actual, string(expected), dmp.DiffPrettyText(diffs))
}
})
}

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)
}
})
}
13 changes: 13 additions & 0 deletions tfexec/internal/e2etest/testdata/bigint/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
terraform {
required_providers {
random = {
version = "3.0.1"
}
}
}

resource "random_integer" "bigint" {
max = 7227701560655103598
min = 7227701560655103597
seed = 12345
}