forked from DrFaust92/terraform-provider-airflow
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathresource_role_test.go
More file actions
75 lines (64 loc) · 1.84 KB
/
Copy pathresource_role_test.go
File metadata and controls
75 lines (64 loc) · 1.84 KB
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
package main
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 TestAccAirflowRole_basic(t *testing.T) {
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "airflow_role.test"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAirflowRoleCheckDestroy,
Steps: []resource.TestStep{
{
Config: testAccAirflowRoleConfigBasic(rName, "can_read", "Audit Logs"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "action.#", "1"),
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "action.*", map[string]string{
"action": "can_read",
"resource": "Audit Logs",
}),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func testAccCheckAirflowRoleCheckDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(ProviderConfig)
for _, rs := range s.RootModule().Resources {
if rs.Type != "airflow_role" {
continue
}
variable, res, err := client.ApiClient.RoleApi.GetRole(client.AuthContext, rs.Primary.ID).Execute()
if err == nil {
if *variable.Name == rs.Primary.ID {
return fmt.Errorf("Airflow Role (%s) still exists.", rs.Primary.ID)
}
}
if res != nil && res.StatusCode == 404 {
continue
}
}
return nil
}
func testAccAirflowRoleConfigBasic(rName, action, resource string) string {
return fmt.Sprintf(`
resource "airflow_role" "test" {
name = %[1]q
action {
action = %[2]q
resource = %[3]q
}
}
`, rName, action, resource)
}