Skip to content

Commit

Permalink
feat: acceptance test change customer + bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
1riatsila1 committed Nov 7, 2024
1 parent 17e70a7 commit 1670ae9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 49 deletions.
6 changes: 5 additions & 1 deletion internal/provider/resources/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@ func (r *groupResource) Update(
// Update the state to match the plan (replace with response from client)
plan.ID = types.StringValue(group.Id)
plan.Name = types.StringValue(group.Name)
plan.ParentGroupId = types.StringValue(group.Parent.Id)
// only update parent if not attached to root node (else leave it as null)
parentGroup, _ := r.getGroup(ctx, group.Parent.Id)
if parentGroup != nil && !util.IsRoot(*parentGroup) {
state.ParentGroupId = types.StringValue(group.Parent.Id)
}

// Set state to fully populated data
diags = resp.State.Set(ctx, plan)
Expand Down
6 changes: 3 additions & 3 deletions test/live/config/config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package config

const WiredNetworkUid = "ethernet-658f93b6ea49"
const WiredNetworkUid = "ethernet-0ee5b46c2ef0"
const WiredNetworkName = "tf-provider-acceptance-tests-ethernet-0"
const WirelessNetworkUid = "ssid-35e69ecab0c3"
const WirelessNetworkUid = "ssid-bf704ff37dc0"
const WirelessNetworkName = "tf-provider-acceptance-tests-ssid-0"
const ServiceTestUid = "f0e703cb-9170-4da9-aa64-acf7379af3c3"
const ServiceTestUid = "6f81e43d-76f1-4a15-aafe-4ce2371d918a"
const ServiceTestName = "tf-provider-acceptance-test-0"
69 changes: 30 additions & 39 deletions test/live/resources/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ type Fetcher interface {
var rootGroup = util.GetRoot()

func TestGroupResource(t *testing.T) {
const groupNameParent = "tf_provider_acceptance_test_parent"
const groupNameParentUpdated = groupNameParent + "_updated"
const groupNameChild = "tf_provider_acceptance_test_child"
const groupNameGrandChild = "tf_provider_acceptance_test_grandchild"
const groupNameGrandChildMovedToParent = groupNameGrandChild + "_moved_to_parent"
const groupNameGrandChildMovedToRoot = groupNameGrandChild + "_moved_to_root"

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
Expand All @@ -25,19 +32,13 @@ func TestGroupResource(t *testing.T) {
// Node without parent (attached to root)
Config: provider.ProviderConfig + `
resource "uxi_group" "parent" {
name = "tf_provider_acceptance_test_parent"
name = "` + groupNameParent + `"
}`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(
"uxi_group.parent",
"name",
"tf_provider_acceptance_test_parent",
),
resource.TestCheckResourceAttrPtr(
"uxi_group.parent",
"parent_group_id",
nil,
"uxi_group.parent", "name", groupNameParent,
),
resource.TestCheckNoResourceAttr("uxi_group.parent", "parent_group_id"),
),
},
// ImportState testing
Expand All @@ -50,65 +51,59 @@ func TestGroupResource(t *testing.T) {
{
Config: provider.ProviderConfig + `
resource "uxi_group" "parent" {
name = "tf_provider_acceptance_test_parent_name_updated"
name = "` + groupNameParentUpdated + `"
}`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(
"uxi_group.parent",
"name",
"tf_provider_acceptance_test_parent_name_updated",
groupNameParentUpdated,
),
resource.TestCheckResourceAttrPtr(
resource.TestCheckNoResourceAttr(
"uxi_group.parent",
"parent_group_id",
&rootGroup.Id,
),
),
},
// Create nodes attached to non root node
{
Config: provider.ProviderConfig + `
resource "uxi_group" "parent" {
name = "tf_provider_acceptance_test_parent_name_updated"
name = "` + groupNameParentUpdated + `"
}
resource "uxi_group" "child" {
name = "tf_provider_acceptance_test_child"
name = "` + groupNameChild + `"
parent_group_id = uxi_group.parent.id
}
resource "uxi_group" "grandchild" {
name = "tf_provider_acceptance_test_grandchild"
name = "` + groupNameGrandChild + `"
parent_group_id = uxi_group.child.id
}`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(
"uxi_group.child",
"name",
"tf_provider_acceptance_test_child",
groupNameChild,
),
resource.TestCheckResourceAttrWith(
"uxi_group.child",
"parent_group_id",
func(parentGroupId string) error {
return checkGroupIsChildOfNode(
parentGroupId,
"tf_provider_acceptance_test_parent_name_updated",
)
return checkGroupIsChildOfNode(parentGroupId, groupNameParentUpdated)
},
),
resource.TestCheckResourceAttr(
"uxi_group.grandchild",
"name",
"tf_provider_acceptance_test_grandchild",
groupNameGrandChild,
),
resource.TestCheckResourceAttrWith(
"uxi_group.grandchild",
"parent_group_id",
func(parentGroupId string) error {
return checkGroupIsChildOfNode(
parentGroupId, "tf_provider_acceptance_test_child",
)
return checkGroupIsChildOfNode(parentGroupId, groupNameChild)
},
),
),
Expand All @@ -117,33 +112,30 @@ func TestGroupResource(t *testing.T) {
{
Config: provider.ProviderConfig + `
resource "uxi_group" "parent" {
name = "tf_provider_acceptance_test_parent_name_updated"
name = "` + groupNameParentUpdated + `"
}
resource "uxi_group" "child" {
name = "tf_provider_acceptance_test_child"
name = "` + groupNameChild + `"
parent_group_id = uxi_group.parent.id
}
# move grandchild from child to parent
resource "uxi_group" "grandchild" {
name = "tf_provider_acceptance_test_grandchild_moved_to_parent"
name = "` + groupNameGrandChildMovedToParent + `"
parent_group_id = uxi_group.parent.id
}`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(
"uxi_group.grandchild",
"name",
"tf_provider_acceptance_test_grandchild_moved_to_parent",
groupNameGrandChildMovedToParent,
),
resource.TestCheckResourceAttrWith(
"uxi_group.grandchild",
"parent_group_id",
func(parentGroupId string) error {
return checkGroupIsChildOfNode(
parentGroupId,
"tf_provider_acceptance_test_parent_name_updated",
)
return checkGroupIsChildOfNode(parentGroupId, groupNameParentUpdated)
},
),
),
Expand All @@ -152,28 +144,27 @@ func TestGroupResource(t *testing.T) {
{
Config: provider.ProviderConfig + `
resource "uxi_group" "parent" {
name = "tf_provider_acceptance_test_parent_name_updated"
name = "` + groupNameParentUpdated + `"
}
resource "uxi_group" "child" {
name = "tf_provider_acceptance_test_child"
name = "` + groupNameChild + `"
parent_group_id = uxi_group.parent.id
}
# move grandchild from parent to root
resource "uxi_group" "grandchild" {
name = "tf_provider_acceptance_test_grandchild_moved_to_root"
name = "` + groupNameGrandChildMovedToRoot + `"
}`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(
"uxi_group.grandchild",
"name",
"tf_provider_acceptance_test_grandchild_moved_to_root",
groupNameGrandChildMovedToRoot,
),
resource.TestCheckResourceAttr(
resource.TestCheckNoResourceAttr(
"uxi_group.grandchild",
"parent_group_id",
rootGroup.Id,
),
),
},
Expand Down
6 changes: 3 additions & 3 deletions test/live/resources/wired_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestWiredNetworkResource(t *testing.T) {
{
Config: provider.ProviderConfig + `
resource "uxi_wired_network" "wired_network_0" {
name = "tf-provider-acceptance-tests-ethernet-0"
name = "` + config.WiredNetworkName + `"
}
import {
Expand All @@ -45,7 +45,7 @@ func TestWiredNetworkResource(t *testing.T) {
resource.TestCheckResourceAttr(
"uxi_wired_network.wired_network_0",
"name",
"tf-provider-acceptance-tests-ethernet-0",
config.WiredNetworkName,
),
resource.TestCheckResourceAttr(
"uxi_wired_network.wired_network_0",
Expand All @@ -64,7 +64,7 @@ func TestWiredNetworkResource(t *testing.T) {
{
Config: provider.ProviderConfig + `
resource "uxi_wired_network" "wired_network_0" {
name = "tf-provider-acceptance-tests-ethernet-0-updated-name"
name = "` + config.WiredNetworkUid + `-updated-name"
}`,
ExpectError: regexp.MustCompile(
`(?s)updating a wired_network is not supported; wired_networks can only be updated\s*through the dashboard`,
Expand Down
6 changes: 3 additions & 3 deletions test/live/resources/wireless_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestWirelessNetworkResource(t *testing.T) {
{
Config: provider.ProviderConfig + `
resource "uxi_wireless_network" "wireless_network_0" {
name = "tf-provider-acceptance-tests-ssid-0"
name = "` + config.WirelessNetworkName + `"
}
import {
Expand All @@ -45,7 +45,7 @@ func TestWirelessNetworkResource(t *testing.T) {
resource.TestCheckResourceAttr(
"uxi_wireless_network.wireless_network_0",
"name",
"tf-provider-acceptance-tests-ssid-0",
config.WirelessNetworkName,
),
resource.TestCheckResourceAttr(
"uxi_wireless_network.wireless_network_0",
Expand All @@ -64,7 +64,7 @@ func TestWirelessNetworkResource(t *testing.T) {
{
Config: provider.ProviderConfig + `
resource "uxi_wireless_network" "wireless_network_0" {
name = "tf-provider-acceptance-tests-ssid-0-updated-name"
name = "` + config.WirelessNetworkName + `-updated-name"
}`,
ExpectError: regexp.MustCompile(
`(?s)updating a wireless_network is not supported; wireless_networks can only be\s*updated through the dashboard`,
Expand Down

0 comments on commit 1670ae9

Please sign in to comment.