-
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 test for sensor group assignment resource
- Loading branch information
1 parent
a23b170
commit 3871bf0
Showing
3 changed files
with
163 additions
and
3 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,120 @@ | ||
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 TestSensorGroupAssignmentResource(t *testing.T) { | ||
const groupName = "tf_provider_acceptance_test_sensor_association_test" | ||
const group2Name = "tf_provider_acceptance_test_sensor_association_test_two" | ||
existingSensorProperties := util.GetSensorProperties(config.SensorUid) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
// Creating a sensor group assignment | ||
{ | ||
Config: provider.ProviderConfig + ` | ||
resource "uxi_group" "my_group" { | ||
name = "` + groupName + `" | ||
} | ||
resource "uxi_sensor" "my_sensor" { | ||
name = "` + existingSensorProperties.Name + `" | ||
address_note = "` + *existingSensorProperties.AddressNotes + `" | ||
notes = "` + *existingSensorProperties.Notes + `" | ||
pcap_mode = "` + *existingSensorProperties.PcapMode + `" | ||
} | ||
import { | ||
to = uxi_sensor.my_sensor | ||
id = "` + config.SensorUid + `" | ||
} | ||
resource "uxi_sensor_group_assignment" "my_sensor_group_assignment" { | ||
sensor_id = uxi_sensor.my_sensor.id | ||
group_id = uxi_group.my_group.id | ||
}`, | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr( | ||
"uxi_sensor_group_assignment.my_sensor_group_assignment", | ||
"sensor_id", | ||
config.SensorUid, | ||
), | ||
resource.TestCheckResourceAttrWith( | ||
"uxi_sensor_group_assignment.my_sensor_group_assignment", | ||
"group_id", | ||
func(value string) error { | ||
st.Assert(t, value, util.GetGroupByName(groupName).Id) | ||
return nil | ||
}, | ||
), | ||
), | ||
}, | ||
// ImportState testing | ||
{ | ||
ResourceName: "uxi_sensor_group_assignment.my_sensor_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_sensor" "my_sensor" { | ||
name = "` + existingSensorProperties.Name + `" | ||
address_note = "` + *existingSensorProperties.AddressNotes + `" | ||
notes = "` + *existingSensorProperties.Notes + `" | ||
pcap_mode = "` + *existingSensorProperties.PcapMode + `" | ||
} | ||
// the new resources we wanna update the assignment to | ||
resource "uxi_group" "my_group_2" { | ||
name = "` + group2Name + `" | ||
} | ||
// the assignment update, updated from sensor/group to sensor/group_2 | ||
resource "uxi_sensor_group_assignment" "my_sensor_group_assignment" { | ||
sensor_id = uxi_sensor.my_sensor_2.id | ||
group_id = uxi_group.my_group_2.id | ||
}`, | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr( | ||
"uxi_sensor_group_assignment.my_sensor_group_assignment", | ||
"sensor_id", | ||
config.SensorUid, | ||
), | ||
resource.TestCheckResourceAttrWith( | ||
"uxi_sensor_group_assignment.my_sensor_group_assignment", | ||
"group_id", | ||
func(value string) error { | ||
st.Assert(t, value, util.GetGroupByName(group2Name).Id) | ||
return nil | ||
}, | ||
), | ||
), | ||
}, | ||
// Delete sensor-group assignments and remove sensors from state | ||
{ | ||
Config: provider.ProviderConfig + ` | ||
removed { | ||
from = uxi_sensor.my_sensor | ||
lifecycle { | ||
destroy = false | ||
} | ||
}`, | ||
}, | ||
}, | ||
}) | ||
} |
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,36 @@ | ||
package util | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type sensorProperties struct { | ||
Id string | ||
Name string | ||
Notes *string | ||
AddressNotes *string | ||
PcapMode *string | ||
} | ||
|
||
func GetSensorProperties(id string) sensorProperties { | ||
result, _, err := Client.ConfigurationAPI. | ||
SensorsGet(context.Background()). | ||
Id(id). | ||
Execute() | ||
if err != nil { | ||
panic(err) | ||
} | ||
if len(result.Items) != 1 { | ||
panic("sensor with id `" + id + "` could not be found") | ||
} | ||
sensor := result.Items[0] | ||
// Read these in, as they may not be always constant with the acceptance test | ||
// customer | ||
return sensorProperties{ | ||
Id: sensor.Id, | ||
Name: sensor.Name, | ||
Notes: sensor.Notes.Get(), | ||
AddressNotes: sensor.AddressNote.Get(), | ||
PcapMode: sensor.PcapMode.Get(), | ||
} | ||
} |
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