generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 3
/
device_test.go
84 lines (79 loc) · 2.31 KB
/
device_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package acc_tests
import (
"regexp"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
func TestAccResourceDeviceEntity(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
CheckDestroy: validateResourceDestroyed("device", "v1/devices"),
Steps: []resource.TestStep{
{
Config: TestAccResourceDeviceConfig + deviceDependencies,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(
"pfptmeta_device.device", "id", regexp.MustCompile("^dev-.*$"),
),
resource.TestCheckResourceAttr(
"pfptmeta_device.device", "name", "resourceDeviceTest",
),
resource.TestCheckResourceAttr(
"pfptmeta_device.device", "description", "some details about the device",
),
resource.TestMatchResourceAttr(
"pfptmeta_device.device", "owner_id", regexp.MustCompile("^usr-.*$"),
),
),
},
},
})
}
func TestAccDataSourceDeviceEntity(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{Config: TestAccResourceDeviceConfig + deviceDependencies},
{
Config: TestAccResourceDeviceConfig + deviceDataSource + deviceDependencies,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(
"data.pfptmeta_device.device", "id", regexp.MustCompile("^dev-.*$"),
),
resource.TestCheckResourceAttr(
"data.pfptmeta_device.device", "name", "resourceDeviceTest",
),
resource.TestCheckResourceAttr(
"data.pfptmeta_device.device", "description", "some details about the device",
),
resource.TestMatchResourceAttr(
"data.pfptmeta_device.device", "owner_id", regexp.MustCompile("^usr-.*$"),
),
),
},
},
})
}
const (
deviceDependencies = `
resource "pfptmeta_user" "user" {
given_name = "John-dev"
family_name = "Doe-dev"
email = "john.doe@example.com"
}
`
TestAccResourceDeviceConfig = `
resource "pfptmeta_device" "device" {
name = "resourceDeviceTest"
description = "some details about the device"
owner_id = pfptmeta_user.user.id
}
`
deviceDataSource = `
data "pfptmeta_device" "device" {
id = pfptmeta_device.device.id
}
`
)