Skip to content

Commit

Permalink
Merge branch 'main' into ay/feat/client/5.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
1riatsila1 authored Nov 15, 2024
2 parents 84165ea + 795aef8 commit 085aeec
Show file tree
Hide file tree
Showing 43 changed files with 488 additions and 150 deletions.
8 changes: 7 additions & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,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: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ toolchain go1.22.5

require (
github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client v0.0.0-00010101000000-000000000000
github.com/google/uuid v1.6.0
github.com/h2non/gock v1.2.0
github.com/hashicorp/terraform-plugin-framework v1.10.0
github.com/hashicorp/terraform-plugin-go v0.23.0
github.com/hashicorp/terraform-plugin-testing v1.10.0
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32
github.com/stretchr/testify v1.9.0
golang.org/x/oauth2 v0.17.0
)

Expand All @@ -19,10 +20,10 @@ require (
github.com/agext/levenshtein v1.2.2 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
Expand Down Expand Up @@ -52,6 +53,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/oklog/run v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
Expand All @@ -67,6 +69,7 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.34.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client => ./pkg/config-api-client
5 changes: 5 additions & 0 deletions internal/provider/resources/agent.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"
"github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client"
Expand Down Expand Up @@ -230,6 +231,10 @@ func (r *agentResource) Delete(
errorPresent, errorDetail := util.RaiseForStatus(response, err)

if errorPresent {
if response.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError(util.GenerateErrorSummary("delete", "uxi_agent"), errorDetail)
return
}
Expand Down
6 changes: 6 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,10 @@ func (r *agentGroupAssignmentResource) Delete(
errorPresent, errorDetail := util.RaiseForStatus(response, err)

if errorPresent {
if response.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError(
util.GenerateErrorSummary("delete", "uxi_agent_group_assignment"),
errorDetail,
Expand Down
6 changes: 6 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,10 @@ func (r *networkGroupAssignmentResource) Delete(
errorPresent, errorDetail := util.RaiseForStatus(response, err)

if errorPresent {
if response.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError(
util.GenerateErrorSummary("delete", "uxi_network_group_assignment"),
errorDetail,
Expand Down
5 changes: 5 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,10 @@ func (r *sensorGroupAssignmentResource) Delete(
errorPresent, errorDetail := util.RaiseForStatus(response, err)

if errorPresent {
if response.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError(
util.GenerateErrorSummary("delete", "uxi_sensor_group_assignment"),
errorDetail,
Expand Down
6 changes: 6 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 @@ -221,6 +223,10 @@ func (r *serviceTestGroupAssignmentResource) Delete(
errorPresent, errorDetail := util.RaiseForStatus(response, err)

if errorPresent {
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 AgentPermanentId = "8260f349-5c73-394a-b786-57985d001763"
const AgentPermanentId = "55277822-c65a-35f7-8b21-d4a9893ec0bb"
const AgentCreateSerial = "56fb38331f19d278"
const CustomerId = "9c16d493-7649-40bc-975b-07422d227c0b"
const GroupIdRoot = "07422d227c0b"
Expand Down
2 changes: 1 addition & 1 deletion test/live/datasources/agent_group_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestAgentGroupAssignmentDataSource(t *testing.T) {
return util.CheckStateAgainstAgentGroupAssignment(
t,
"data.uxi_agent_group_assignment.my_agent_group_assignment",
util.GetAgentGroupAssignment(rs.Primary.ID),
*util.GetAgentGroupAssignment(rs.Primary.ID),
)(s)
},
),
Expand Down
6 changes: 3 additions & 3 deletions test/live/datasources/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/provider"
"github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/util"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/nbio/st"
"github.com/stretchr/testify/assert"
)

func TestGroupDataSource(t *testing.T) {
Expand Down Expand Up @@ -45,7 +45,7 @@ func TestGroupDataSource(t *testing.T) {
"data.uxi_group.my_group",
"id",
func(value string) error {
st.Assert(t, value, util.GetGroupByName(groupName).Id)
assert.Equal(t, value, util.GetGroupByName(groupName).Id)
return nil
},
),
Expand All @@ -54,7 +54,7 @@ func TestGroupDataSource(t *testing.T) {
"data.uxi_group.my_group",
"path",
func(value string) error {
st.Assert(t, value, util.GetGroupByName(groupName).Path)
assert.Equal(t, value, util.GetGroupByName(groupName).Path)
return nil
},
),
Expand Down
48 changes: 37 additions & 11 deletions test/live/resources/agent_group_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ import (
"github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/util"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/nbio/st"
"github.com/stretchr/testify/assert"
)

func TestAgentGroupAssignmentResource(t *testing.T) {
const groupName = "tf_provider_acceptance_test_agent_group_assignment_resource"
const group2Name = "tf_provider_acceptance_test_agent_group_assignment_resource_two"
const (
groupName = "tf_provider_acceptance_test_agent_group_assignment_resource"
group2Name = "tf_provider_acceptance_test_agent_group_assignment_resource_two"
)
var (
resourceIdBeforeRecreate string
resourceIdAfterRecreate string
)

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Creating a agent group assignment
// Creating
{
Config: provider.ProviderConfig + `
resource "uxi_group" "my_group" {
Expand Down Expand Up @@ -46,29 +52,30 @@ func TestAgentGroupAssignmentResource(t *testing.T) {
"uxi_agent_group_assignment.my_agent_group_assignment",
"group_id",
func(value string) error {
st.Assert(t, util.GetGroupByName(groupName).Id, value)
assert.Equal(t, util.GetGroupByName(groupName).Id, value)
return nil
},
),
// Check properties match what is on backend
func(s *terraform.State) error {
resourceName := "uxi_agent_group_assignment.my_agent_group_assignment"
rs := s.RootModule().Resources[resourceName]
resourceIdBeforeRecreate = rs.Primary.ID
return util.CheckStateAgainstAgentGroupAssignment(
t,
"uxi_agent_group_assignment.my_agent_group_assignment",
util.GetAgentGroupAssignment(rs.Primary.ID),
*util.GetAgentGroupAssignment(resourceIdBeforeRecreate),
)(s)
},
),
},
// ImportState testing
// ImportState
{
ResourceName: "uxi_agent_group_assignment.my_agent_group_assignment",
ImportState: true,
ImportStateVerify: true,
},
// Update testing
// Update
{
Config: provider.ProviderConfig + `
// the original resources
Expand Down Expand Up @@ -103,23 +110,42 @@ func TestAgentGroupAssignmentResource(t *testing.T) {
"uxi_agent_group_assignment.my_agent_group_assignment",
"group_id",
func(value string) error {
st.Assert(t, util.GetGroupByName(group2Name).Id, value)
assert.Equal(t, util.GetGroupByName(group2Name).Id, value)
return nil
},
),
// Check properties match what is on backend
func(s *terraform.State) error {
resourceName := "uxi_agent_group_assignment.my_agent_group_assignment"
rs := s.RootModule().Resources[resourceName]
resourceIdAfterRecreate = rs.Primary.ID
return util.CheckStateAgainstAgentGroupAssignment(
t,
"uxi_agent_group_assignment.my_agent_group_assignment",
util.GetAgentGroupAssignment(rs.Primary.ID),
*util.GetAgentGroupAssignment(resourceIdAfterRecreate),
)(s)
},
),
},
// Delete testing happens automatically
// Delete
{
Config: provider.ProviderConfig,
},
},
CheckDestroy: func(s *terraform.State) error {
assert.Equal(t, util.GetGroupByName(groupName), nil)
assert.Equal(t, util.GetGroupByName(group2Name), nil)
assert.Equal(
t,
util.GetAgentGroupAssignment(resourceIdBeforeRecreate),
nil,
)
assert.Equal(
t,
util.GetAgentGroupAssignment(resourceIdAfterRecreate),
nil,
)
return nil
},
})
}
17 changes: 13 additions & 4 deletions test/live/resources/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/provider"
"github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/util"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/stretchr/testify/assert"
)

func TestAgentResource(t *testing.T) {
Expand Down Expand Up @@ -57,19 +59,19 @@ func TestAgentResource(t *testing.T) {
}`,

Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("uxi_agent.my_agent", "id", agentId),
resource.TestCheckResourceAttr("uxi_agent.my_agent", "name", agentName),
resource.TestCheckResourceAttr("uxi_agent.my_agent", "notes", ""),
resource.TestCheckResourceAttr("uxi_agent.my_agent", "pcap_mode", "light"),
resource.TestCheckResourceAttr("uxi_agent.my_agent", "id", agentId),
),
},
// ImportState testing
// ImportState
{
ResourceName: "uxi_agent.my_agent",
ImportState: true,
ImportStateVerify: true,
},
// Update testing
// Update
{
Config: provider.ProviderConfig + `
resource "uxi_agent" "my_agent" {
Expand All @@ -84,7 +86,14 @@ func TestAgentResource(t *testing.T) {
resource.TestCheckResourceAttr("uxi_agent.my_agent", "pcap_mode", "off"),
),
},
// Delete testing happen automatically
// Delete
{
Config: provider.ProviderConfig,
},
},
CheckDestroy: func(s *terraform.State) error {
assert.Equal(t, util.GetAgent(agentId), nil)
return nil
},
})
}
Loading

0 comments on commit 085aeec

Please sign in to comment.