-
Notifications
You must be signed in to change notification settings - Fork 46
/
resource_role_test.go
59 lines (52 loc) · 1.77 KB
/
resource_role_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 nexus
import (
"fmt"
"strconv"
"strings"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)
func TestAccRoleBasic(t *testing.T) {
t.Parallel()
roleID := acctest.RandString(10)
roleName := acctest.RandString(10)
roleDescription := acctest.RandString(30)
rolePrivileges := []string{"nx-all"}
roleRoles := []string{"nx-admin"}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
// Creates a basic role
{
Config: testAccRoleResource(roleID, roleName, roleDescription, rolePrivileges, roleRoles),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("nexus_role.acceptance", "id", roleID),
resource.TestCheckResourceAttr("nexus_role.acceptance", "name", roleName),
resource.TestCheckResourceAttr("nexus_role.acceptance", "roleid", roleID),
resource.TestCheckResourceAttr("nexus_role.acceptance", "description", roleDescription),
resource.TestCheckResourceAttr("nexus_role.acceptance", "privileges.#", strconv.Itoa(len(rolePrivileges))),
resource.TestCheckResourceAttr("nexus_role.acceptance", "roles.#", strconv.Itoa(len(roleRoles))),
),
},
{
ResourceName: "nexus_role.acceptance",
ImportStateId: roleID,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func testAccRoleResource(id string, name string, description string, privileges []string, roles []string) string {
return fmt.Sprintf(`
resource "nexus_role" "acceptance" {
roleid = "%s"
name = "%s"
description = "%s"
privileges = ["%s"]
roles = ["%s"]
}
`, id, name, description, strings.Join(privileges, "\",\""), strings.Join(roles, "\",\""))
}