Skip to content

Commit

Permalink
add test for bigint json.Number representation
Browse files Browse the repository at this point in the history
  • Loading branch information
kmoe committed Dec 17, 2020
1 parent 9186a7c commit fea1edc
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
57 changes: 57 additions & 0 deletions 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 @@ -376,3 +377,59 @@ func TestShowPlanFileRaw013(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": "7227701560655103597",
"max": json.Number("7227701560655103597"),
"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.0"
}
}
}

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

0 comments on commit fea1edc

Please sign in to comment.