-
Notifications
You must be signed in to change notification settings - Fork 15
/
resource_user_test.go
59 lines (54 loc) · 1.78 KB
/
resource_user_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
package main
import (
"fmt"
"strings"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
func TestAcc_User(t *testing.T) {
name1 := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
name2 := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
email := "[email protected]"
username := "test_user"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: providers(),
Steps: []resource.TestStep{
{
Config: userConfig(name1, name1, email, username),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("airflow_user.test", "first_name", name1),
resource.TestCheckResourceAttr("airflow_user.test", "last_name", name1),
resource.TestCheckResourceAttr("airflow_user.test", "email", email),
resource.TestCheckResourceAttr("airflow_user.test", "username", username),
),
},
{
Config: userConfig(name2, name2, email, username),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("airflow_user.test", "first_name", name2),
resource.TestCheckResourceAttr("airflow_user.test", "last_name", name2),
resource.TestCheckResourceAttr("airflow_user.test", "email", email),
resource.TestCheckResourceAttr("airflow_user.test", "username", username),
),
},
{
ResourceName: "airflow_user.test",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func userConfig(firstName, lastName, email, username string) string {
return fmt.Sprintf(`
resource "airflow_user" "test" {
first_name = "%s"
last_name = "%s"
email = "%s"
username = "%s"
roles = ["Public"]
}
`, firstName, lastName, email, username)
}