command: tests pass

This commit is contained in:
Mitchell Hashimoto 2014-09-24 15:48:46 -07:00
parent 718fb42f4b
commit a36b3e1ec5
7 changed files with 53 additions and 15 deletions

View File

@ -11,7 +11,6 @@ import (
"testing"
"time"
"github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/terraform"
"github.com/mitchellh/cli"
)
@ -246,7 +245,7 @@ func TestApply_noArgs(t *testing.T) {
func TestApply_plan(t *testing.T) {
planPath := testPlanFile(t, &terraform.Plan{
Config: new(config.Config),
Module: testModule(t, "apply"),
})
statePath := testTempFile(t)
@ -294,7 +293,7 @@ func TestApply_planWithVarFile(t *testing.T) {
}
planPath := testPlanFile(t, &terraform.Plan{
Config: new(config.Config),
Module: testModule(t, "apply"),
})
statePath := testTempFile(t)
@ -345,7 +344,7 @@ func TestApply_planWithVarFile(t *testing.T) {
func TestApply_planVars(t *testing.T) {
planPath := testPlanFile(t, &terraform.Plan{
Config: new(config.Config),
Module: testModule(t, "apply"),
})
statePath := testTempFile(t)

View File

@ -6,6 +6,7 @@ import (
"path/filepath"
"testing"
"github.com/hashicorp/terraform/config/module"
"github.com/hashicorp/terraform/terraform"
)
@ -22,6 +23,18 @@ func init() {
}
}
func tempDir(t *testing.T) string {
dir, err := ioutil.TempDir("", "tf")
if err != nil {
t.Fatalf("err: %s", err)
}
if err := os.RemoveAll(dir); err != nil {
t.Fatalf("err: %s", err)
}
return dir
}
func testFixturePath(name string) string {
return filepath.Join(fixtureDir, name)
}
@ -36,6 +49,20 @@ func testCtxConfig(p terraform.ResourceProvider) *terraform.ContextOpts {
}
}
func testModule(t *testing.T, name string) *module.Tree {
mod, err := module.NewTreeModule("", filepath.Join(fixtureDir, name))
if err != nil {
t.Fatalf("err: %s", err)
}
s := &module.FolderStorage{StorageDir: tempDir(t)}
if err := mod.Load(s, module.GetModeGet); err != nil {
t.Fatalf("err: %s", err)
}
return mod
}
func testPlanFile(t *testing.T, plan *terraform.Plan) string {
path := testTempFile(t)

View File

@ -5,7 +5,6 @@ import (
"strings"
"testing"
"github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/terraform"
"github.com/mitchellh/cli"
)
@ -81,7 +80,7 @@ func TestGraph_noArgs(t *testing.T) {
func TestGraph_plan(t *testing.T) {
planPath := testPlanFile(t, &terraform.Plan{
Config: new(config.Config),
Module: testModule(t, "graph"),
})
ui := new(cli.MockUi)

View File

@ -3,7 +3,7 @@ package command
import (
"testing"
"github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/config/module"
"github.com/hashicorp/terraform/terraform"
"github.com/mitchellh/cli"
)
@ -43,7 +43,7 @@ func TestShow_noArgs(t *testing.T) {
func TestShow_plan(t *testing.T) {
planPath := testPlanFile(t, &terraform.Plan{
Config: new(config.Config),
Module: new(module.Tree),
})
ui := new(cli.MockUi)

View File

@ -120,6 +120,10 @@ func (r *Resource) Id() string {
// Validate does some basic semantic checking of the configuration.
func (c *Config) Validate() error {
if c == nil {
return nil
}
var errs []error
for _, k := range c.unknownKeys {

View File

@ -58,6 +58,13 @@ func TestConfigValidate_dupResource(t *testing.T) {
}
}
func TestConfigValidate_nil(t *testing.T) {
var c Config
if err := c.Validate(); err != nil {
t.Fatalf("err: %s", err)
}
}
func TestConfigValidate_outputBadField(t *testing.T) {
c := testConfig(t, "validate-output-bad-field")
if err := c.Validate(); err == nil {

View File

@ -215,14 +215,16 @@ func (c *Context) Stop() {
func (c *Context) Validate() ([]string, []error) {
var rerr *multierror.Error
// Validate the configuration itself
if err := c.module.Config().Validate(); err != nil {
rerr = multierror.ErrorAppend(rerr, err)
}
if config := c.module.Config(); config != nil {
// Validate the configuration itself
if err := config.Validate(); err != nil {
rerr = multierror.ErrorAppend(rerr, err)
}
// Validate the user variables
if errs := smcUserVariables(c.module.Config(), c.variables); len(errs) > 0 {
rerr = multierror.ErrorAppend(rerr, errs...)
// Validate the user variables
if errs := smcUserVariables(config, c.variables); len(errs) > 0 {
rerr = multierror.ErrorAppend(rerr, errs...)
}
}
// Validate the graph