107 lines
2.4 KiB
Go
107 lines
2.4 KiB
Go
package config
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// This is the directory where our test fixtures are.
|
|
const fixtureDir = "./test-fixtures"
|
|
|
|
func TestConfigValidate(t *testing.T) {
|
|
c := testConfig(t, "validate-good")
|
|
if err := c.Validate(); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
}
|
|
|
|
func TestConfigValidate_badMultiResource(t *testing.T) {
|
|
c := testConfig(t, "validate-bad-multi-resource")
|
|
if err := c.Validate(); err == nil {
|
|
t.Fatal("should not be valid")
|
|
}
|
|
}
|
|
|
|
func TestConfigValidate_dupResource(t *testing.T) {
|
|
c := testConfig(t, "validate-dup-resource")
|
|
if err := c.Validate(); err == nil {
|
|
t.Fatal("should not be valid")
|
|
}
|
|
}
|
|
|
|
func TestConfigValidate_outputBadField(t *testing.T) {
|
|
c := testConfig(t, "validate-output-bad-field")
|
|
if err := c.Validate(); err == nil {
|
|
t.Fatal("should not be valid")
|
|
}
|
|
}
|
|
|
|
func TestConfigValidate_unknownThing(t *testing.T) {
|
|
c := testConfig(t, "validate-unknownthing")
|
|
if err := c.Validate(); err == nil {
|
|
t.Fatal("should not be valid")
|
|
}
|
|
}
|
|
|
|
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")
|
|
}
|
|
}
|
|
|
|
func TestConfigValidate_unknownResourceVar_output(t *testing.T) {
|
|
c := testConfig(t, "validate-unknown-resource-var-output")
|
|
if err := c.Validate(); err == nil {
|
|
t.Fatal("should not be valid")
|
|
}
|
|
}
|
|
|
|
func TestConfigValidate_unknownVar(t *testing.T) {
|
|
c := testConfig(t, "validate-unknownvar")
|
|
if err := c.Validate(); err == nil {
|
|
t.Fatal("should not be valid")
|
|
}
|
|
}
|
|
|
|
func TestConfigValidate_varDefault(t *testing.T) {
|
|
c := testConfig(t, "validate-var-default")
|
|
if err := c.Validate(); err != nil {
|
|
t.Fatalf("should be valid: %s", err)
|
|
}
|
|
}
|
|
|
|
func TestConfigValidate_varDefaultBadType(t *testing.T) {
|
|
t.Skip()
|
|
|
|
// TODO(mitchellh): FIX
|
|
|
|
c := testConfig(t, "validate-var-default-bad-type")
|
|
if err := c.Validate(); err == nil {
|
|
t.Fatal("should not be valid")
|
|
}
|
|
}
|
|
|
|
func TestProviderConfigName(t *testing.T) {
|
|
pcs := []*ProviderConfig{
|
|
&ProviderConfig{Name: "aw"},
|
|
&ProviderConfig{Name: "aws"},
|
|
&ProviderConfig{Name: "a"},
|
|
&ProviderConfig{Name: "gce_"},
|
|
}
|
|
|
|
n := ProviderConfigName("aws_instance", pcs)
|
|
if n != "aws" {
|
|
t.Fatalf("bad: %s", n)
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|