-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provider/test: Add test of data source count.index
This adds a unit test to the test provider that verifies count.index behaves correctly. Although not ideal this is hard to implement as a context test without changing around the (non helper/schema) implementation of the x_data_source.
- Loading branch information
Showing
3 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package test | ||
|
||
import ( | ||
"errors" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestDataSource_dataSourceCount(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" { | ||
count = 3 | ||
input = "count-${count.index}" | ||
} | ||
resource "test_resource" "foo" { | ||
required = "yep" | ||
required_map = { | ||
key = "value" | ||
} | ||
list = ["${data.test_data_source.test.*.output}"] | ||
} | ||
`), | ||
Check: func(s *terraform.State) error { | ||
res, hasRes := s.RootModule().Resources["test_resource.foo"] | ||
if !hasRes { | ||
return errors.New("No test_resource.foo in state") | ||
} | ||
if res.Primary.Attributes["list.#"] != "3" { | ||
return errors.New("Wrong list.#, expected 3") | ||
} | ||
if res.Primary.Attributes["list.0"] != "count-0" { | ||
return errors.New("Wrong list.0, expected count-0") | ||
} | ||
if res.Primary.Attributes["list.1"] != "count-1" { | ||
return errors.New("Wrong list.0, expected count-1") | ||
} | ||
if res.Primary.Attributes["list.2"] != "count-2" { | ||
return errors.New("Wrong list.0, expected count-2") | ||
} | ||
return nil | ||
}, | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters