Add more tests for local values

pull/34797/head
Mutahhir Hayat 2 years ago
parent 2667a0f2c3
commit 6bbc8cdc76

@ -24,10 +24,36 @@ func TestLocalValueValue(t *testing.T) {
LocalName: "name",
WantVal: cty.StringVal("jackson"),
},
// "childName": {
// LocalName: "childName",
// WantVal: cty.StringVal("foo"),
// },
"childName": {
LocalName: "childName",
WantVal: cty.StringVal("outputted-child of jackson"),
},
"functional": {
LocalName: "functional",
WantVal: cty.StringVal("Hello, Ander!"),
},
"mappy": {
LocalName: "mappy",
WantVal: cty.ObjectVal(map[string]cty.Value{
"name": cty.StringVal("jackson"),
"age": cty.NumberIntVal(30),
}),
},
"listy": {
LocalName: "listy",
WantVal: cty.TupleVal([]cty.Value{
cty.StringVal("jackson"),
cty.NumberIntVal(30),
}),
},
"booleany": {
LocalName: "booleany",
WantVal: cty.BoolVal(true),
},
"conditiony": {
LocalName: "conditiony",
WantVal: cty.StringVal("true"),
},
}
for name, test := range tests {
@ -45,7 +71,7 @@ func TestLocalValueValue(t *testing.T) {
t.Errorf("unexpected errors\n%s", diags.Err().Error())
}
if got != test.WantVal {
if got.Equals(test.WantVal).False() {
t.Errorf("got %s, want %s", got, test.WantVal)
}

@ -941,7 +941,7 @@ func TestPlanning_Locals(t *testing.T) {
})
inPromisingTask(t, func(ctx context.Context, t *testing.T) {
plan, diags := testPlan(t, main)
_, diags := testPlan(t, main)
if diags.HasErrors() {
t.Fatalf("errors encountered\n%s", spew.Sdump(diags.ForRPC()))
}

@ -2,6 +2,15 @@
locals {
name = "jackson"
childName = stack.child.outputted_name
functional = format("Hello, %s!", "Ander")
mappy = {
name = "jackson",
age = 30
}
listy = ["jackson", 30]
booleany = true
conditiony = local.booleany == true ? "true" : "false"
}
stack "child" {

Loading…
Cancel
Save