2014-07-20 01:39:40 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2017-08-31 20:47:10 +02:00
|
|
|
"fmt"
|
2014-07-20 01:39:40 +02:00
|
|
|
"reflect"
|
|
|
|
"testing"
|
2017-08-31 20:47:10 +02:00
|
|
|
|
|
|
|
"github.com/davecgh/go-spew/spew"
|
2014-07-20 01:39:40 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAppend(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
c1, c2, result *Config
|
|
|
|
err bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
&Config{
|
2015-03-05 21:56:31 +01:00
|
|
|
Atlas: &AtlasConfig{
|
|
|
|
Name: "foo",
|
|
|
|
},
|
2014-09-12 04:50:41 +02:00
|
|
|
Modules: []*Module{
|
|
|
|
&Module{Name: "foo"},
|
|
|
|
},
|
2014-07-20 01:39:40 +02:00
|
|
|
Outputs: []*Output{
|
|
|
|
&Output{Name: "foo"},
|
|
|
|
},
|
|
|
|
ProviderConfigs: []*ProviderConfig{
|
|
|
|
&ProviderConfig{Name: "foo"},
|
|
|
|
},
|
|
|
|
Resources: []*Resource{
|
|
|
|
&Resource{Name: "foo"},
|
|
|
|
},
|
|
|
|
Variables: []*Variable{
|
|
|
|
&Variable{Name: "foo"},
|
|
|
|
},
|
2017-08-31 20:47:10 +02:00
|
|
|
Locals: []*Local{
|
|
|
|
&Local{Name: "foo"},
|
|
|
|
},
|
2014-07-20 01:39:40 +02:00
|
|
|
|
|
|
|
unknownKeys: []string{"foo"},
|
|
|
|
},
|
|
|
|
|
|
|
|
&Config{
|
2015-03-05 21:56:31 +01:00
|
|
|
Atlas: &AtlasConfig{
|
|
|
|
Name: "bar",
|
|
|
|
},
|
2014-09-12 04:50:41 +02:00
|
|
|
Modules: []*Module{
|
|
|
|
&Module{Name: "bar"},
|
|
|
|
},
|
2014-07-20 01:39:40 +02:00
|
|
|
Outputs: []*Output{
|
|
|
|
&Output{Name: "bar"},
|
|
|
|
},
|
|
|
|
ProviderConfigs: []*ProviderConfig{
|
|
|
|
&ProviderConfig{Name: "bar"},
|
|
|
|
},
|
|
|
|
Resources: []*Resource{
|
|
|
|
&Resource{Name: "bar"},
|
|
|
|
},
|
|
|
|
Variables: []*Variable{
|
|
|
|
&Variable{Name: "bar"},
|
|
|
|
},
|
2017-08-31 20:47:10 +02:00
|
|
|
Locals: []*Local{
|
|
|
|
&Local{Name: "bar"},
|
|
|
|
},
|
2014-07-20 01:39:40 +02:00
|
|
|
|
|
|
|
unknownKeys: []string{"bar"},
|
|
|
|
},
|
|
|
|
|
|
|
|
&Config{
|
2015-03-05 21:56:31 +01:00
|
|
|
Atlas: &AtlasConfig{
|
|
|
|
Name: "bar",
|
|
|
|
},
|
2014-09-12 04:50:41 +02:00
|
|
|
Modules: []*Module{
|
|
|
|
&Module{Name: "foo"},
|
|
|
|
&Module{Name: "bar"},
|
|
|
|
},
|
2014-07-20 01:39:40 +02:00
|
|
|
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"},
|
|
|
|
},
|
2017-08-31 20:47:10 +02:00
|
|
|
Locals: []*Local{
|
|
|
|
&Local{Name: "foo"},
|
|
|
|
&Local{Name: "bar"},
|
|
|
|
},
|
2014-07-20 01:39:40 +02:00
|
|
|
|
|
|
|
unknownKeys: []string{"foo", "bar"},
|
|
|
|
},
|
|
|
|
|
|
|
|
false,
|
|
|
|
},
|
2016-12-14 06:53:02 +01:00
|
|
|
|
|
|
|
// Terraform block
|
|
|
|
{
|
|
|
|
&Config{
|
|
|
|
Terraform: &Terraform{
|
|
|
|
RequiredVersion: "A",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&Config{},
|
|
|
|
&Config{
|
|
|
|
Terraform: &Terraform{
|
|
|
|
RequiredVersion: "A",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
&Config{},
|
|
|
|
&Config{
|
|
|
|
Terraform: &Terraform{
|
|
|
|
RequiredVersion: "A",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&Config{
|
|
|
|
Terraform: &Terraform{
|
|
|
|
RequiredVersion: "A",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2017-03-21 20:43:55 +01:00
|
|
|
|
2017-03-22 14:01:54 +01:00
|
|
|
// appending configs merges terraform blocks
|
2017-03-21 20:43:55 +01:00
|
|
|
{
|
|
|
|
&Config{
|
|
|
|
Terraform: &Terraform{
|
|
|
|
RequiredVersion: "A",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&Config{
|
|
|
|
Terraform: &Terraform{
|
|
|
|
Backend: &Backend{
|
|
|
|
Type: "test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&Config{
|
|
|
|
Terraform: &Terraform{
|
|
|
|
RequiredVersion: "A",
|
|
|
|
Backend: &Backend{
|
|
|
|
Type: "test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2014-07-20 01:39:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, tc := range cases {
|
2017-08-31 20:47:10 +02:00
|
|
|
t.Run(fmt.Sprintf("%02d", i), func(t *testing.T) {
|
|
|
|
actual, err := Append(tc.c1, tc.c2)
|
|
|
|
if err != nil != tc.err {
|
|
|
|
t.Errorf("unexpected error: %s", err)
|
|
|
|
}
|
2014-07-20 01:39:40 +02:00
|
|
|
|
2017-08-31 20:47:10 +02:00
|
|
|
if !reflect.DeepEqual(actual, tc.result) {
|
|
|
|
t.Errorf("wrong result\ngot: %swant: %s", spew.Sdump(actual), spew.Sdump(tc.result))
|
|
|
|
}
|
|
|
|
})
|
2014-07-20 01:39:40 +02:00
|
|
|
}
|
|
|
|
}
|