github.com/mikesimons/terraform@v0.6.13-0.20160304043642-f11448c69214/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  				Atlas: &AtlasConfig{
    16  					Name: "foo",
    17  				},
    18  				Modules: []*Module{
    19  					&Module{Name: "foo"},
    20  				},
    21  				Outputs: []*Output{
    22  					&Output{Name: "foo"},
    23  				},
    24  				ProviderConfigs: []*ProviderConfig{
    25  					&ProviderConfig{Name: "foo"},
    26  				},
    27  				Resources: []*Resource{
    28  					&Resource{Name: "foo"},
    29  				},
    30  				Variables: []*Variable{
    31  					&Variable{Name: "foo"},
    32  				},
    33  
    34  				unknownKeys: []string{"foo"},
    35  			},
    36  
    37  			&Config{
    38  				Atlas: &AtlasConfig{
    39  					Name: "bar",
    40  				},
    41  				Modules: []*Module{
    42  					&Module{Name: "bar"},
    43  				},
    44  				Outputs: []*Output{
    45  					&Output{Name: "bar"},
    46  				},
    47  				ProviderConfigs: []*ProviderConfig{
    48  					&ProviderConfig{Name: "bar"},
    49  				},
    50  				Resources: []*Resource{
    51  					&Resource{Name: "bar"},
    52  				},
    53  				Variables: []*Variable{
    54  					&Variable{Name: "bar"},
    55  				},
    56  
    57  				unknownKeys: []string{"bar"},
    58  			},
    59  
    60  			&Config{
    61  				Atlas: &AtlasConfig{
    62  					Name: "bar",
    63  				},
    64  				Modules: []*Module{
    65  					&Module{Name: "foo"},
    66  					&Module{Name: "bar"},
    67  				},
    68  				Outputs: []*Output{
    69  					&Output{Name: "foo"},
    70  					&Output{Name: "bar"},
    71  				},
    72  				ProviderConfigs: []*ProviderConfig{
    73  					&ProviderConfig{Name: "foo"},
    74  					&ProviderConfig{Name: "bar"},
    75  				},
    76  				Resources: []*Resource{
    77  					&Resource{Name: "foo"},
    78  					&Resource{Name: "bar"},
    79  				},
    80  				Variables: []*Variable{
    81  					&Variable{Name: "foo"},
    82  					&Variable{Name: "bar"},
    83  				},
    84  
    85  				unknownKeys: []string{"foo", "bar"},
    86  			},
    87  
    88  			false,
    89  		},
    90  	}
    91  
    92  	for i, tc := range cases {
    93  		actual, err := Append(tc.c1, tc.c2)
    94  		if err != nil != tc.err {
    95  			t.Fatalf("%d: error fail", i)
    96  		}
    97  
    98  		if !reflect.DeepEqual(actual, tc.result) {
    99  			t.Fatalf("%d: bad:\n\n%#v", i, actual)
   100  		}
   101  	}
   102  }