diff --git a/Justfile b/Justfile index 47a7a0ad..6962cf33 100644 --- a/Justfile +++ b/Justfile @@ -94,7 +94,13 @@ acceptance-tests +ARGS='': echo if [[ $REPLY =~ ^[Yy]$ ]] then - TF_ACC=1 go test -v ./test/live/... -race -covermode=atomic -coverprofile=.coverage {{ ARGS }} + # we run these seperately so that they do not interfere with each other since GoLang executes + # tests in different directories at the same time + for dir in "datasources" "resources" + do + echo "Running tests in $dir..." + TF_ACC=1 go test -v ./test/live/$dir/... -race {{ ARGS }} + done fi diff --git a/internal/provider/resources/agent_group_assignment.go b/internal/provider/resources/agent_group_assignment.go index e7216a5e..6b34f745 100644 --- a/internal/provider/resources/agent_group_assignment.go +++ b/internal/provider/resources/agent_group_assignment.go @@ -2,6 +2,8 @@ package resources import ( "context" + "net/http" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/util" "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" @@ -206,6 +208,11 @@ func (r *agentGroupAssignmentResource) Delete( errorPresent, errorDetail := util.RaiseForStatus(response, err) if errorPresent { + // deleting a group will cascade delete assignments, so this resource will no longer exist + if response.StatusCode == http.StatusNotFound { + resp.State.RemoveResource(ctx) + return + } resp.Diagnostics.AddError( util.GenerateErrorSummary("delete", "uxi_agent_group_assignment"), errorDetail, diff --git a/internal/provider/resources/network_group_assignment.go b/internal/provider/resources/network_group_assignment.go index 3212fefe..66f4ff59 100644 --- a/internal/provider/resources/network_group_assignment.go +++ b/internal/provider/resources/network_group_assignment.go @@ -2,6 +2,8 @@ package resources import ( "context" + "net/http" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/util" "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" @@ -218,6 +220,11 @@ func (r *networkGroupAssignmentResource) Delete( errorPresent, errorDetail := util.RaiseForStatus(response, err) if errorPresent { + // deleting a group will cascade delete assignments, so this resource will no longer exist + if response.StatusCode == http.StatusNotFound { + resp.State.RemoveResource(ctx) + return + } resp.Diagnostics.AddError( util.GenerateErrorSummary("delete", "uxi_network_group_assignment"), errorDetail, diff --git a/internal/provider/resources/sensor_group_assignment.go b/internal/provider/resources/sensor_group_assignment.go index 10119007..491025ed 100644 --- a/internal/provider/resources/sensor_group_assignment.go +++ b/internal/provider/resources/sensor_group_assignment.go @@ -2,6 +2,7 @@ package resources import ( "context" + "net/http" "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/util" config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" @@ -218,6 +219,11 @@ func (r *sensorGroupAssignmentResource) Delete( errorPresent, errorDetail := util.RaiseForStatus(response, err) if errorPresent { + // deleting a group will cascade delete assignments, so this resource will no longer exist + if response.StatusCode == http.StatusNotFound { + resp.State.RemoveResource(ctx) + return + } resp.Diagnostics.AddError( util.GenerateErrorSummary("delete", "uxi_sensor_group_assignment"), errorDetail, diff --git a/internal/provider/resources/service_group_assignment.go b/internal/provider/resources/service_group_assignment.go index 62443f83..ddc7abab 100644 --- a/internal/provider/resources/service_group_assignment.go +++ b/internal/provider/resources/service_group_assignment.go @@ -2,6 +2,8 @@ package resources import ( "context" + "net/http" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/util" "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" @@ -219,6 +221,11 @@ func (r *serviceTestGroupAssignmentResource) Delete( errorPresent, errorDetail := util.RaiseForStatus(response, err) if errorPresent { + // deleting a group will cascade delete assignments, so this resource will no longer exist + if response.StatusCode == http.StatusNotFound { + resp.State.RemoveResource(ctx) + return + } resp.Diagnostics.AddError( util.GenerateErrorSummary("delete", "uxi_service_test_group_assignment"), errorDetail, diff --git a/test/live/config/config.go b/test/live/config/config.go index 3377dab0..13fb0ba0 100644 --- a/test/live/config/config.go +++ b/test/live/config/config.go @@ -4,7 +4,7 @@ package config // Configuration-API Acceptance Testing (844457745a1111ef880836000a52e73e) // And therefore the client_id and client_secret used for the acceptance tests must match this // customer. -const AgentPermanentUid = "8260f349-5c73-394a-b786-57985d001763" +const AgentPermanentUid = "55277822-c65a-35f7-8b21-d4a9893ec0bb" const AgentCreateSerial = "56fb38331f19d278" const CustomerUid = "9c16d493-7649-40bc-975b-07422d227c0b" const GroupUidRoot = "07422d227c0b" diff --git a/test/live/resources/agent_group_assignment_test.go b/test/live/resources/agent_group_assignment_test.go index 0c6c14e6..8e83e0da 100644 --- a/test/live/resources/agent_group_assignment_test.go +++ b/test/live/resources/agent_group_assignment_test.go @@ -17,8 +17,8 @@ func TestAgentGroupAssignmentResource(t *testing.T) { group2Name = "tf_provider_acceptance_test_agent_group_assignment_resource_two" ) var ( - resourceIdBeforeRecreateBeforeRecreate string - resourceIdBeforeRecreateAfterRecreate string + resourceIdBeforeRecreate string + resourceIdAfterRecreate string ) resource.Test(t, resource.TestCase{ @@ -60,11 +60,11 @@ func TestAgentGroupAssignmentResource(t *testing.T) { func(s *terraform.State) error { resourceName := "uxi_agent_group_assignment.my_agent_group_assignment" rs := s.RootModule().Resources[resourceName] - resourceIdBeforeRecreateBeforeRecreate = rs.Primary.ID + resourceIdBeforeRecreate = rs.Primary.ID return util.CheckStateAgainstAgentGroupAssignment( t, "uxi_agent_group_assignment.my_agent_group_assignment", - *util.GetAgentGroupAssignment(resourceIdBeforeRecreateBeforeRecreate), + *util.GetAgentGroupAssignment(resourceIdBeforeRecreate), )(s) }, ), @@ -118,22 +118,13 @@ func TestAgentGroupAssignmentResource(t *testing.T) { func(s *terraform.State) error { resourceName := "uxi_agent_group_assignment.my_agent_group_assignment" rs := s.RootModule().Resources[resourceName] - resourceIdBeforeRecreateAfterRecreate = rs.Primary.ID + resourceIdAfterRecreate = rs.Primary.ID return util.CheckStateAgainstAgentGroupAssignment( t, "uxi_agent_group_assignment.my_agent_group_assignment", - *util.GetAgentGroupAssignment(resourceIdBeforeRecreateAfterRecreate), + *util.GetAgentGroupAssignment(resourceIdAfterRecreate), )(s) }, - // Check that resource has been recreated - resource.TestCheckResourceAttrWith( - "uxi_agent_group_assignment.my_agent_group_assignment", - "id", - func(value string) error { - assert.NotEqual(t, value, resourceIdBeforeRecreateBeforeRecreate) - return nil - }, - ), ), }, // Delete @@ -146,12 +137,12 @@ func TestAgentGroupAssignmentResource(t *testing.T) { assert.Equal(t, util.GetGroupByName(group2Name), nil) assert.Equal( t, - util.GetAgentGroupAssignment(resourceIdBeforeRecreateBeforeRecreate), + util.GetAgentGroupAssignment(resourceIdBeforeRecreate), nil, ) assert.Equal( t, - util.GetAgentGroupAssignment(resourceIdBeforeRecreateAfterRecreate), + util.GetAgentGroupAssignment(resourceIdAfterRecreate), nil, ) return nil diff --git a/test/live/resources/group_test.go b/test/live/resources/group_test.go index b51b404c..eba0aa33 100644 --- a/test/live/resources/group_test.go +++ b/test/live/resources/group_test.go @@ -19,15 +19,15 @@ type Fetcher interface { func TestGroupResource(t *testing.T) { const ( - groupNameParent = "tf_provider_acceptance_test_parent" + groupNameParent = "tf_provider_acceptance_test_group_resource_parent" groupNameParentUpdated = groupNameParent + "_updated" - groupNameChild = "tf_provider_acceptance_test_child" - groupNameGrandChild = "tf_provider_acceptance_test_grandchild" + groupNameChild = "tf_provider_acceptance_test_group_resource__child" + groupNameGrandChild = "tf_provider_acceptance_test_group_resource__grandchild" groupNameGrandChildMovedToParent = groupNameGrandChild + "_moved_to_parent" groupNameGrandChildMovedToRoot = groupNameGrandChild + "_moved_to_root" ) - var resourceIdBeforeRecreateBeforeRecreate string + var resourceIdBeforeRecreate string resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -127,10 +127,10 @@ func TestGroupResource(t *testing.T) { "uxi_group.grandchild", "id", func(value string) error { - resourceIdBeforeRecreateBeforeRecreate = util.GetGroupByName( + resourceIdBeforeRecreate = util.GetGroupByName( groupNameGrandChild, ).Id - assert.Equal(t, value, resourceIdBeforeRecreateBeforeRecreate) + assert.Equal(t, value, resourceIdBeforeRecreate) return nil }, ), @@ -195,7 +195,7 @@ func TestGroupResource(t *testing.T) { "uxi_group.grandchild", "id", func(value string) error { - assert.NotEqual(t, value, resourceIdBeforeRecreateBeforeRecreate) + assert.NotEqual(t, value, resourceIdBeforeRecreate) return nil }, ), diff --git a/test/live/resources/network_group_assignment_test.go b/test/live/resources/network_group_assignment_test.go index df73f2de..14303b0b 100644 --- a/test/live/resources/network_group_assignment_test.go +++ b/test/live/resources/network_group_assignment_test.go @@ -13,8 +13,8 @@ import ( func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { const ( - groupName = "tf_provider_acceptance_test_network_assignment_test" - group2Name = "tf_provider_acceptance_test_network_assignment_test_two" + groupName = "tf_provider_acceptance_test_network_assignment_resource" + group2Name = "tf_provider_acceptance_test_network_assignment_resource_two" ) var ( diff --git a/test/live/resources/sensor_group_assignment_test.go b/test/live/resources/sensor_group_assignment_test.go index d0a6cef5..9d520f57 100644 --- a/test/live/resources/sensor_group_assignment_test.go +++ b/test/live/resources/sensor_group_assignment_test.go @@ -13,8 +13,8 @@ import ( func TestSensorGroupAssignmentResource(t *testing.T) { const ( - groupName = "tf_provider_acceptance_test_sensor_assignment_test" - group2Name = "tf_provider_acceptance_test_sensor_assignment_test_two" + groupName = "tf_provider_acceptance_test_sensor_assignment_resource" + group2Name = "tf_provider_acceptance_test_sensor_assignment_resource_two" ) var ( @@ -134,15 +134,6 @@ func TestSensorGroupAssignmentResource(t *testing.T) { util.GetSensorGroupAssignment(resourceIdAfterRecreate), )(s) }, - // Check that resource has been recreated - resource.TestCheckResourceAttrWith( - "uxi_network_group_assignment.my_network_group_assignment", - "id", - func(value string) error { - assert.NotEqual(t, value, resourceIdBeforeRecreate) - return nil - }, - ), ), }, // Delete sensor-group assignments and remove sensors from state diff --git a/test/live/resources/service_test_group_assignment_test.go b/test/live/resources/service_test_group_assignment_test.go index 7d3047f5..2d393368 100644 --- a/test/live/resources/service_test_group_assignment_test.go +++ b/test/live/resources/service_test_group_assignment_test.go @@ -13,8 +13,8 @@ import ( func TestServiceTestGroupAssignmentResource(t *testing.T) { const ( - groupName = "tf_acceptance_test_service_test_group_assignment" - group2Name = "tf_acceptance_test_service_test_group_assignment_two" + groupName = "tf_acceptance_test_service_test_group_assignment_resource" + group2Name = "tf_acceptance_test_service_test_group_assignment_resource_two" ) var ( @@ -129,7 +129,7 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { }, // Check that resource has been recreated resource.TestCheckResourceAttrWith( - "uxi_network_group_assignment.my_network_group_assignment", + "uxi_service_test_group_assignment.my_service_test_group_assignment", "id", func(value string) error { assert.NotEqual(t, value, resourceIdBeforeRecreate) diff --git a/test/live/util/util.go b/test/live/util/util.go index e87dc24c..3430656c 100644 --- a/test/live/util/util.go +++ b/test/live/util/util.go @@ -26,16 +26,7 @@ func TestOptionalValue( return resource.TestCheckNoResourceAttr(tfResource, tfKey) } - return resource.TestCheckResourceAttrWith( - tfResource, - tfKey, - func(value string) error { - if value != *property { - return fmt.Errorf("have `%s`; but want `%s`", value, *property) - } - return nil - }, - ) + return resource.TestCheckResourceAttrPtr(tfResource, tfKey, property) } // This is required to do a check against floats since 100% accuracy is not guaranteed for floating @@ -55,8 +46,8 @@ func TestOptionalFloatValue( tfResource, tfKey, func(value string) error { - have := math.Round(stringToFloat64(value)*1e6) / 1e6 - want := math.Round(float64(*property*1e6)) / 1e6 + have := math.Round(stringToFloat64(value)*1e5) / 1e5 + want := math.Round(float64(*property*1e5)) / 1e5 if have != want { return fmt.Errorf("have `%f`; but want `%f`", have, want) }