2014-07-20 19:17:03 -05:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMerge(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
c1, c2, result *Config
|
|
|
|
err bool
|
|
|
|
}{
|
|
|
|
// Normal good case.
|
|
|
|
{
|
|
|
|
&Config{
|
|
|
|
Outputs: []*Output{
|
|
|
|
&Output{Name: "foo"},
|
|
|
|
},
|
|
|
|
ProviderConfigs: []*ProviderConfig{
|
|
|
|
&ProviderConfig{Name: "foo"},
|
|
|
|
},
|
|
|
|
Resources: []*Resource{
|
|
|
|
&Resource{Name: "foo"},
|
|
|
|
},
|
|
|
|
Variables: []*Variable{
|
|
|
|
&Variable{Name: "foo"},
|
|
|
|
},
|
|
|
|
|
|
|
|
unknownKeys: []string{"foo"},
|
|
|
|
},
|
|
|
|
|
|
|
|
&Config{
|
|
|
|
Outputs: []*Output{
|
|
|
|
&Output{Name: "bar"},
|
|
|
|
},
|
|
|
|
ProviderConfigs: []*ProviderConfig{
|
|
|
|
&ProviderConfig{Name: "bar"},
|
|
|
|
},
|
|
|
|
Resources: []*Resource{
|
|
|
|
&Resource{Name: "bar"},
|
|
|
|
},
|
|
|
|
Variables: []*Variable{
|
|
|
|
&Variable{Name: "bar"},
|
|
|
|
},
|
|
|
|
|
|
|
|
unknownKeys: []string{"bar"},
|
|
|
|
},
|
|
|
|
|
|
|
|
&Config{
|
|
|
|
Outputs: []*Output{
|
|
|
|
&Output{Name: "foo"},
|
|
|
|
&Output{Name: "bar"},
|
|
|
|
},
|
|
|
|
ProviderConfigs: []*ProviderConfig{
|
|
|
|
&ProviderConfig{Name: "foo"},
|
|
|
|
&ProviderConfig{Name: "bar"},
|
|
|
|
},
|
|
|
|
Resources: []*Resource{
|
|
|
|
&Resource{Name: "foo"},
|
|
|
|
&Resource{Name: "bar"},
|
|
|
|
},
|
|
|
|
Variables: []*Variable{
|
|
|
|
&Variable{Name: "foo"},
|
|
|
|
&Variable{Name: "bar"},
|
|
|
|
},
|
|
|
|
|
|
|
|
unknownKeys: []string{"foo", "bar"},
|
|
|
|
},
|
|
|
|
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
|
|
|
|
// Test that when merging duplicates, it merges into the
|
|
|
|
// first, but keeps the duplicates so that errors still
|
|
|
|
// happen.
|
|
|
|
{
|
|
|
|
&Config{
|
|
|
|
Outputs: []*Output{
|
|
|
|
&Output{Name: "foo"},
|
|
|
|
},
|
|
|
|
ProviderConfigs: []*ProviderConfig{
|
|
|
|
&ProviderConfig{Name: "foo"},
|
|
|
|
},
|
|
|
|
Resources: []*Resource{
|
|
|
|
&Resource{Name: "foo"},
|
|
|
|
},
|
|
|
|
Variables: []*Variable{
|
|
|
|
&Variable{Name: "foo", Default: "foo"},
|
|
|
|
&Variable{Name: "foo"},
|
|
|
|
},
|
|
|
|
|
|
|
|
unknownKeys: []string{"foo"},
|
|
|
|
},
|
|
|
|
|
|
|
|
&Config{
|
|
|
|
Outputs: []*Output{
|
|
|
|
&Output{Name: "bar"},
|
|
|
|
},
|
|
|
|
ProviderConfigs: []*ProviderConfig{
|
|
|
|
&ProviderConfig{Name: "bar"},
|
|
|
|
},
|
|
|
|
Resources: []*Resource{
|
|
|
|
&Resource{Name: "bar"},
|
|
|
|
},
|
|
|
|
Variables: []*Variable{
|
2014-07-21 09:32:36 -05:00
|
|
|
&Variable{Name: "foo", Default: "bar"},
|
2014-07-20 19:17:03 -05:00
|
|
|
&Variable{Name: "bar"},
|
|
|
|
},
|
|
|
|
|
|
|
|
unknownKeys: []string{"bar"},
|
|
|
|
},
|
|
|
|
|
|
|
|
&Config{
|
|
|
|
Outputs: []*Output{
|
|
|
|
&Output{Name: "foo"},
|
|
|
|
&Output{Name: "bar"},
|
|
|
|
},
|
|
|
|
ProviderConfigs: []*ProviderConfig{
|
|
|
|
&ProviderConfig{Name: "foo"},
|
|
|
|
&ProviderConfig{Name: "bar"},
|
|
|
|
},
|
|
|
|
Resources: []*Resource{
|
|
|
|
&Resource{Name: "foo"},
|
|
|
|
&Resource{Name: "bar"},
|
|
|
|
},
|
|
|
|
Variables: []*Variable{
|
2014-07-21 09:32:36 -05:00
|
|
|
&Variable{Name: "foo", Default: "bar"},
|
2014-07-20 19:17:03 -05:00
|
|
|
&Variable{Name: "foo"},
|
|
|
|
&Variable{Name: "bar"},
|
|
|
|
},
|
|
|
|
|
|
|
|
unknownKeys: []string{"foo", "bar"},
|
|
|
|
},
|
|
|
|
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tc := range cases {
|
|
|
|
actual, err := Merge(tc.c1, tc.c2)
|
|
|
|
if (err != nil) != tc.err {
|
|
|
|
t.Fatalf("%d: error fail", i)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(actual, tc.result) {
|
|
|
|
t.Fatalf("%d: bad:\n\n%#v", i, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|