forked from ivoronin/terraform-provider-netbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_prefix_test.go
55 lines (47 loc) · 1.17 KB
/
resource_prefix_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
package main
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)
func testAccPrefixConfig(prefix string) string {
return fmt.Sprintf(`
resource "netbox_prefix" "prefix_test" {
prefix = "%s"
}
`, prefix)
}
func TestAccNetboxPrefix_basic(t *testing.T) {
resource.UnitTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccPrefixConfig("192.168.100.0/24"),
Check: resource.ComposeTestCheckFunc(
testAccNetboxPrefixCheck("netbox_prefix.prefix_test"),
),
},
{
Config: testAccPrefixConfig("192.168.200.0/24"),
Check: resource.ComposeTestCheckFunc(
testAccNetboxPrefixCheck("netbox_prefix.prefix_test"),
),
},
},
})
}
func testAccNetboxPrefixCheck(id string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[id]
if !ok {
return fmt.Errorf("Not found: %s", id)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set")
}
//address := rs.Primary.Attributes["address"]
return nil
}
}