github.com/sl1pm4t/terraform@v0.6.4-0.20170725213156-870617d22df3/config_test.go (about) 1 package main 2 3 import ( 4 "os" 5 "path/filepath" 6 "reflect" 7 "testing" 8 ) 9 10 // This is the directory where our test fixtures are. 11 const fixtureDir = "./test-fixtures" 12 13 func TestLoadConfig(t *testing.T) { 14 c, err := LoadConfig(filepath.Join(fixtureDir, "config")) 15 if err != nil { 16 t.Fatalf("err: %s", err) 17 } 18 19 expected := &Config{ 20 Providers: map[string]string{ 21 "aws": "foo", 22 "do": "bar", 23 }, 24 } 25 26 if !reflect.DeepEqual(c, expected) { 27 t.Fatalf("bad: %#v", c) 28 } 29 } 30 31 func TestLoadConfig_env(t *testing.T) { 32 defer os.Unsetenv("TFTEST") 33 os.Setenv("TFTEST", "hello") 34 35 c, err := LoadConfig(filepath.Join(fixtureDir, "config-env")) 36 if err != nil { 37 t.Fatalf("err: %s", err) 38 } 39 40 expected := &Config{ 41 Providers: map[string]string{ 42 "aws": "hello", 43 "google": "bar", 44 }, 45 Provisioners: map[string]string{ 46 "local": "hello", 47 }, 48 } 49 50 if !reflect.DeepEqual(c, expected) { 51 t.Fatalf("bad: %#v", c) 52 } 53 } 54 55 func TestConfig_Merge(t *testing.T) { 56 c1 := &Config{ 57 Providers: map[string]string{ 58 "foo": "bar", 59 "bar": "blah", 60 }, 61 Provisioners: map[string]string{ 62 "local": "local", 63 "remote": "bad", 64 }, 65 } 66 67 c2 := &Config{ 68 Providers: map[string]string{ 69 "bar": "baz", 70 "baz": "what", 71 }, 72 Provisioners: map[string]string{ 73 "remote": "remote", 74 }, 75 } 76 77 expected := &Config{ 78 Providers: map[string]string{ 79 "foo": "bar", 80 "bar": "baz", 81 "baz": "what", 82 }, 83 Provisioners: map[string]string{ 84 "local": "local", 85 "remote": "remote", 86 }, 87 } 88 89 actual := c1.Merge(c2) 90 if !reflect.DeepEqual(actual, expected) { 91 t.Fatalf("bad: %#v", actual) 92 } 93 } 94 95 func TestConfig_Merge_disableCheckpoint(t *testing.T) { 96 c1 := &Config{ 97 DisableCheckpoint: true, 98 } 99 100 c2 := &Config{} 101 102 expected := &Config{ 103 Providers: map[string]string{}, 104 Provisioners: map[string]string{}, 105 DisableCheckpoint: true, 106 } 107 108 actual := c1.Merge(c2) 109 if !reflect.DeepEqual(actual, expected) { 110 t.Fatalf("bad: %#v", actual) 111 } 112 } 113 114 func TestConfig_Merge_disableCheckpointSignature(t *testing.T) { 115 c1 := &Config{ 116 DisableCheckpointSignature: true, 117 } 118 119 c2 := &Config{} 120 121 expected := &Config{ 122 Providers: map[string]string{}, 123 Provisioners: map[string]string{}, 124 DisableCheckpointSignature: true, 125 } 126 127 actual := c1.Merge(c2) 128 if !reflect.DeepEqual(actual, expected) { 129 t.Fatalf("bad: %#v", actual) 130 } 131 }