-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: acceptance tests | data source | sensor group assignment
- Loading branch information
1 parent
14416e1
commit 8668c06
Showing
4 changed files
with
99 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}, | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
) | ||
} |