From a2455c65a84f698dea75eb7802ab9426058da54b Mon Sep 17 00:00:00 2001 From: Alistair Yan <52126234+1riatsila1@users.noreply.github.com> Date: Mon, 11 Nov 2024 11:02:42 +0400 Subject: [PATCH] feat: acceptance tests for service test group assignment (#77) --- .../service_test_group_assignment_test.go | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 test/live/resources/service_test_group_assignment_test.go diff --git a/test/live/resources/service_test_group_assignment_test.go b/test/live/resources/service_test_group_assignment_test.go new file mode 100644 index 00000000..ba230885 --- /dev/null +++ b/test/live/resources/service_test_group_assignment_test.go @@ -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 + } + }`, + }, + }, + }) +}