Skip to content

Commit

Permalink
Add tests for user and user_group
Browse files Browse the repository at this point in the history
  • Loading branch information
outscale-toa committed Sep 6, 2024
1 parent a2cc9c1 commit 13110d8
Show file tree
Hide file tree
Showing 10 changed files with 417 additions and 0 deletions.
37 changes: 37 additions & 0 deletions outscale/data_source_outscale_user_groups_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package outscale

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccOthers_user_groups_basic(t *testing.T) {
t.Parallel()
resourceName := "data.outscale_user_groups.basicUGTest"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataUserGroupsBasicConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "user_groups.#"),
),
},
},
})
}

const testAccDataUserGroupsBasicConfig = `
resource "outscale_user_group" "uGroupData" {
user_group_name = "TestACC_uGdata"
path = "/"
}
data "outscale_user_groups" "basicUGTest" {
filter {
name = "user_group_ids"
values = [outscale_user_group.uGroupData.user_group_id]
}
}`
35 changes: 35 additions & 0 deletions outscale/data_source_outscale_users_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package outscale

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccOthers_Users_basic(t *testing.T) {
t.Parallel()
//resourceName := "outscale_user.basic_data_user"
resourceName := "data.outscale_users.basicTestUser" //s.data_testUser"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccOutscaleDataUserBasicConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "users.#"),
),
},
},
})
}

const testAccOutscaleDataUserBasicConfig = `
resource "outscale_user" "basic_data_user" {
user_name = "ACC_test_data1"
path = "/"
}
data "outscale_users" "basicTestUser" {
depends_on = [outscale_user.basic_data_user]
}`
132 changes: 132 additions & 0 deletions outscale/resource_outscale_user_group_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package outscale

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccOthers_user_group_basic(t *testing.T) {
t.Parallel()
resourceName := "outscale_user_group.basic_group"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccUserGroupBasicConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "user_group_name"),
resource.TestCheckResourceAttr(resourceName, "path", "/"),
),
},
},
})
}
func TestAccOthers_userGroup_with_user(t *testing.T) {
t.Parallel()
resourceName := "outscale_user_group.userGroupAcc"
groupName := "groupWithUsers"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccUserGroupWithUsers(groupName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "user_group_name"),
resource.TestCheckResourceAttr(resourceName, "path", "/"),
resource.TestCheckResourceAttr(resourceName, "user_group_name", groupName),
),
},
},
})
}

func TestAccOthers_userGroup_update(t *testing.T) {
t.Parallel()
resourceName := "outscale_user_group.userGroupTAcc1"
groupName := "Gp1UpUser"
userName := "userGp1"
newGpName := "Gp2UpUsers"
newUsName := "userGp2"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccUserGroupUpadate(groupName, userName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "user_group_name"),
resource.TestCheckResourceAttr(resourceName, "path", "/"),
resource.TestCheckResourceAttr(resourceName, "user_group_name", groupName),
),
},
{
Config: testAccUserGroupUpadate(newGpName, newUsName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "user_group_name"),
resource.TestCheckResourceAttrSet(resourceName, "users.#"),
resource.TestCheckResourceAttr(resourceName, "path", "/"),
resource.TestCheckResourceAttr(resourceName, "user_group_name", newGpName),
),
},
},
})
}

const testAccUserGroupBasicConfig = `
resource "outscale_user_group" "basic_group" {
user_group_name = "TestACC_group1"
path = "/"
}`

func testAccUserGroupWithUsers(name string) string {
return fmt.Sprintf(`
resource "outscale_user" "userToAdd1" {
user_name = "userForGp1"
path = "/"
}
resource "outscale_user" "userToAdd2" {
user_name = "userForGp2"
path = "/TestPath/"
}
resource "outscale_user_group" "userGroupAcc" {
user_group_name = "%s"
path = "/"
users {
user_name = outscale_user.userToAdd1.user_name
}
users {
user_name = outscale_user.userToAdd2.user_name
path = "/TestPath/"
}
}
`, name)
}

func testAccUserGroupUpadate(name, userName string) string {
return fmt.Sprintf(`
resource "outscale_user" "userUpToAdd01" {
user_name = "userGp1"
path = "/"
}
resource "outscale_user" "userUpToAdd02" {
user_name = "userGp2"
path = "/TestPath/"
}
resource "outscale_user_group" "userGroupTAcc1" {
user_group_name = "%s"
path = "/"
users {
user_name = "%s"
}
depends_on = [outscale_user.userUpToAdd01]
}
`, name, userName)
}
73 changes: 73 additions & 0 deletions outscale/resource_outscale_user_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package outscale

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccOthers_User_basic(t *testing.T) {
t.Parallel()
resourceName := "outscale_user.basic_user"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccOutscaleUserBasicConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "user_name"),
resource.TestCheckResourceAttr(resourceName, "path", "/"),
),
},
},
})
}

func TestAccOthers_User_update(t *testing.T) {
t.Parallel()
resourceName := "outscale_user.update_user"
name := "TestACC_user1"
newName := "TestACC_user2"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccOutscaleUserUpdatedConfig(name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "user_name"),
resource.TestCheckResourceAttr(resourceName, "path", "/"),
resource.TestCheckResourceAttr(resourceName, "user_name", name),
),
},
{
Config: testAccOutscaleUserUpdatedConfig(newName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "path"),
resource.TestCheckResourceAttrSet(resourceName, "user_name"),
resource.TestCheckResourceAttr(resourceName, "path", "/"),
resource.TestCheckResourceAttr(resourceName, "user_name", newName),
),
},
},
})
}

const testAccOutscaleUserBasicConfig = `
resource "outscale_user" "basic_user" {
user_name = "ACC_test1"
path = "/"
}`

func testAccOutscaleUserUpdatedConfig(name string) string {
return fmt.Sprintf(`
resource "outscale_user" "update_user" {
user_name = "%s"
path = "/"
}
`, name)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"version": "########",
"terraform_version": "########",
"serial": "########",
"lineage": "########",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "outscale_user",
"name": "userInteg",
"provider": "provider[\"registry.terraform.io/outscale/outscale\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"id": "##id-0##",
"path": "/",
"user_id": "##id-1##",
"user_name": "test_integ"
},
"sensitive_attributes": [],
"private": "bnVsbA=="
}
]
}
],
"check_results": "########"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "outscale_user" "userInteg" {
user_name = "test_integ"
path = "/"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"version": "########",
"terraform_version": "########",
"serial": "########",
"lineage": "########",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "outscale_user",
"name": "userInteg",
"provider": "provider[\"registry.terraform.io/outscale/outscale\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"id": "##id-0##",
"path": "/Integ/",
"user_id": "##id-1##",
"user_name": "test_integ_update"
},
"sensitive_attributes": [],
"private": "bnVsbA=="
}
]
}
],
"check_results": "########"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "outscale_user" "userInteg" {
user_name = "test_integ_update"
path = "/Integ/"
}
Loading

0 comments on commit 13110d8

Please sign in to comment.