Skip to content

Commit

Permalink
feat: acceptance tests | data source | sensor group assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
1riatsila1 committed Nov 12, 2024
1 parent 14416e1 commit 8668c06
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 6 deletions.
58 changes: 58 additions & 0 deletions test/live/datasources/sensor_group_assignment_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package data_source_test

import (
"testing"

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

func TestSensorGroupAssignmentDataSource(t *testing.T) {
const groupName = "tf_provider_acceptance_test_sensor_group_assignment_datasource"

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: provider.ProviderConfig + `
// create the resource to be used as a datasource
resource "uxi_group" "my_group" {
name = "` + groupName + `"
}
data "uxi_sensor" "my_sensor" {
filter = {
sensor_id = "` + config.SensorUid + `"
}
}
resource "uxi_sensor_group_assignment" "my_sensor_group_assignment" {
sensor_id = data.uxi_sensor.my_sensor.id
group_id = uxi_group.my_group.id
}
// the actual datasource
data "uxi_sensor_group_assignment" "my_sensor_group_assignment" {
filter = {
sensor_group_assignment_id = uxi_sensor_group_assignment.my_sensor_group_assignment.id
}
}
`,
Check: resource.ComposeTestCheckFunc(
func(s *terraform.State) error {
resourceName := "uxi_sensor_group_assignment.my_sensor_group_assignment"
rs := s.RootModule().Resources[resourceName]
return util.CheckStateAgainstSensorGroupAssignment(
t,
"data.uxi_sensor_group_assignment.my_sensor_group_assignment",
util.GetSensorGroupAssignment(rs.Primary.ID),
)(s)
},
),
},
},
})
}
8 changes: 4 additions & 4 deletions test/live/resources/network_group_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

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

// Test Wired Network Group Assignment
resource.Test(t, resource.TestCase{
Expand Down Expand Up @@ -119,8 +119,8 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) {
}

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

// Test Wired Network Group Assignment
resource.Test(t, resource.TestCase{
Expand Down
4 changes: 2 additions & 2 deletions test/live/resources/sensor_group_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

func TestSensorGroupAssignmentResource(t *testing.T) {
const groupName = "tf_provider_acceptance_test_sensor_association_test"
const group2Name = "tf_provider_acceptance_test_sensor_association_test_two"
const groupName = "tf_provider_acceptance_test_sensor_assignment_test"
const group2Name = "tf_provider_acceptance_test_sensor_assignment_test_two"
existingSensorProperties := util.GetSensorProperties(config.SensorUid)

resource.Test(t, resource.TestCase{
Expand Down
35 changes: 35 additions & 0 deletions test/live/util/sensor_group_assignment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package util

import (
"context"

config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/nbio/st"
)

func GetSensorGroupAssignment(id string) config_api_client.SensorGroupAssignmentsItem {
result, _, err := Client.ConfigurationAPI.
SensorGroupAssignmentsGet(context.Background()).
Id(id).
Execute()
if err != nil {
panic(err)
}
if len(result.Items) != 1 {
panic("sensor_group_assignment with id `" + id + "` could not be found")
}
return result.Items[0]
}

func CheckStateAgainstSensorGroupAssignment(
t st.Fatalf,
entity string,
sensorGroupAssignment config_api_client.SensorGroupAssignmentsItem,
) resource.TestCheckFunc {
return resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(entity, "id", sensorGroupAssignment.Id),
resource.TestCheckResourceAttr(entity, "group_id", sensorGroupAssignment.Group.Id),
resource.TestCheckResourceAttr(entity, "sensor_id", sensorGroupAssignment.Sensor.Id),
)
}

0 comments on commit 8668c06

Please sign in to comment.