2014-05-23 01:56:28 +02:00
|
|
|
package config
|
|
|
|
|
2014-05-24 20:41:19 +02:00
|
|
|
import (
|
2014-07-03 06:00:06 +02:00
|
|
|
"path/filepath"
|
2014-05-24 20:41:19 +02:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2014-05-23 01:56:28 +02:00
|
|
|
// This is the directory where our test fixtures are.
|
|
|
|
const fixtureDir = "./test-fixtures"
|
2014-05-24 20:41:19 +02:00
|
|
|
|
2014-07-03 06:00:06 +02:00
|
|
|
func TestConfigValidate(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-good")
|
|
|
|
if err := c.Validate(); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-03 06:06:26 +02:00
|
|
|
func TestConfigValidate_unknownResourceVar(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-unknown-resource-var")
|
|
|
|
if err := c.Validate(); err == nil {
|
|
|
|
t.Fatal("should not be valid")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-03 06:00:06 +02:00
|
|
|
func TestConfigValidate_unknownVar(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-unknownvar")
|
|
|
|
if err := c.Validate(); err == nil {
|
|
|
|
t.Fatal("should not be valid")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:41:19 +02:00
|
|
|
func TestNewResourceVariable(t *testing.T) {
|
|
|
|
v, err := NewResourceVariable("foo.bar.baz")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if v.Type != "foo" {
|
|
|
|
t.Fatalf("bad: %#v", v)
|
|
|
|
}
|
|
|
|
if v.Name != "bar" {
|
|
|
|
t.Fatalf("bad: %#v", v)
|
|
|
|
}
|
|
|
|
if v.Field != "baz" {
|
|
|
|
t.Fatalf("bad: %#v", v)
|
|
|
|
}
|
|
|
|
|
|
|
|
if v.FullKey() != "foo.bar.baz" {
|
|
|
|
t.Fatalf("bad: %#v", v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewUserVariable(t *testing.T) {
|
|
|
|
v, err := NewUserVariable("var.bar")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if v.Name != "bar" {
|
|
|
|
t.Fatalf("bad: %#v", v.Name)
|
|
|
|
}
|
|
|
|
if v.FullKey() != "var.bar" {
|
|
|
|
t.Fatalf("bad: %#v", v)
|
|
|
|
}
|
|
|
|
}
|
2014-05-24 22:57:51 +02:00
|
|
|
|
2014-06-24 22:29:07 +02:00
|
|
|
func TestProviderConfigName(t *testing.T) {
|
2014-06-05 21:21:05 +02:00
|
|
|
pcs := map[string]*ProviderConfig{
|
|
|
|
"aw": new(ProviderConfig),
|
|
|
|
"aws": new(ProviderConfig),
|
|
|
|
"a": new(ProviderConfig),
|
|
|
|
"gce_": new(ProviderConfig),
|
|
|
|
}
|
|
|
|
|
2014-06-24 22:29:07 +02:00
|
|
|
n := ProviderConfigName("aws_instance", pcs)
|
2014-06-05 21:21:05 +02:00
|
|
|
if n != "aws" {
|
|
|
|
t.Fatalf("bad: %s", n)
|
|
|
|
}
|
|
|
|
}
|
2014-07-03 06:00:06 +02:00
|
|
|
|
|
|
|
func testConfig(t *testing.T, name string) *Config {
|
|
|
|
c, err := Load(filepath.Join(fixtureDir, name, "main.tf"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return c
|
|
|
|
}
|