terraform: more tests
This commit is contained in:
parent
9cd877a59c
commit
31f6b7474d
|
@ -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) {
|
||||
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) {
|
||||
input := new(MockUIInput)
|
||||
m := testModule(t, "input-vars")
|
||||
|
|
|
@ -41,7 +41,7 @@ func (w *ContextGraphWalker) EnterGraph(g *Graph) EvalContext {
|
|||
Module: w.Context.module,
|
||||
State: w.Context.state,
|
||||
StateLock: &w.Context.stateLock,
|
||||
Variables: nil,
|
||||
Variables: w.Context.variables,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue