-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_cf_asg_test.go
63 lines (49 loc) · 1.41 KB
/
data_source_cf_asg_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package cloudfoundry
import (
"fmt"
"github.com/terraform-providers/terraform-provider-cloudfoundry/cloudfoundry/managers"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)
const asgDataResource = `
data "cloudfoundry_asg" "public" {
name = "%s"
}
`
func TestAccDataSourceAsg_normal(t *testing.T) {
defaultAsg := getTestSecurityGroup()
ref := "data.cloudfoundry_asg.public"
resource.ParallelTest(t,
resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProvidersFactories,
Steps: []resource.TestStep{
resource.TestStep{
Config: fmt.Sprintf(asgDataResource, defaultAsg),
Check: resource.ComposeTestCheckFunc(
checkDataSourceAsgExists(ref),
resource.TestCheckResourceAttr(
ref, "name", defaultAsg),
),
},
},
})
}
func checkDataSourceAsgExists(resource string) resource.TestCheckFunc {
return func(s *terraform.State) error {
session := testAccProvider.Meta().(*managers.Session)
rs, ok := s.RootModule().Resources[resource]
if !ok {
return fmt.Errorf("asg '%s' not found in terraform state", resource)
}
id := rs.Primary.ID
attributes := rs.Primary.Attributes
asg, _, err := session.ClientV2.GetSecurityGroup(id)
if err != nil {
return err
}
err = assertEquals(attributes, "name", asg.Name)
return err
}
}