Add a provider test for a list of maps

Interpolation of a map from a list of maps was not working. Add a
provider example test to cover this.
This commit is contained in:
James Bardin 2016-12-16 09:39:13 -05:00
parent 5b5e892d4b
commit d1d6907640
1 changed files with 60 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package test
import (
"reflect"
"regexp"
"strings"
"testing"
@ -427,6 +428,65 @@ variable "maplist" {
})
}
func TestResource_dataSourceIndexMapList(t *testing.T) {
resource.UnitTest(t, resource.TestCase{
Providers: testAccProviders,
CheckDestroy: testAccCheckResourceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: strings.TrimSpace(`
resource "test_resource" "foo" {
required = "val"
required_map = {
x = "y"
}
list_of_map = [
{
a = "1"
b = "2"
},
{
c = "3"
d = "4"
},
]
}
output "map_from_list" {
value = "${test_resource.foo.list_of_map[0]}"
}
output "value_from_map_from_list" {
value = "${lookup(test_resource.foo.list_of_map[1], "d")}"
}
`),
ExpectError: nil,
Check: func(s *terraform.State) error {
root := s.ModuleByPath(terraform.RootModulePath)
mapOut := root.Outputs["map_from_list"].Value
expectedMapOut := map[string]interface{}{
"a": "1",
"b": "2",
}
valueOut := root.Outputs["value_from_map_from_list"].Value
expectedValueOut := "4"
if !reflect.DeepEqual(mapOut, expectedMapOut) {
t.Fatalf("Expected: %#v\nGot: %#v", expectedMapOut, mapOut)
}
if !reflect.DeepEqual(valueOut, expectedValueOut) {
t.Fatalf("Expected: %#v\nGot: %#v", valueOut, expectedValueOut)
}
return nil
},
},
},
})
}
func testAccCheckResourceDestroy(s *terraform.State) error {
return nil
}