Skip to content

Commit

Permalink
test: ensure group without parent changes as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
SiasMey committed Dec 5, 2024
1 parent 0481a37 commit 48010c2
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions test/mocked/resources/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,97 @@ func Test_UpdateGroupResource_WithoutRecreate_ShouldSucceed(t *testing.T) {
mockOAuth.Mock.Disable()
}

func Test_UpdateGroupResource_WithoutParent_ShouldSucceed(t *testing.T) {
defer gock.Off()
mockOAuth := util.MockOAuth()

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Create
{
PreConfig: func() {
util.MockPostGroup(
util.GenerateGroupAttachedToRootGroupPostRequest("id", ""),
util.GenerateGroupAttachedToRootGroupPostResponse("id", ""),
1,
)
util.MockGetGroup(util.MockRootGroupID, util.GenerateRootGroupGetResponse(), 1)
util.MockGetGroup(
"id",
util.GenerateGroupAttachedToRootGroupGetResponse("id", ""),
1,
)
},
Config: provider.ProviderConfig + `
resource "hpeuxi_group" "my_group" {
name = "name"
}`,
},
// Update that does not trigger a recreate
{
PreConfig: func() {
// existing group
util.MockGetGroup(
"id",
util.GenerateGroupAttachedToRootGroupGetResponse("id", ""),
1,
)
// updated group
util.MockPatchGroup(
"id",
util.GenerateGroupPatchRequest("_2"),
util.GenerateGroupPatchResponse("id", "_2", ""),
1,
)
util.MockGetGroup(util.MockRootGroupID, util.GenerateRootGroupGetResponse(), 2)
util.MockGetGroup(
"id",
util.GenerateGroupAttachedToRootGroupGetResponse("id", "_2"),
2,
)
},
Config: provider.ProviderConfig + `
resource "hpeuxi_group" "my_group" {
name = "name_2"
}`,
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction(
"hpeuxi_group.my_group",
plancheck.ResourceActionUpdate,
),
plancheck.ExpectKnownValue(
"hpeuxi_group.my_group",
tfjsonpath.New("name"),
knownvalue.StringExact("name_2"),
),
},
},
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("hpeuxi_group.my_group", "name", "name_2"),
resource.TestCheckNoResourceAttr("hpeuxi_group.my_group", "parent_group_id"),
resource.TestCheckResourceAttr("hpeuxi_group.my_group", "id", "id"),
),
},
// Delete
{
PreConfig: func() {
util.MockGetGroup(
"id",
util.GenerateGroupAttachedToRootGroupGetResponse("id", "_2"),
1,
)
util.MockDeleteGroup("id", 1)
},
Config: provider.ProviderConfig,
},
},
})

mockOAuth.Mock.Disable()
}

func Test_UpdateGroupResource_WithRecreate_ShouldSucceed(t *testing.T) {
defer gock.Off()
mockOAuth := util.MockOAuth()
Expand Down

0 comments on commit 48010c2

Please sign in to comment.