-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_source_openstack_identity_user_v3_test.go
107 lines (90 loc) · 3.07 KB
/
data_source_openstack_identity_user_v3_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package openstack
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)
func TestAccOpenStackIdentityV3UserDataSource_basic(t *testing.T) {
userName := fmt.Sprintf("tf_test_%s", acctest.RandString(5))
userPassword := acctest.RandString(20)
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckAdminOnly(t)
},
ProviderFactories: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccOpenStackIdentityUserV3DataSourceUser(userName, userPassword),
},
{
Config: testAccOpenStackIdentityUserV3DataSourceBasic(userName, userPassword),
Check: resource.ComposeTestCheckFunc(
testAccCheckIdentityUserV3DataSourceID("data.openstack_identity_user_v3.user_1"),
resource.TestCheckResourceAttr(
"data.openstack_identity_user_v3.user_1", "name", userName),
resource.TestCheckResourceAttr(
"data.openstack_identity_user_v3.user_1", "domain_id", "default"),
resource.TestCheckResourceAttr(
"data.openstack_identity_user_v3.user_1", "enabled", "true"),
testAccCheckIdentityUserV3DataSourceDefaultProjectID(
"data.openstack_identity_user_v3.user_1", "openstack_identity_project_v3.project_1"),
),
},
},
})
}
func testAccCheckIdentityUserV3DataSourceID(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Can't find user data source: %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("User data source ID not set")
}
return nil
}
}
func testAccCheckIdentityUserV3DataSourceDefaultProjectID(n1, n2 string) resource.TestCheckFunc {
return func(s *terraform.State) error {
ds1, ok := s.RootModule().Resources[n1]
if !ok {
return fmt.Errorf("Can't find user data source: %s", n1)
}
if ds1.Primary.ID == "" {
return fmt.Errorf("User data source ID not set")
}
rs2, ok := s.RootModule().Resources[n2]
if !ok {
return fmt.Errorf("Can't find project resource: %s", n2)
}
if rs2.Primary.ID == "" {
return fmt.Errorf("Project resource ID not set")
}
if rs2.Primary.ID != ds1.Primary.Attributes["default_project_id"] {
return fmt.Errorf("Project id and user default_project_id don't match")
}
return nil
}
}
func testAccOpenStackIdentityUserV3DataSourceUser(name, password string) string {
return fmt.Sprintf(`
%s
resource "openstack_identity_user_v3" "user_1" {
name = "%s"
password = "%s"
default_project_id = "${openstack_identity_project_v3.project_1.id}"
}
`, testAccOpenStackIdentityProjectV3DataSourceProject(fmt.Sprintf("%s_project", name), acctest.RandString(20), "tag1", "tag2"), name, password)
}
func testAccOpenStackIdentityUserV3DataSourceBasic(name, password string) string {
return fmt.Sprintf(`
%s
data "openstack_identity_user_v3" "user_1" {
name = "${openstack_identity_user_v3.user_1.name}"
}
`, testAccOpenStackIdentityUserV3DataSourceUser(name, password))
}