Skip to content

Commit

Permalink
fix running full acceptance test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
1riatsila1 committed Nov 14, 2024
1 parent 0d93913 commit e81bcaf
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 54 deletions.
8 changes: 7 additions & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
7 changes: 7 additions & 0 deletions internal/provider/resources/agent_group_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions internal/provider/resources/network_group_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions internal/provider/resources/sensor_group_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions internal/provider/resources/service_group_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/live/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 8 additions & 17 deletions test/live/resources/agent_group_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
},
),
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions test/live/resources/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
},
),
Expand Down Expand Up @@ -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
},
),
Expand Down
4 changes: 2 additions & 2 deletions test/live/resources/network_group_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
13 changes: 2 additions & 11 deletions test/live/resources/sensor_group_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/live/resources/service_test_group_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 3 additions & 12 deletions test/live/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down

0 comments on commit e81bcaf

Please sign in to comment.