mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 18:01:01 -06:00
41a4235eb3
This allows the use case where installation of a plugin can simply say to add `$GOPATH/bin/foo` to your terraformrc and the user can do that verbatim. Additionally terraformrc files become portable for certain environments which are self-contained. I was hesitant at first about this because it diverges the syntax a bit from our standard interpolation syntax. However, due to the special nature of terraformrc and the strong use cases cited I'm okay with this.
132 lines
2.3 KiB
Go
132 lines
2.3 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
// This is the directory where our test fixtures are.
|
|
const fixtureDir = "./test-fixtures"
|
|
|
|
func TestLoadConfig(t *testing.T) {
|
|
c, err := LoadConfig(filepath.Join(fixtureDir, "config"))
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
expected := &Config{
|
|
Providers: map[string]string{
|
|
"aws": "foo",
|
|
"do": "bar",
|
|
},
|
|
}
|
|
|
|
if !reflect.DeepEqual(c, expected) {
|
|
t.Fatalf("bad: %#v", c)
|
|
}
|
|
}
|
|
|
|
func TestLoadConfig_env(t *testing.T) {
|
|
defer os.Unsetenv("TFTEST")
|
|
os.Setenv("TFTEST", "hello")
|
|
|
|
c, err := LoadConfig(filepath.Join(fixtureDir, "config-env"))
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
expected := &Config{
|
|
Providers: map[string]string{
|
|
"aws": "hello",
|
|
"google": "bar",
|
|
},
|
|
Provisioners: map[string]string{
|
|
"local": "hello",
|
|
},
|
|
}
|
|
|
|
if !reflect.DeepEqual(c, expected) {
|
|
t.Fatalf("bad: %#v", c)
|
|
}
|
|
}
|
|
|
|
func TestConfig_Merge(t *testing.T) {
|
|
c1 := &Config{
|
|
Providers: map[string]string{
|
|
"foo": "bar",
|
|
"bar": "blah",
|
|
},
|
|
Provisioners: map[string]string{
|
|
"local": "local",
|
|
"remote": "bad",
|
|
},
|
|
}
|
|
|
|
c2 := &Config{
|
|
Providers: map[string]string{
|
|
"bar": "baz",
|
|
"baz": "what",
|
|
},
|
|
Provisioners: map[string]string{
|
|
"remote": "remote",
|
|
},
|
|
}
|
|
|
|
expected := &Config{
|
|
Providers: map[string]string{
|
|
"foo": "bar",
|
|
"bar": "baz",
|
|
"baz": "what",
|
|
},
|
|
Provisioners: map[string]string{
|
|
"local": "local",
|
|
"remote": "remote",
|
|
},
|
|
}
|
|
|
|
actual := c1.Merge(c2)
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
t.Fatalf("bad: %#v", actual)
|
|
}
|
|
}
|
|
|
|
func TestConfig_Merge_disableCheckpoint(t *testing.T) {
|
|
c1 := &Config{
|
|
DisableCheckpoint: true,
|
|
}
|
|
|
|
c2 := &Config{}
|
|
|
|
expected := &Config{
|
|
Providers: map[string]string{},
|
|
Provisioners: map[string]string{},
|
|
DisableCheckpoint: true,
|
|
}
|
|
|
|
actual := c1.Merge(c2)
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
t.Fatalf("bad: %#v", actual)
|
|
}
|
|
}
|
|
|
|
func TestConfig_Merge_disableCheckpointSignature(t *testing.T) {
|
|
c1 := &Config{
|
|
DisableCheckpointSignature: true,
|
|
}
|
|
|
|
c2 := &Config{}
|
|
|
|
expected := &Config{
|
|
Providers: map[string]string{},
|
|
Provisioners: map[string]string{},
|
|
DisableCheckpointSignature: true,
|
|
}
|
|
|
|
actual := c1.Merge(c2)
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
t.Fatalf("bad: %#v", actual)
|
|
}
|
|
}
|