-
Notifications
You must be signed in to change notification settings - Fork 3
/
datasource_service_template_test.go
67 lines (57 loc) · 1.63 KB
/
datasource_service_template_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
package cloudforms
import (
"fmt"
"os"
"testing"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccDataSourceTemplate_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCheckDataTemplateConfigTemplateName(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.cloudforms_service_template.mytemplate", "name", os.Getenv("CF_TEMPLATE_NAME")),
),
},
},
})
}
func testAccDataSourceTemplate(src, n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
service := s.RootModule().Resources[src]
serviceResource := service.Primary.Attributes
search := s.RootModule().Resources[n]
searchResource := search.Primary.Attributes
testArrtributes := []string{
"href",
"id",
"description",
"service_template_catalog_id",
}
for _, attribute := range testArrtributes {
if searchResource[attribute] != serviceResource[attribute] {
return fmt.Errorf("Expected Service's parameter `%s` to be: `%s` but got: `%s`", attribute, serviceResource[attribute], searchResource[attribute])
}
}
return nil
}
}
func testAccCheckDataTemplateConfigTemplateName() string {
return fmt.Sprintf(`
provider "cloudforms" {
user_name = "%s"
password = "%s"
ip = "%s"
}
data "cloudforms_service_template" "mytemplate"{
name = "%s"
}
`, os.Getenv("CF_USER_NAME"),
os.Getenv("CF_PASSWORD"),
os.Getenv("CF_SERVER_IP"),
os.Getenv("CF_TEMPLATE_NAME"))
}