github.com/chalford/terraform@v0.3.7-0.20150113080010-a78c69a8c81f/config/append_test.go (about) 1 package config 2 3 import ( 4 "reflect" 5 "testing" 6 ) 7 8 func TestAppend(t *testing.T) { 9 cases := []struct { 10 c1, c2, result *Config 11 err bool 12 }{ 13 { 14 &Config{ 15 Modules: []*Module{ 16 &Module{Name: "foo"}, 17 }, 18 Outputs: []*Output{ 19 &Output{Name: "foo"}, 20 }, 21 ProviderConfigs: []*ProviderConfig{ 22 &ProviderConfig{Name: "foo"}, 23 }, 24 Resources: []*Resource{ 25 &Resource{Name: "foo"}, 26 }, 27 Variables: []*Variable{ 28 &Variable{Name: "foo"}, 29 }, 30 31 unknownKeys: []string{"foo"}, 32 }, 33 34 &Config{ 35 Modules: []*Module{ 36 &Module{Name: "bar"}, 37 }, 38 Outputs: []*Output{ 39 &Output{Name: "bar"}, 40 }, 41 ProviderConfigs: []*ProviderConfig{ 42 &ProviderConfig{Name: "bar"}, 43 }, 44 Resources: []*Resource{ 45 &Resource{Name: "bar"}, 46 }, 47 Variables: []*Variable{ 48 &Variable{Name: "bar"}, 49 }, 50 51 unknownKeys: []string{"bar"}, 52 }, 53 54 &Config{ 55 Modules: []*Module{ 56 &Module{Name: "foo"}, 57 &Module{Name: "bar"}, 58 }, 59 Outputs: []*Output{ 60 &Output{Name: "foo"}, 61 &Output{Name: "bar"}, 62 }, 63 ProviderConfigs: []*ProviderConfig{ 64 &ProviderConfig{Name: "foo"}, 65 &ProviderConfig{Name: "bar"}, 66 }, 67 Resources: []*Resource{ 68 &Resource{Name: "foo"}, 69 &Resource{Name: "bar"}, 70 }, 71 Variables: []*Variable{ 72 &Variable{Name: "foo"}, 73 &Variable{Name: "bar"}, 74 }, 75 76 unknownKeys: []string{"foo", "bar"}, 77 }, 78 79 false, 80 }, 81 } 82 83 for i, tc := range cases { 84 actual, err := Append(tc.c1, tc.c2) 85 if (err != nil) != tc.err { 86 t.Fatalf("%d: error fail", i) 87 } 88 89 if !reflect.DeepEqual(actual, tc.result) { 90 t.Fatalf("%d: bad:\n\n%#v", i, actual) 91 } 92 } 93 }