config: TODO tests for validation

This commit is contained in:
Mitchell Hashimoto 2014-07-21 08:34:44 -07:00
parent b0ce89b805
commit b8a0a02217
5 changed files with 37 additions and 2 deletions

View File

@ -131,6 +131,9 @@ func (c *Config) Validate() error {
varMap[v.Name] = v varMap[v.Name] = v
} }
// TODO(mitchellh): Validate that variable defaults are only a string
// or mapping of strings.
// Check for references to user variables that do not actually // Check for references to user variables that do not actually
// exist and record those errors. // exist and record those errors.
for source, vs := range vars { for source, vs := range vars {

View File

@ -64,6 +64,24 @@ func TestConfigValidate_unknownVar(t *testing.T) {
} }
} }
func TestConfigValidate_varDefault(t *testing.T) {
c := testConfig(t, "validate-var-default")
if err := c.Validate(); err != nil {
t.Fatalf("should be valid: %s", err)
}
}
func TestConfigValidate_varDefaultBadType(t *testing.T) {
t.Skip()
// TODO(mitchellh): FIX
c := testConfig(t, "validate-var-default-bad-type")
if err := c.Validate(); err == nil {
t.Fatal("should not be valid")
}
}
func TestNewResourceVariable(t *testing.T) { func TestNewResourceVariable(t *testing.T) {
v, err := NewResourceVariable("foo.bar.baz") v, err := NewResourceVariable("foo.bar.baz")
if err != nil { if err != nil {

View File

@ -51,11 +51,13 @@ func (t *libuclConfigurable) Config() (*Config, error) {
if len(rawConfig.Variable) > 0 { if len(rawConfig.Variable) > 0 {
config.Variables = make([]*Variable, 0, len(rawConfig.Variable)) config.Variables = make([]*Variable, 0, len(rawConfig.Variable))
for k, v := range rawConfig.Variable { for k, v := range rawConfig.Variable {
config.Variables = append(config.Variables, &Variable{ newVar := &Variable{
Name: k, Name: k,
Default: v.Default, Default: v.Default,
Description: v.Description, Description: v.Description,
}) }
config.Variables = append(config.Variables, newVar)
} }
} }

View File

@ -0,0 +1,3 @@
variable "foo" {
default = ["foo", "bar"]
}

View File

@ -0,0 +1,9 @@
variable "foo" {
default = "bar"
}
variable "foo" {
default = {
"foo" = "bar"
}
}