mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 18:01:01 -06:00
d2001275dc
This is REALLY heavy and would be really hard to maintain any sort of compatibility with, but it is what we're going to do during dev initially (if we don't ship with it) in order to just get stuff working.
128 lines
2.4 KiB
Go
128 lines
2.4 KiB
Go
package config
|
|
|
|
import (
|
|
"encoding/gob"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestNewRawConfig(t *testing.T) {
|
|
raw := map[string]interface{}{
|
|
"foo": "${var.bar}",
|
|
}
|
|
|
|
rc, err := NewRawConfig(raw)
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
if len(rc.Variables) != 1 {
|
|
t.Fatalf("bad: %#v", rc.Variables)
|
|
}
|
|
}
|
|
|
|
func TestRawConfig(t *testing.T) {
|
|
raw := map[string]interface{}{
|
|
"foo": "${var.bar}",
|
|
}
|
|
|
|
rc, err := NewRawConfig(raw)
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
// Before interpolate, Config() should be the raw
|
|
if !reflect.DeepEqual(rc.Config(), raw) {
|
|
t.Fatalf("bad: %#v", rc.Config())
|
|
}
|
|
|
|
vars := map[string]string{"var.bar": "baz"}
|
|
if err := rc.Interpolate(vars); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
actual := rc.Config()
|
|
expected := map[string]interface{}{
|
|
"foo": "baz",
|
|
}
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
t.Fatalf("bad: %#v", actual)
|
|
}
|
|
if len(rc.UnknownKeys()) != 0 {
|
|
t.Fatalf("bad: %#v", rc.UnknownKeys())
|
|
}
|
|
}
|
|
|
|
func TestRawConfig_double(t *testing.T) {
|
|
raw := map[string]interface{}{
|
|
"foo": "${var.bar}",
|
|
}
|
|
|
|
rc, err := NewRawConfig(raw)
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
vars := map[string]string{"var.bar": "baz"}
|
|
if err := rc.Interpolate(vars); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
actual := rc.Config()
|
|
expected := map[string]interface{}{
|
|
"foo": "baz",
|
|
}
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
t.Fatalf("bad: %#v", actual)
|
|
}
|
|
|
|
vars = map[string]string{"var.bar": "what"}
|
|
if err := rc.Interpolate(vars); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
actual = rc.Config()
|
|
expected = map[string]interface{}{
|
|
"foo": "what",
|
|
}
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
t.Fatalf("bad: %#v", actual)
|
|
}
|
|
}
|
|
|
|
func TestRawConfig_unknown(t *testing.T) {
|
|
raw := map[string]interface{}{
|
|
"foo": "${var.bar}",
|
|
}
|
|
|
|
rc, err := NewRawConfig(raw)
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
vars := map[string]string{"var.bar": UnknownVariableValue}
|
|
if err := rc.Interpolate(vars); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
actual := rc.Config()
|
|
expected := map[string]interface{}{}
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
t.Fatalf("bad: %#v", actual)
|
|
}
|
|
|
|
expectedKeys := []string{"foo"}
|
|
if !reflect.DeepEqual(rc.UnknownKeys(), expectedKeys) {
|
|
t.Fatalf("bad: %#v", rc.UnknownKeys())
|
|
}
|
|
}
|
|
|
|
func TestRawConfig_implGob(t *testing.T) {
|
|
var _ gob.GobDecoder = new(RawConfig)
|
|
var _ gob.GobEncoder = new(RawConfig)
|
|
}
|