-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_cf_router_group_test.go
69 lines (54 loc) · 1.58 KB
/
data_source_cf_router_group_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
64
65
66
67
68
69
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 routerGroupDataResource = `
data "cloudfoundry_router_group" "rg" {
name = "default-tcp"
}
`
func TestAccDataSourceRouterGroup_normal(t *testing.T) {
ref := "data.cloudfoundry_router_group.rg"
resource.ParallelTest(t,
resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProvidersFactories,
Steps: []resource.TestStep{
resource.TestStep{
Config: routerGroupDataResource,
Check: resource.ComposeTestCheckFunc(
checkDataSourceRouterGroupExists(ref),
resource.TestCheckResourceAttr(
ref, "name", "default-tcp"),
),
},
},
})
}
func checkDataSourceRouterGroupExists(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("router_group '%s' not found in terraform state", resource)
}
id := rs.Primary.ID
name := rs.Primary.Attributes["name"]
rgType := rs.Primary.Attributes["type"]
routerGroup, err := session.RouterClient.GetRouterGroupByName(name)
if err != nil {
return err
}
if err := assertSame(id, routerGroup.GUID); err != nil {
return err
}
if err := assertSame(rgType, routerGroup.Type); err != nil {
return err
}
return nil
}
}