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"
|
2015-04-15 02:42:23 +02:00
|
|
|
"strings"
|
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
|
|
|
|
2016-02-06 00:40:35 +01:00
|
|
|
func TestConfigCopy(t *testing.T) {
|
|
|
|
c := testConfig(t, "copy-basic")
|
|
|
|
rOrig := c.Resources[0]
|
|
|
|
rCopy := rOrig.Copy()
|
|
|
|
|
|
|
|
if rCopy.Name != rOrig.Name {
|
|
|
|
t.Fatalf("Expected names to equal: %q <=> %q", rCopy.Name, rOrig.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rCopy.Type != rOrig.Type {
|
|
|
|
t.Fatalf("Expected types to equal: %q <=> %q", rCopy.Type, rOrig.Type)
|
|
|
|
}
|
|
|
|
|
|
|
|
origCount := rOrig.RawCount.Config()["count"]
|
|
|
|
rCopy.RawCount.Config()["count"] = "5"
|
|
|
|
if rOrig.RawCount.Config()["count"] != origCount {
|
|
|
|
t.Fatalf("Expected RawCount to be copied, but it behaves like a ref!")
|
|
|
|
}
|
|
|
|
|
|
|
|
rCopy.RawConfig.Config()["newfield"] = "hello"
|
|
|
|
if rOrig.RawConfig.Config()["newfield"] == "hello" {
|
|
|
|
t.Fatalf("Expected RawConfig to be copied, but it behaves like a ref!")
|
|
|
|
}
|
|
|
|
|
|
|
|
rCopy.Provisioners = append(rCopy.Provisioners, &Provisioner{})
|
|
|
|
if len(rOrig.Provisioners) == len(rCopy.Provisioners) {
|
|
|
|
t.Fatalf("Expected Provisioners to be copied, but it behaves like a ref!")
|
|
|
|
}
|
|
|
|
|
|
|
|
if rCopy.Provider != rOrig.Provider {
|
|
|
|
t.Fatalf("Expected providers to equal: %q <=> %q",
|
|
|
|
rCopy.Provider, rOrig.Provider)
|
|
|
|
}
|
|
|
|
|
|
|
|
rCopy.DependsOn[0] = "gotchya"
|
|
|
|
if rOrig.DependsOn[0] == rCopy.DependsOn[0] {
|
|
|
|
t.Fatalf("Expected DependsOn to be copied, but it behaves like a ref!")
|
|
|
|
}
|
|
|
|
|
|
|
|
rCopy.Lifecycle.IgnoreChanges[0] = "gotchya"
|
|
|
|
if rOrig.Lifecycle.IgnoreChanges[0] == rCopy.Lifecycle.IgnoreChanges[0] {
|
|
|
|
t.Fatalf("Expected Lifecycle to be copied, but it behaves like a ref!")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-10-02 20:34:08 +02:00
|
|
|
func TestConfigCount(t *testing.T) {
|
|
|
|
c := testConfig(t, "count-int")
|
|
|
|
actual, err := c.Resources[0].Count()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
if actual != 5 {
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigCount_string(t *testing.T) {
|
|
|
|
c := testConfig(t, "count-string")
|
|
|
|
actual, err := c.Resources[0].Count()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
if actual != 5 {
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigCount_var(t *testing.T) {
|
|
|
|
c := testConfig(t, "count-var")
|
|
|
|
_, err := c.Resources[0].Count()
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("should error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-23 02:16:48 +02:00
|
|
|
func TestConfigValidate_badDependsOn(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-bad-depends-on")
|
|
|
|
if err := c.Validate(); err == nil {
|
|
|
|
t.Fatal("should not be valid")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-03 01:51:20 +02:00
|
|
|
func TestConfigValidate_countInt(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-count-int")
|
|
|
|
if err := c.Validate(); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-15 02:42:23 +02:00
|
|
|
func TestConfigValidate_countBadContext(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-count-bad-context")
|
2015-04-15 17:41:56 +02:00
|
|
|
|
2015-04-15 02:42:23 +02:00
|
|
|
err := c.Validate()
|
2015-04-15 17:41:56 +02:00
|
|
|
|
|
|
|
expected := []string{
|
|
|
|
"no_count_in_output: count variables are only valid within resources",
|
|
|
|
"no_count_in_module: count variables are only valid within resources",
|
|
|
|
}
|
|
|
|
for _, exp := range expected {
|
|
|
|
if !strings.Contains(err.Error(), exp) {
|
|
|
|
t.Fatalf("expected: %q,\nto contain: %q", err, exp)
|
|
|
|
}
|
2015-04-15 02:42:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-03 03:22:32 +02:00
|
|
|
func TestConfigValidate_countCountVar(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-count-count-var")
|
|
|
|
if err := c.Validate(); err == nil {
|
|
|
|
t.Fatal("should not be valid")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-03 01:30:46 +02:00
|
|
|
func TestConfigValidate_countModuleVar(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-count-module-var")
|
|
|
|
if err := c.Validate(); err == nil {
|
|
|
|
t.Fatal("should not be valid")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-03 01:51:20 +02:00
|
|
|
func TestConfigValidate_countNotInt(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-count-not-int")
|
|
|
|
if err := c.Validate(); err == nil {
|
|
|
|
t.Fatal("should not be valid")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-03 01:30:46 +02:00
|
|
|
func TestConfigValidate_countResourceVar(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-count-resource-var")
|
|
|
|
if err := c.Validate(); err == nil {
|
|
|
|
t.Fatal("should not be valid")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigValidate_countUserVar(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-count-user-var")
|
|
|
|
if err := c.Validate(); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-03 03:25:18 +02:00
|
|
|
func TestConfigValidate_countVar(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-count-var")
|
|
|
|
if err := c.Validate(); err != nil {
|
2014-11-02 13:56:44 +01:00
|
|
|
t.Fatalf("err: %s", err)
|
2014-10-03 03:25:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-03 03:24:37 +02:00
|
|
|
func TestConfigValidate_countVarInvalid(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-count-var-invalid")
|
|
|
|
if err := c.Validate(); err == nil {
|
|
|
|
t.Fatal("should not be valid")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-20 18:07:41 +01:00
|
|
|
func TestConfigValidate_dependsOnVar(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-depends-on-var")
|
|
|
|
if err := c.Validate(); err == nil {
|
|
|
|
t.Fatal("should not be valid")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-12 01:02:36 +02:00
|
|
|
func TestConfigValidate_dupModule(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-dup-module")
|
|
|
|
if err := c.Validate(); err == nil {
|
|
|
|
t.Fatal("should not be valid")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-19 01:31:01 +02:00
|
|
|
func TestConfigValidate_dupResource(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-dup-resource")
|
|
|
|
if err := c.Validate(); err == nil {
|
|
|
|
t.Fatal("should not be valid")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-09 01:03:22 +02:00
|
|
|
func TestConfigValidate_moduleNameBad(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-module-name-bad")
|
|
|
|
if err := c.Validate(); err == nil {
|
|
|
|
t.Fatal("should not be valid")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-08 05:19:32 +02:00
|
|
|
func TestConfigValidate_moduleSourceVar(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-module-source-var")
|
|
|
|
if err := c.Validate(); err == nil {
|
|
|
|
t.Fatal("should not be valid")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-16 07:10:16 +01:00
|
|
|
func TestConfigValidate_moduleVarInt(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-module-var-int")
|
|
|
|
if err := c.Validate(); err != nil {
|
|
|
|
t.Fatalf("should be valid: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigValidate_moduleVarMap(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-module-var-map")
|
core: support native list variables in config
This commit adds support for native list variables and outputs, building
up on the previous change to state. Interpolation functions now return
native lists in preference to StringList.
List variables are defined like this:
variable "test" {
# This can also be inferred
type = "list"
default = ["Hello", "World"]
}
output "test_out" {
value = "${var.a_list}"
}
This results in the following state:
```
...
"outputs": {
"test_out": [
"hello",
"world"
]
},
...
```
And the result of terraform output is as follows:
```
$ terraform output
test_out = [
hello
world
]
```
Using the output name, an xargs-friendly representation is output:
```
$ terraform output test_out
hello
world
```
The output command also supports indexing into the list (with
appropriate range checking and no wrapping):
```
$ terraform output test_out 1
world
```
Along with maps, list outputs from one module may be passed as variables
into another, removing the need for the `join(",", var.list_as_string)`
and `split(",", var.list_as_string)` which was previously necessary in
Terraform configuration.
This commit also updates the tests and implementations of built-in
interpolation functions to take and return native lists where
appropriate.
A backwards compatibility note: previously the concat interpolation
function was capable of concatenating either strings or lists. The
strings use case was deprectated a long time ago but still remained.
Because we cannot return `ast.TypeAny` from an interpolation function,
this use case is no longer supported for strings - `concat` is only
capable of concatenating lists. This should not be a huge issue - the
type checker picks up incorrect parameters, and the native HIL string
concatenation - or the `join` function - can be used to replicate the
missing behaviour.
2016-04-22 02:03:24 +02:00
|
|
|
if err := c.Validate(); err != nil {
|
|
|
|
t.Fatalf("should be valid: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigValidate_moduleVarList(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-module-var-list")
|
|
|
|
if err := c.Validate(); err != nil {
|
|
|
|
t.Fatalf("should be valid: %s", err)
|
2014-12-16 07:10:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-22 10:39:07 +02:00
|
|
|
func TestConfigValidate_moduleVarSelf(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-module-var-self")
|
|
|
|
if err := c.Validate(); err == nil {
|
|
|
|
t.Fatal("should be invalid")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-25 00:48:46 +02:00
|
|
|
func TestConfigValidate_nil(t *testing.T) {
|
|
|
|
var c Config
|
|
|
|
if err := c.Validate(); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-04 19:57:09 +02:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-08 03:03:11 +02:00
|
|
|
func TestConfigValidate_pathVar(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-path-var")
|
|
|
|
if err := c.Validate(); err != nil {
|
2014-11-02 13:56:44 +01:00
|
|
|
t.Fatalf("err: %s", err)
|
2014-10-08 03:03:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigValidate_pathVarInvalid(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-path-var-invalid")
|
|
|
|
if err := c.Validate(); err == nil {
|
|
|
|
t.Fatal("should not be valid")
|
2015-02-20 18:18:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-20 23:25:33 +02:00
|
|
|
func TestConfigValidate_providerMulti(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-provider-multi")
|
|
|
|
if err := c.Validate(); err == nil {
|
|
|
|
t.Fatal("should not be valid")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-20 23:27:44 +02:00
|
|
|
func TestConfigValidate_providerMultiGood(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-provider-multi-good")
|
|
|
|
if err := c.Validate(); err != nil {
|
|
|
|
t.Fatalf("should be valid: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-20 23:47:31 +02:00
|
|
|
func TestConfigValidate_providerMultiRefGood(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-provider-multi-ref-good")
|
|
|
|
if err := c.Validate(); err != nil {
|
|
|
|
t.Fatalf("should be valid: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigValidate_providerMultiRefBad(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-provider-multi-ref-bad")
|
|
|
|
if err := c.Validate(); err == nil {
|
|
|
|
t.Fatal("should not be valid")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-20 18:19:13 +01:00
|
|
|
func TestConfigValidate_provConnSplatOther(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-prov-conn-splat-other")
|
|
|
|
if err := c.Validate(); err != nil {
|
|
|
|
t.Fatalf("should be valid: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-20 18:18:08 +01:00
|
|
|
func TestConfigValidate_provConnSplatSelf(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-prov-conn-splat-self")
|
|
|
|
if err := c.Validate(); err == nil {
|
|
|
|
t.Fatal("should not be valid")
|
2015-02-20 18:21:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigValidate_provSplatOther(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-prov-splat-other")
|
|
|
|
if err := c.Validate(); err != nil {
|
|
|
|
t.Fatalf("should be valid: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigValidate_provSplatSelf(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-prov-splat-self")
|
|
|
|
if err := c.Validate(); err == nil {
|
|
|
|
t.Fatal("should not be valid")
|
2015-02-23 23:43:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigValidate_resourceProvVarSelf(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-resource-prov-self")
|
|
|
|
if err := c.Validate(); err != nil {
|
|
|
|
t.Fatalf("should be valid: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigValidate_resourceVarSelf(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-resource-self")
|
|
|
|
if err := c.Validate(); err == nil {
|
|
|
|
t.Fatal("should not be valid")
|
2014-10-08 03:03:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-19 01:00:21 +02:00
|
|
|
func TestConfigValidate_unknownThing(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-unknownthing")
|
|
|
|
if err := c.Validate(); err == nil {
|
|
|
|
t.Fatal("should not be valid")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-04 19:53:36 +02:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {
|
2014-10-02 20:18:57 +02:00
|
|
|
t.Fatal("should not be valid")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigValidate_unknownVarCount(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-unknownvar-count")
|
|
|
|
if err := c.Validate(); err == nil {
|
2014-07-03 06:00:06 +02:00
|
|
|
t.Fatal("should not be valid")
|
2014-07-21 17:34:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
core: support native list variables in config
This commit adds support for native list variables and outputs, building
up on the previous change to state. Interpolation functions now return
native lists in preference to StringList.
List variables are defined like this:
variable "test" {
# This can also be inferred
type = "list"
default = ["Hello", "World"]
}
output "test_out" {
value = "${var.a_list}"
}
This results in the following state:
```
...
"outputs": {
"test_out": [
"hello",
"world"
]
},
...
```
And the result of terraform output is as follows:
```
$ terraform output
test_out = [
hello
world
]
```
Using the output name, an xargs-friendly representation is output:
```
$ terraform output test_out
hello
world
```
The output command also supports indexing into the list (with
appropriate range checking and no wrapping):
```
$ terraform output test_out 1
world
```
Along with maps, list outputs from one module may be passed as variables
into another, removing the need for the `join(",", var.list_as_string)`
and `split(",", var.list_as_string)` which was previously necessary in
Terraform configuration.
This commit also updates the tests and implementations of built-in
interpolation functions to take and return native lists where
appropriate.
A backwards compatibility note: previously the concat interpolation
function was capable of concatenating either strings or lists. The
strings use case was deprectated a long time ago but still remained.
Because we cannot return `ast.TypeAny` from an interpolation function,
this use case is no longer supported for strings - `concat` is only
capable of concatenating lists. This should not be a huge issue - the
type checker picks up incorrect parameters, and the native HIL string
concatenation - or the `join` function - can be used to replicate the
missing behaviour.
2016-04-22 02:03:24 +02:00
|
|
|
func TestConfigValidate_varDefaultListType(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-var-default-list-type")
|
|
|
|
if err := c.Validate(); err != nil {
|
2016-05-10 22:00:28 +02:00
|
|
|
t.Fatalf("should be valid: %s", err)
|
2014-07-03 06:00:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-11 18:46:56 +02:00
|
|
|
func TestConfigValidate_varDefaultInterpolate(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-var-default-interpolate")
|
|
|
|
if err := c.Validate(); err == nil {
|
|
|
|
t.Fatal("should not be valid")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-12 02:20:39 +02:00
|
|
|
func TestConfigValidate_varMultiExactNonSlice(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-var-multi-exact-non-slice")
|
|
|
|
if err := c.Validate(); err != nil {
|
|
|
|
t.Fatalf("should be valid: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-10 06:15:08 +02:00
|
|
|
func TestConfigValidate_varMultiNonSlice(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-var-multi-non-slice")
|
|
|
|
if err := c.Validate(); err == nil {
|
2015-02-17 22:32:45 +01:00
|
|
|
t.Fatal("should not be valid")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigValidate_varMultiNonSliceProvisioner(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-var-multi-non-slice-provisioner")
|
|
|
|
if err := c.Validate(); err == nil {
|
2014-10-10 06:15:08 +02:00
|
|
|
t.Fatal("should not be valid")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-15 18:39:52 +01:00
|
|
|
func TestConfigValidate_varMultiFunctionCall(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-var-multi-func")
|
|
|
|
if err := c.Validate(); err != nil {
|
|
|
|
t.Fatalf("should be valid: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-15 20:45:41 +02:00
|
|
|
func TestConfigValidate_varModule(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-var-module")
|
|
|
|
if err := c.Validate(); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigValidate_varModuleInvalid(t *testing.T) {
|
|
|
|
c := testConfig(t, "validate-var-module-invalid")
|
|
|
|
if err := c.Validate(); err == nil {
|
|
|
|
t.Fatal("should not be valid")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-09 00:06:04 +02:00
|
|
|
func TestNameRegexp(t *testing.T) {
|
2014-10-10 23:50:35 +02:00
|
|
|
cases := []struct {
|
2014-10-09 00:06:04 +02:00
|
|
|
Input string
|
|
|
|
Match bool
|
|
|
|
}{
|
|
|
|
{"hello", true},
|
|
|
|
{"foo-bar", true},
|
|
|
|
{"foo_bar", true},
|
|
|
|
{"_hello", true},
|
|
|
|
{"foo bar", false},
|
|
|
|
{"foo.bar", false},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
if NameRegexp.Match([]byte(tc.Input)) != tc.Match {
|
|
|
|
t.Fatalf("Input: %s\n\nExpected: %#v", tc.Input, tc.Match)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-24 22:29:07 +02:00
|
|
|
func TestProviderConfigName(t *testing.T) {
|
2014-07-20 01:05:48 +02:00
|
|
|
pcs := []*ProviderConfig{
|
|
|
|
&ProviderConfig{Name: "aw"},
|
|
|
|
&ProviderConfig{Name: "aws"},
|
|
|
|
&ProviderConfig{Name: "a"},
|
|
|
|
&ProviderConfig{Name: "gce_"},
|
2014-06-05 21:21:05 +02:00
|
|
|
}
|
|
|
|
|
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 {
|
2015-06-23 16:15:26 +02:00
|
|
|
c, err := LoadFile(filepath.Join(fixtureDir, name, "main.tf"))
|
2014-07-03 06:00:06 +02:00
|
|
|
if err != nil {
|
2014-08-05 07:04:48 +02:00
|
|
|
t.Fatalf("file: %s\n\nerr: %s", name, err)
|
2014-07-03 06:00:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return c
|
|
|
|
}
|