fix command tests

A number of tests had invalid configs or providers, but were never
properly validated
This commit is contained in:
James Bardin 2020-08-07 14:04:40 -04:00
parent 3cf84bb3f9
commit 99cd3ab223
3 changed files with 29 additions and 7 deletions

View File

@ -8,8 +8,11 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/hashicorp/terraform/configs/configschema"
"github.com/hashicorp/terraform/helper/copy" "github.com/hashicorp/terraform/helper/copy"
"github.com/hashicorp/terraform/terraform"
"github.com/mitchellh/cli" "github.com/mitchellh/cli"
"github.com/zclconf/go-cty/cty"
) )
// ConsoleCommand is tested primarily with tests in the "repl" package. // ConsoleCommand is tested primarily with tests in the "repl" package.
@ -60,6 +63,16 @@ func TestConsole_tfvars(t *testing.T) {
} }
p := testProvider() p := testProvider()
p.GetSchemaReturn = &terraform.ProviderSchema{
ResourceTypes: map[string]*configschema.Block{
"test_instance": {
Attributes: map[string]*configschema.Attribute{
"value": {Type: cty.String, Optional: true},
},
},
},
}
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &ConsoleCommand{ c := &ConsoleCommand{
Meta: Meta{ Meta: Meta{
@ -98,6 +111,15 @@ func TestConsole_unsetRequiredVars(t *testing.T) {
defer testFixCwd(t, tmp, cwd) defer testFixCwd(t, tmp, cwd)
p := testProvider() p := testProvider()
p.GetSchemaReturn = &terraform.ProviderSchema{
ResourceTypes: map[string]*configschema.Block{
"test_instance": {
Attributes: map[string]*configschema.Attribute{
"value": {Type: cty.String, Optional: true},
},
},
},
}
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &ConsoleCommand{ c := &ConsoleCommand{
Meta: Meta{ Meta: Meta{
@ -142,7 +164,7 @@ func TestConsole_modules(t *testing.T) {
defer os.RemoveAll(td) defer os.RemoveAll(td)
defer testChdir(t, td)() defer testChdir(t, td)()
p := testProvider() p := applyFixtureProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &ConsoleCommand{ c := &ConsoleCommand{

View File

@ -20,7 +20,7 @@ func TestGraph(t *testing.T) {
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &GraphCommand{ c := &GraphCommand{
Meta: Meta{ Meta: Meta{
testingOverrides: metaOverridesForProvider(testProvider()), testingOverrides: metaOverridesForProvider(applyFixtureProvider()),
Ui: ui, Ui: ui,
}, },
} }
@ -42,7 +42,7 @@ func TestGraph_multipleArgs(t *testing.T) {
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &GraphCommand{ c := &GraphCommand{
Meta: Meta{ Meta: Meta{
testingOverrides: metaOverridesForProvider(testProvider()), testingOverrides: metaOverridesForProvider(applyFixtureProvider()),
Ui: ui, Ui: ui,
}, },
} }
@ -69,7 +69,7 @@ func TestGraph_noArgs(t *testing.T) {
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &GraphCommand{ c := &GraphCommand{
Meta: Meta{ Meta: Meta{
testingOverrides: metaOverridesForProvider(testProvider()), testingOverrides: metaOverridesForProvider(applyFixtureProvider()),
Ui: ui, Ui: ui,
}, },
} }
@ -94,7 +94,7 @@ func TestGraph_noConfig(t *testing.T) {
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &GraphCommand{ c := &GraphCommand{
Meta: Meta{ Meta: Meta{
testingOverrides: metaOverridesForProvider(testProvider()), testingOverrides: metaOverridesForProvider(applyFixtureProvider()),
Ui: ui, Ui: ui,
}, },
} }
@ -148,7 +148,7 @@ func TestGraph_plan(t *testing.T) {
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &GraphCommand{ c := &GraphCommand{
Meta: Meta{ Meta: Meta{
testingOverrides: metaOverridesForProvider(testProvider()), testingOverrides: metaOverridesForProvider(applyFixtureProvider()),
Ui: ui, Ui: ui,
}, },
} }

View File

@ -1,5 +1,5 @@
variable "foo" {} variable "foo" {}
resource "test_instance" "foo" { resource "test_instance" "foo" {
value = "${var.foo}" value = var.foo
} }