Skip to content

Commit

Permalink
feat: acceptance tests | network group assignments (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
1riatsila1 authored Nov 6, 2024
1 parent 7878b47 commit 5615632
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 2 deletions.
6 changes: 6 additions & 0 deletions test/live/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package config

const WiredNetworkUid = "ethernet-658f93b6ea49"
const WiredNetworkName = "tf-provider-acceptance-tests-ethernet-0"
const WirelessNetworkUid = "ssid-35e69ecab0c3"
const WirelessNetworkName = "tf-provider-acceptance-tests-ssid-0"
2 changes: 1 addition & 1 deletion test/live/resources/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func TestRootGroupResource(t *testing.T) {
}

func checkGroupIsChildOfNode(actualParentGroupId, expectedParentName string) error {
expectedParentGroupId := util.GetNodeByName(expectedParentName).GetId()
expectedParentGroupId := util.GetGroupByName(expectedParentName).GetId()

if expectedParentGroupId != actualParentGroupId {
return fmt.Errorf(
Expand Down
227 changes: 227 additions & 0 deletions test/live/resources/network_group_assignment_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
package resource_test

import (
"testing"

"github.com/aruba-uxi/terraform-provider-configuration/test/live/config"
"github.com/aruba-uxi/terraform-provider-configuration/test/live/provider"
"github.com/aruba-uxi/terraform-provider-configuration/test/live/util"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/nbio/st"
)

func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) {
const groupName = "tf_provider_acceptance_test_network_association_test"
const group2Name = "tf_provider_acceptance_test_network_association_test_two"

// Test Wired Network Group Assignment
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Creating a network group assignment
{
Config: provider.ProviderConfig + `
resource "uxi_group" "my_group" {
name = "` + groupName + `"
}
resource "uxi_wired_network" "my_network" {
name = "` + config.WiredNetworkName + `"
}
import {
to = uxi_wired_network.my_network
id = "` + config.WiredNetworkUid + `"
}
resource "uxi_network_group_assignment" "my_network_group_assignment" {
network_id = uxi_wired_network.my_network.id
group_id = uxi_group.my_group.id
}`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(
"uxi_network_group_assignment.my_network_group_assignment",
"network_id",
config.WiredNetworkUid,
),
resource.TestCheckResourceAttrWith(
"uxi_network_group_assignment.my_network_group_assignment",
"group_id",
func(group_id string) error {
st.Assert(t, group_id, util.GetGroupByName(groupName).Id)
return nil
},
),
),
},
// ImportState testing
{
ResourceName: "uxi_network_group_assignment.my_network_group_assignment",
ImportState: true,
ImportStateVerify: true,
},
// Update and Read testing
{
Config: provider.ProviderConfig + `
// the original resources
resource "uxi_group" "my_group" {
name = "` + groupName + `"
}
resource "uxi_wired_network" "my_network" {
name = "` + config.WiredNetworkName + `"
}
import {
to = uxi_wired_network.my_network
id = "` + config.WiredNetworkUid + `"
}
// the new resources we wanna update the assignment to
resource "uxi_group" "my_group_2" {
name = "` + group2Name + `"
}
// the assignment update, updated from network/group to network/group_2
resource "uxi_network_group_assignment" "my_network_group_assignment" {
network_id = uxi_wired_network.my_network.id
group_id = uxi_group.my_group_2.id
}`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(
"uxi_network_group_assignment.my_network_group_assignment",
"network_id",
config.WiredNetworkUid,
),
resource.TestCheckResourceAttrWith(
"uxi_network_group_assignment.my_network_group_assignment",
"group_id",
func(group_id string) error {
st.Assert(t, group_id, util.GetGroupByName(group2Name).Id)
return nil
},
),
),
},
// Delete network-group-assignments and remove networks from state
{
Config: provider.ProviderConfig + `
removed {
from = uxi_wired_network.my_network
lifecycle {
destroy = false
}
}`,
},
},
})
}

func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) {
const groupName = "tf_provider_acceptance_test_network_association_test"
const group2Name = "tf_provider_acceptance_test_network_association_test_two"

// Test Wired Network Group Assignment
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Creating a network group assignment
{
Config: provider.ProviderConfig + `
resource "uxi_group" "my_group" {
name = "` + groupName + `"
}
resource "uxi_wireless_network" "my_network" {
name = "` + config.WirelessNetworkName + `"
}
import {
to = uxi_wireless_network.my_network
id = "` + config.WirelessNetworkUid + `"
}
resource "uxi_network_group_assignment" "my_network_group_assignment" {
network_id = uxi_wireless_network.my_network.id
group_id = uxi_group.my_group.id
}`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(
"uxi_network_group_assignment.my_network_group_assignment",
"network_id",
config.WirelessNetworkUid,
),
resource.TestCheckResourceAttrWith(
"uxi_network_group_assignment.my_network_group_assignment",
"group_id",
func(group_id string) error {
st.Assert(t, group_id, util.GetGroupByName(groupName).Id)
return nil
},
),
),
},
// ImportState testing
{
ResourceName: "uxi_network_group_assignment.my_network_group_assignment",
ImportState: true,
ImportStateVerify: true,
},
// Update and Read testing
{
Config: provider.ProviderConfig + `
// the original resources
resource "uxi_group" "my_group" {
name = "` + groupName + `"
}
resource "uxi_wireless_network" "my_network" {
name = "` + config.WirelessNetworkName + `"
}
import {
to = uxi_wireless_network.my_network
id = "` + config.WirelessNetworkUid + `"
}
// the new resources we wanna update the assignment to
resource "uxi_group" "my_group_2" {
name = "` + group2Name + `"
}
// the assignment update, updated from network/group to network/group_2
resource "uxi_network_group_assignment" "my_network_group_assignment" {
network_id = uxi_wireless_network.my_network.id
group_id = uxi_group.my_group_2.id
}`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(
"uxi_network_group_assignment.my_network_group_assignment",
"network_id",
config.WirelessNetworkUid,
),
resource.TestCheckResourceAttrWith(
"uxi_network_group_assignment.my_network_group_assignment",
"group_id",
func(group_id string) error {
st.Assert(t, group_id, util.GetGroupByName(group2Name).Id)
return nil
},
),
),
},
// Delete network-group-assignments and remove networks from state
{
Config: provider.ProviderConfig + `
removed {
from = uxi_wireless_network.my_network
lifecycle {
destroy = false
}
}`,
},
},
})
}
2 changes: 1 addition & 1 deletion test/live/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func GetRoot() *config_api_client.GroupsGetItem {
return nil
}

func GetNodeByName(name string) *config_api_client.GroupsGetItem {
func GetGroupByName(name string) *config_api_client.GroupsGetItem {
groups, _, _ := Client.ConfigurationAPI.GroupsGet(context.Background()).Execute()
for _, group := range groups.Items {
if group.Name == name {
Expand Down

0 comments on commit 5615632

Please sign in to comment.