terraform: tests passing for Config change

This commit is contained in:
Mitchell Hashimoto 2014-07-18 22:13:15 -07:00
parent e4bcd3c448
commit a19e2983de
4 changed files with 40 additions and 34 deletions

View File

@ -48,22 +48,24 @@ func (t *libuclConfigurable) Config() (*Config, error) {
// TODO(mitchellh): Make function like loadVariablesLibucl so that
// duplicates aren't overriden
config := new(Config)
config.Variables = make([]*Variable, 0, len(rawConfig.Variable))
for k, v := range rawConfig.Variable {
defaultSet := false
for _, f := range v.Fields {
if f == "Default" {
defaultSet = true
break
if len(rawConfig.Variable) > 0 {
config.Variables = make([]*Variable, 0, len(rawConfig.Variable))
for k, v := range rawConfig.Variable {
defaultSet := false
for _, f := range v.Fields {
if f == "Default" {
defaultSet = true
break
}
}
}
config.Variables = append(config.Variables, &Variable{
Name: k,
Default: v.Default,
Description: v.Description,
defaultSet: defaultSet,
})
config.Variables = append(config.Variables, &Variable{
Name: k,
Default: v.Default,
Description: v.Description,
defaultSet: defaultSet,
})
}
}
// Build the provider configs

View File

@ -26,26 +26,28 @@ func Merge(c1, c2 *Config) (*Config, error) {
// Merge variables: Variable merging is quite simple. Set fields in
// later set variables override those earlier.
c.Variables = make([]*Variable, 0, len(c1.Variables)+len(c2.Variables))
varMap := make(map[string]*Variable)
for _, v := range c1.Variables {
varMap[v.Name] = v
}
for _, v2 := range c2.Variables {
v1, ok := varMap[v2.Name]
if ok {
if v2.Default == "" {
v2.Default = v1.Default
}
if v2.Description == "" {
v2.Description = v1.Description
}
if len(c1.Variables) > 0 || len(c2.Variables) > 0 {
c.Variables = make([]*Variable, 0, len(c1.Variables)+len(c2.Variables))
varMap := make(map[string]*Variable)
for _, v := range c1.Variables {
varMap[v.Name] = v
}
for _, v2 := range c2.Variables {
v1, ok := varMap[v2.Name]
if ok {
if v2.Default == "" {
v2.Default = v1.Default
}
if v2.Description == "" {
v2.Description = v1.Description
}
}
varMap[v2.Name] = v2
}
for _, v := range varMap {
c.Variables = append(c.Variables, v)
varMap[v2.Name] = v2
}
for _, v := range varMap {
c.Variables = append(c.Variables, v)
}
}
// Merge outputs: If they collide, just take the latest one for now. In

View File

@ -53,6 +53,8 @@ func TestReadWritePlan(t *testing.T) {
t.Fatalf("err: %s", err)
}
println(reflect.DeepEqual(actual.Config.Variables, plan.Config.Variables))
if !reflect.DeepEqual(actual, plan) {
t.Fatalf("bad: %#v", actual)
}

View File

@ -13,9 +13,9 @@ func smcUserVariables(c *config.Config, vs map[string]string) []error {
// Check that all required variables are present
required := make(map[string]struct{})
for k, v := range c.Variables {
for _, v := range c.Variables {
if v.Required() {
required[k] = struct{}{}
required[v.Name] = struct{}{}
}
}
for k, _ := range vs {