github.com/ffrizzo/terraform@v0.8.2-0.20161219200057-992e12335f3d/config_test.go (about)

     1  package main
     2  
     3  import (
     4  	"path/filepath"
     5  	"reflect"
     6  	"testing"
     7  )
     8  
     9  // This is the directory where our test fixtures are.
    10  const fixtureDir = "./test-fixtures"
    11  
    12  func TestLoadConfig(t *testing.T) {
    13  	c, err := LoadConfig(filepath.Join(fixtureDir, "config"))
    14  	if err != nil {
    15  		t.Fatalf("err: %s", err)
    16  	}
    17  
    18  	expected := &Config{
    19  		Providers: map[string]string{
    20  			"aws": "foo",
    21  			"do":  "bar",
    22  		},
    23  	}
    24  
    25  	if !reflect.DeepEqual(c, expected) {
    26  		t.Fatalf("bad: %#v", c)
    27  	}
    28  }
    29  
    30  func TestConfig_Merge(t *testing.T) {
    31  	c1 := &Config{
    32  		Providers: map[string]string{
    33  			"foo": "bar",
    34  			"bar": "blah",
    35  		},
    36  		Provisioners: map[string]string{
    37  			"local":  "local",
    38  			"remote": "bad",
    39  		},
    40  	}
    41  
    42  	c2 := &Config{
    43  		Providers: map[string]string{
    44  			"bar": "baz",
    45  			"baz": "what",
    46  		},
    47  		Provisioners: map[string]string{
    48  			"remote": "remote",
    49  		},
    50  	}
    51  
    52  	expected := &Config{
    53  		Providers: map[string]string{
    54  			"foo": "bar",
    55  			"bar": "baz",
    56  			"baz": "what",
    57  		},
    58  		Provisioners: map[string]string{
    59  			"local":  "local",
    60  			"remote": "remote",
    61  		},
    62  	}
    63  
    64  	actual := c1.Merge(c2)
    65  	if !reflect.DeepEqual(actual, expected) {
    66  		t.Fatalf("bad: %#v", actual)
    67  	}
    68  }
    69  
    70  func TestConfig_Merge_disableCheckpoint(t *testing.T) {
    71  	c1 := &Config{
    72  		DisableCheckpoint: true,
    73  	}
    74  
    75  	c2 := &Config{}
    76  
    77  	expected := &Config{
    78  		Providers:         map[string]string{},
    79  		Provisioners:      map[string]string{},
    80  		DisableCheckpoint: true,
    81  	}
    82  
    83  	actual := c1.Merge(c2)
    84  	if !reflect.DeepEqual(actual, expected) {
    85  		t.Fatalf("bad: %#v", actual)
    86  	}
    87  }
    88  
    89  func TestConfig_Merge_disableCheckpointSignature(t *testing.T) {
    90  	c1 := &Config{
    91  		DisableCheckpointSignature: true,
    92  	}
    93  
    94  	c2 := &Config{}
    95  
    96  	expected := &Config{
    97  		Providers:                  map[string]string{},
    98  		Provisioners:               map[string]string{},
    99  		DisableCheckpointSignature: true,
   100  	}
   101  
   102  	actual := c1.Merge(c2)
   103  	if !reflect.DeepEqual(actual, expected) {
   104  		t.Fatalf("bad: %#v", actual)
   105  	}
   106  }