providers/test: additional testing via integration tests

This commit is contained in:
Mitchell Hashimoto 2017-01-28 11:09:24 -08:00
parent b8c310c61e
commit dd8ee38ba8
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
1 changed files with 44 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package test
import ( import (
"errors" "errors"
"fmt"
"strings" "strings"
"testing" "testing"
@ -55,3 +56,46 @@ resource "test_resource" "foo" {
}, },
}) })
} }
// Test that the output of a data source can be used as the value for
// a "count" in a real resource. This would fail with "count cannot be computed"
// at some point.
func TestDataSource_valueAsResourceCount(t *testing.T) {
resource.UnitTest(t, resource.TestCase{
Providers: testAccProviders,
CheckDestroy: func(s *terraform.State) error {
return nil
},
Steps: []resource.TestStep{
{
Config: strings.TrimSpace(`
data "test_data_source" "test" {
input = "4"
}
resource "test_resource" "foo" {
count = "${data.test_data_source.test.output}"
required = "yep"
required_map = {
key = "value"
}
}
`),
Check: func(s *terraform.State) error {
count := 0
for k, _ := range s.RootModule().Resources {
if strings.HasPrefix(k, "test_resource.foo.") {
count++
}
}
if count != 4 {
return fmt.Errorf("bad count: %d", count)
}
return nil
},
},
},
})
}