terraform: more tests

This commit is contained in:
Mitchell Hashimoto 2015-02-09 09:54:56 -08:00
parent 9cd877a59c
commit 31f6b7474d
2 changed files with 48 additions and 48 deletions

View File

@ -378,6 +378,53 @@ func TestContext2Validate_selfRefMultiAll(t *testing.T) {
} }
} }
func TestContext2Validate_varRef(t *testing.T) {
m := testModule(t, "validate-variable-ref")
p := testProvider("aws")
c := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})
computed := false
p.ValidateResourceFn = func(t string, c *ResourceConfig) ([]string, []error) {
computed = c.IsComputed("foo")
return nil, nil
}
c.Validate()
if !computed {
t.Fatal("should be computed")
}
}
func TestContext2Validate_varRefFilled(t *testing.T) {
m := testModule(t, "validate-variable-ref")
p := testProvider("aws")
c := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
Variables: map[string]string{
"foo": "bar",
},
})
var value interface{}
p.ValidateResourceFn = func(t string, c *ResourceConfig) ([]string, []error) {
value, _ = c.Get("foo")
return nil, nil
}
c.Validate()
if value != "bar" {
t.Fatalf("bad: %#v", value)
}
}
/* /*
func TestContextValidate_moduleBadResource(t *testing.T) { func TestContextValidate_moduleBadResource(t *testing.T) {
m := testModule(t, "validate-module-bad-rc") m := testModule(t, "validate-module-bad-rc")
@ -519,53 +566,6 @@ func TestContextValidate_provisionerConfig_good(t *testing.T) {
} }
} }
func TestContextValidate_varRef(t *testing.T) {
m := testModule(t, "validate-variable-ref")
p := testProvider("aws")
c := testContext(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})
computed := false
p.ValidateResourceFn = func(t string, c *ResourceConfig) ([]string, []error) {
computed = c.IsComputed("foo")
return nil, nil
}
c.Validate()
if !computed {
t.Fatal("should be computed")
}
}
func TestContextValidate_varRefFilled(t *testing.T) {
m := testModule(t, "validate-variable-ref")
p := testProvider("aws")
c := testContext(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
Variables: map[string]string{
"foo": "bar",
},
})
var value interface{}
p.ValidateResourceFn = func(t string, c *ResourceConfig) ([]string, []error) {
value, _ = c.Get("foo")
return nil, nil
}
c.Validate()
if value != "bar" {
t.Fatalf("bad: %#v", value)
}
}
func TestContextInput(t *testing.T) { func TestContextInput(t *testing.T) {
input := new(MockUIInput) input := new(MockUIInput)
m := testModule(t, "input-vars") m := testModule(t, "input-vars")

View File

@ -41,7 +41,7 @@ func (w *ContextGraphWalker) EnterGraph(g *Graph) EvalContext {
Module: w.Context.module, Module: w.Context.module,
State: w.Context.state, State: w.Context.state,
StateLock: &w.Context.stateLock, StateLock: &w.Context.stateLock,
Variables: nil, Variables: w.Context.variables,
}, },
} }
} }