fix show-json test to expect error from nested mod

One of the show json command tests expected no error when presented with
an invalid configuration in a nested module. Modify the test created in
PR #21569 so that it can still verify there is no panic, but now expect
an error from init.
This commit is contained in:
James Bardin 2019-07-16 21:25:30 -04:00
parent 8111050c66
commit e4640a43d7
6 changed files with 45 additions and 20 deletions

View File

@ -5,6 +5,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"testing" "testing"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
@ -153,6 +154,8 @@ func TestShow_json_output(t *testing.T) {
defer os.RemoveAll(td) defer os.RemoveAll(td)
defer testChdir(t, td)() defer testChdir(t, td)()
expectError := strings.Contains(entry.Name(), "error")
p := showFixtureProvider() p := showFixtureProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
m := Meta{ m := Meta{
@ -171,6 +174,10 @@ func TestShow_json_output(t *testing.T) {
}, },
} }
if code := ic.Run([]string{}); code != 0 { if code := ic.Run([]string{}); code != 0 {
if expectError {
// this should error, but not panic.
return
}
t.Fatalf("init failed\n%s", ui.ErrorWriter) t.Fatalf("init failed\n%s", ui.ErrorWriter)
} }

View File

@ -0,0 +1,3 @@
module "my_module" {
source = "./modules"
}

View File

@ -0,0 +1,3 @@
module "more" {
source = "./more-modules"
}

View File

@ -0,0 +1,4 @@
variable "misspelled" {
default = "ehllo"
descriptoni = "I am a misspelled attribute"
}

View File

@ -1,4 +1,4 @@
variable "misspelled" { variable "ok" {
default = "ehllo" default = "something"
descriptoni = "I am a misspelled attribute" description = "description"
} }

View File

@ -1,23 +1,31 @@
{ {
"format_version": "0.1", "format_version": "0.1",
"terraform_version": "0.12.1-dev", "terraform_version": "0.12.1-dev",
"planned_values": { "planned_values": {
"root_module": {} "root_module": {}
}, },
"configuration": { "configuration": {
"root_module": { "root_module": {
"module_calls": {
"my_module": {
"source": "./modules",
"module": {
"module_calls": { "module_calls": {
"my_module": { "more": {
"source": "./modules", "module": {
"module": { "variables": {
"module_calls": { "ok": {
"more": { "default": "something",
"module": {} "description": "description"
}
}
} }
} }
},
"source": "./more-modules"
}
} }
}
} }
}
} }
} }
}