providers/test: additional testing via integration tests
This commit is contained in:
parent
b8c310c61e
commit
dd8ee38ba8
|
@ -2,6 +2,7 @@ package test
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"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
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue