-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdatasource_computer_test.go
69 lines (59 loc) · 1.54 KB
/
datasource_computer_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 bigfix
import (
"fmt"
"os"
"testing"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccDataSourceComputer_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckDataComputerConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.bigfix_computer.test", "name", os.Getenv("BFX_COMPUTER")),
),
},
},
})
}
func testAccDataSourceComputer(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{
"id",
"os",
"ram",
"ip_address",
}
for _, attribute := range testArrtributes {
if searchResource[attribute] != serviceResource[attribute] {
return fmt.Errorf("Expected Computer parameter `%s` to be `%s` but got `%s`", attribute, serviceResource[attribute], searchResource[attribute])
}
}
return nil
}
}
func testAccCheckDataComputerConfig() string {
return fmt.Sprintf(`
provider "bigfix" {
server = "%s"
port = %s
username = "%s"
password = "%s"
}
data "bigfix_computer" "test"{
name = "%s"
}
`, os.Getenv("BFX_SERVER"),
os.Getenv("BFX_PORT"),
os.Getenv("BFX_USERNAME"),
os.Getenv("BFX_PASSWORD"),
os.Getenv("BFX_COMPUTER"))
}