-
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.
Merge branch 'main' into ay/feat/acceptance-tests/sensor-group-assign…
…ment
- Loading branch information
Showing
1 changed file
with
113 additions
and
0 deletions.
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
test/live/resources/service_test_group_assignment_test.go
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,113 @@ | ||
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 TestServiceTestGroupAssignmentResource(t *testing.T) { | ||
const groupName = "tf_acceptance_test_service_test_group_assignment" | ||
const group2Name = "tf_acceptance_test_service_test_group_assignment_two" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
// Creating a serviceTest group assignment | ||
{ | ||
Config: provider.ProviderConfig + ` | ||
resource "uxi_group" "my_group" { | ||
name = "` + groupName + `" | ||
} | ||
resource "uxi_service_test" "my_service_test" { | ||
name = "` + config.ServiceTestName + `" | ||
} | ||
import { | ||
to = uxi_service_test.my_service_test | ||
id = "` + config.ServiceTestUid + `" | ||
} | ||
resource "uxi_service_test_group_assignment" "my_service_test_group_assignment" { | ||
service_test_id = uxi_service_test.my_service_test.id | ||
group_id = uxi_group.my_group.id | ||
}`, | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr( | ||
"uxi_service_test_group_assignment.my_service_test_group_assignment", | ||
"service_test_id", | ||
config.ServiceTestUid, | ||
), | ||
resource.TestCheckResourceAttrWith( | ||
"uxi_service_test_group_assignment.my_service_test_group_assignment", | ||
"group_id", | ||
func(value string) error { | ||
st.Assert(t, value, util.GetGroupByName(groupName).Id) | ||
return nil | ||
}, | ||
), | ||
), | ||
}, | ||
// ImportState testing | ||
{ | ||
ResourceName: "uxi_service_test_group_assignment.my_service_test_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_service_test" "my_service_test" { | ||
name = "` + config.ServiceTestName + `" | ||
} | ||
// the new resources we wanna update the assignment to | ||
resource "uxi_group" "my_group_2" { | ||
name = "` + group2Name + `" | ||
} | ||
// the assignment update, updated from service_test/group to service_test/group_2 | ||
resource "uxi_service_test_group_assignment" "my_service_test_group_assignment" { | ||
service_test_id = uxi_service_test.my_service_test.id | ||
group_id = uxi_group.my_group_2.id | ||
}`, | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr( | ||
"uxi_service_test_group_assignment.my_service_test_group_assignment", | ||
"service_test_id", | ||
config.ServiceTestUid, | ||
), | ||
resource.TestCheckResourceAttrWith( | ||
"uxi_service_test_group_assignment.my_service_test_group_assignment", | ||
"group_id", | ||
func(value string) error { | ||
st.Assert(t, value, util.GetGroupByName(group2Name).Id) | ||
return nil | ||
}, | ||
), | ||
), | ||
}, | ||
// Remove serviceTests from state | ||
{ | ||
Config: provider.ProviderConfig + ` | ||
removed { | ||
from = uxi_service_test.my_service_test | ||
lifecycle { | ||
destroy = false | ||
} | ||
}`, | ||
}, | ||
}, | ||
}) | ||
} |