Skip to content

Commit

Permalink
cmd: Add tests to -w and -r
Browse files Browse the repository at this point in the history
  • Loading branch information
shihanng committed Nov 26, 2021
1 parent 67fca7e commit d830103
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
37 changes: 37 additions & 0 deletions cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"
"testing"

"github.com/sebdah/goldie/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -44,6 +45,42 @@ export TF_VAR_password=''
`, actual.String())
}

func TestWFlag(t *testing.T) {
os.Args = strings.Fields("tfvar testdata -w")

var actual bytes.Buffer
cmd, sync := New(&actual, "dev")
defer sync()

require.NoError(t, cmd.Execute())

g := goldie.New(
t,
goldie.WithNameSuffix(".golden.json"),
goldie.WithDiffEngine(goldie.ColoredDiff),
)

g.Assert(t, "w_flag", actual.Bytes())
}

func TestRFlag(t *testing.T) {
os.Args = strings.Fields("tfvar testdata -r")

var actual bytes.Buffer
cmd, sync := New(&actual, "dev")
defer sync()

require.NoError(t, cmd.Execute())

g := goldie.New(
t,
goldie.WithNameSuffix(".golden.tf"),
goldie.WithDiffEngine(goldie.ColoredDiff),
)

g.Assert(t, "r_flag", actual.Bytes())
}

func TestIgnoreDefault(t *testing.T) {
os.Args = strings.Fields("tfvar testdata --ignore-default")

Expand Down
40 changes: 40 additions & 0 deletions cmd/testdata/r_flag.golden.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

resource "tfe_variable" "availability_zone_names" {
key = "availability_zone_names"
value = ["us-west-1a"]
sensitive = false
description = ""
workspace_id = null
category = "terraform"
}

resource "tfe_variable" "docker_ports" {
key = "docker_ports"
value = [{
external = 8300
internal = 8300
protocol = "tcp"
}]
sensitive = false
description = ""
workspace_id = null
category = "terraform"
}

resource "tfe_variable" "image_id" {
key = "image_id"
value = null
sensitive = false
description = ""
workspace_id = null
category = "terraform"
}

resource "tfe_variable" "password" {
key = "password"
value = null
sensitive = true
description = "the root password to use with the database"
workspace_id = null
category = "terraform"
}
52 changes: 52 additions & 0 deletions cmd/testdata/w_flag.golden.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"data": {
"type": "vars",
"attributes": {
"key": "availability_zone_names",
"value": "['us-west-1a']",
"description": "",
"category": "terraform",
"hcl": false,
"sensitive": false
}
}
}
{
"data": {
"type": "vars",
"attributes": {
"key": "docker_ports",
"value": "[{ external = 8300, internal = 8300, protocol = 'tcp' }]",
"description": "",
"category": "terraform",
"hcl": false,
"sensitive": false
}
}
}
{
"data": {
"type": "vars",
"attributes": {
"key": "image_id",
"value": "",
"description": "",
"category": "terraform",
"hcl": false,
"sensitive": false
}
}
}
{
"data": {
"type": "vars",
"attributes": {
"key": "password",
"value": "",
"description": "the root password to use with the database",
"category": "terraform",
"hcl": false,
"sensitive": true
}
}
}

0 comments on commit d830103

Please sign in to comment.