From a90bf2520c7f89f9732baba4ebf865322d7e48e1 Mon Sep 17 00:00:00 2001 From: 1riatsila1 Date: Tue, 5 Nov 2024 17:20:17 +0400 Subject: [PATCH] fix: groups attached to root keep null parent_group_id --- go.mod | 2 +- internal/provider/datasources/agent.go | 2 +- internal/provider/datasources/group.go | 2 +- .../datasources/network_group_assignment.go | 2 +- internal/provider/datasources/sensor.go | 2 +- .../datasources/sensor_group_assignment.go | 2 +- .../provider/datasources/wired_network.go | 2 +- .../provider/datasources/wireless_network.go | 2 +- internal/provider/provider.go | 4 +- internal/provider/resources/agent.go | 2 +- internal/provider/resources/group.go | 63 +++-- .../resources/network_group_assignment.go | 2 +- internal/provider/resources/sensor.go | 2 +- .../resources/sensor_group_assignment.go | 2 +- .../resources/service_group_assignment.go | 2 +- internal/provider/resources/wired_network.go | 2 +- .../provider/resources/wireless_network.go | 2 +- internal/provider/util/retry.go | 2 +- main.go | 2 +- test/live/provider/provider.go | 4 +- test/live/resources/group_test.go | 6 +- test/live/util/util.go | 2 +- test/mocked/data-sources/agent_test.go | 4 +- test/mocked/data-sources/group_test.go | 8 +- .../network_group_assignment_test.go | 4 +- .../sensor_group_assignment_test.go | 4 +- test/mocked/data-sources/sensor_test.go | 4 +- .../mocked/data-sources/wired_network_test.go | 4 +- .../data-sources/wireless_network_test.go | 4 +- test/mocked/provider/provider.go | 2 +- .../resources/agent_group_assignment_test.go | 22 +- test/mocked/resources/agent_test.go | 4 +- test/mocked/resources/group_test.go | 223 ++++++++++++++++-- .../network_group_assignment_test.go | 72 +++--- .../resources/sensor_group_assignment_test.go | 56 +++-- test/mocked/resources/sensor_test.go | 4 +- test/mocked/resources/service_test.go | 6 +- .../service_test_group_assignment_test.go | 38 +-- test/mocked/resources/wired_network_test.go | 4 +- .../mocked/resources/wireless_network_test.go | 4 +- test/mocked/util/utils.go | 4 +- 41 files changed, 408 insertions(+), 176 deletions(-) diff --git a/go.mod b/go.mod index 35303e84..56484332 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/aruba-uxi/terraform-provider-configuration-api +module github.com/aruba-uxi/terraform-provider-configuration go 1.21 diff --git a/internal/provider/datasources/agent.go b/internal/provider/datasources/agent.go index f559616e..04784ba0 100644 --- a/internal/provider/datasources/agent.go +++ b/internal/provider/datasources/agent.go @@ -3,8 +3,8 @@ package datasources import ( "context" - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider/util" config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" diff --git a/internal/provider/datasources/group.go b/internal/provider/datasources/group.go index 53b7752f..5030d44f 100644 --- a/internal/provider/datasources/group.go +++ b/internal/provider/datasources/group.go @@ -3,8 +3,8 @@ package datasources import ( "context" - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider/util" config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" diff --git a/internal/provider/datasources/network_group_assignment.go b/internal/provider/datasources/network_group_assignment.go index 2b6e5684..3ed0fdf3 100644 --- a/internal/provider/datasources/network_group_assignment.go +++ b/internal/provider/datasources/network_group_assignment.go @@ -3,8 +3,8 @@ package datasources import ( "context" - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider/util" config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" diff --git a/internal/provider/datasources/sensor.go b/internal/provider/datasources/sensor.go index a5f23abe..b1437fa4 100644 --- a/internal/provider/datasources/sensor.go +++ b/internal/provider/datasources/sensor.go @@ -3,8 +3,8 @@ package datasources import ( "context" - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider/util" config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" diff --git a/internal/provider/datasources/sensor_group_assignment.go b/internal/provider/datasources/sensor_group_assignment.go index 6071d2ac..493f3acd 100644 --- a/internal/provider/datasources/sensor_group_assignment.go +++ b/internal/provider/datasources/sensor_group_assignment.go @@ -3,8 +3,8 @@ package datasources import ( "context" - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider/util" config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" diff --git a/internal/provider/datasources/wired_network.go b/internal/provider/datasources/wired_network.go index 5c6c5d31..94dd3a1a 100644 --- a/internal/provider/datasources/wired_network.go +++ b/internal/provider/datasources/wired_network.go @@ -3,8 +3,8 @@ package datasources import ( "context" - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider/util" config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" diff --git a/internal/provider/datasources/wireless_network.go b/internal/provider/datasources/wireless_network.go index 0171800a..d8f03c32 100644 --- a/internal/provider/datasources/wireless_network.go +++ b/internal/provider/datasources/wireless_network.go @@ -3,8 +3,8 @@ package datasources import ( "context" - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider/util" config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 144fa6b9..f5223f5b 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -4,8 +4,8 @@ import ( "context" "os" - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider/datasources" - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider/resources" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/datasources" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/resources" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/provider" diff --git a/internal/provider/resources/agent.go b/internal/provider/resources/agent.go index d18bb019..4c6641dd 100644 --- a/internal/provider/resources/agent.go +++ b/internal/provider/resources/agent.go @@ -3,8 +3,8 @@ package resources import ( "context" - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider/util" "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" diff --git a/internal/provider/resources/group.go b/internal/provider/resources/group.go index bcbb48b4..9a58ba4f 100644 --- a/internal/provider/resources/group.go +++ b/internal/provider/resources/group.go @@ -3,8 +3,8 @@ package resources import ( "context" - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider/util" "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -14,6 +14,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" ) +const groupNotFoundErrorString = "not found" + // Ensure the implementation satisfies the expected interfaces. var ( _ resource.Resource = &groupResource{} @@ -64,7 +66,6 @@ func (r *groupResource) Schema( // UXI business logic does not permit moving of groups stringplanmodifier.RequiresReplace(), }, - Computed: true, }, }, } @@ -125,7 +126,11 @@ func (r *groupResource) Create( // Update the state to match the plan (replace with response from client) plan.ID = types.StringValue(group.Id) plan.Name = types.StringValue(group.Name) - plan.ParentGroupId = types.StringValue(group.Parent.Id) + // only update parent if not attached to root node (else leave it as null) + parentGroup, _ := r.getGroup(ctx, group.Parent.Id) + if parentGroup != nil && !util.IsRoot(*parentGroup) { + plan.ParentGroupId = types.StringValue(group.Parent.Id) + } // Set state to fully populated data diags = resp.State.Set(ctx, plan) @@ -148,33 +153,31 @@ func (r *groupResource) Read( return } - request := r.client.ConfigurationAPI. - GroupsGet(ctx). - Id(state.ID.ValueString()) - groupResponse, response, err := util.RetryFor429(request.Execute) - errorPresent, errorDetail := util.RaiseForStatus(response, err) + group, errorDetail := r.getGroup(ctx, state.ID.ValueString()) errorSummary := util.GenerateErrorSummary("read", "uxi_group") - if errorPresent { - resp.Diagnostics.AddError(errorSummary, errorDetail) + if errorDetail != nil { + if *errorDetail == groupNotFoundErrorString { + resp.State.RemoveResource(ctx) + return + } + resp.Diagnostics.AddError(errorSummary, *errorDetail) return } - if len(groupResponse.Items) != 1 { - resp.State.RemoveResource(ctx) - return - } - group := groupResponse.Items[0] - - if util.IsRoot(group) { + if util.IsRoot(*group) { resp.Diagnostics.AddError(errorSummary, "The root group cannot be used as a resource") return } // Update state from client response state.Name = types.StringValue(group.Name) - state.ParentGroupId = types.StringValue(group.Parent.Get().Id) + // only update parent if not attached to root node (else leave it as null) + parentGroup, _ := r.getGroup(ctx, group.Parent.Get().Id) + if parentGroup != nil && !util.IsRoot(*parentGroup) { + state.ParentGroupId = types.StringValue(group.Parent.Get().Id) + } // Set refreshed state diags = resp.State.Set(ctx, &state) @@ -190,9 +193,11 @@ func (r *groupResource) Update( resp *resource.UpdateResponse, ) { // Retrieve values from plan - var plan groupResourceModel + var plan, state groupResourceModel diags := req.Plan.Get(ctx, &plan) resp.Diagnostics.Append(diags...) + diags = req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { return } @@ -254,3 +259,23 @@ func (r *groupResource) ImportState( ) { resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) } + +func (r *groupResource) getGroup( + ctx context.Context, + id string, +) (*config_api_client.GroupsGetItem, *string) { + request := r.client.ConfigurationAPI.GroupsGet(ctx).Id(id) + groupResponse, response, err := util.RetryFor429(request.Execute) + errorPresent, errorDetail := util.RaiseForStatus(response, err) + + if errorPresent { + return nil, &errorDetail + } + + if len(groupResponse.Items) != 1 { + notFound := groupNotFoundErrorString + return nil, ¬Found + } + + return &groupResponse.Items[0], nil +} diff --git a/internal/provider/resources/network_group_assignment.go b/internal/provider/resources/network_group_assignment.go index 56458cb4..0a07d0f3 100644 --- a/internal/provider/resources/network_group_assignment.go +++ b/internal/provider/resources/network_group_assignment.go @@ -2,8 +2,8 @@ package resources import ( "context" - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider/util" "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" diff --git a/internal/provider/resources/sensor.go b/internal/provider/resources/sensor.go index f41fc0f4..23cc5b2f 100644 --- a/internal/provider/resources/sensor.go +++ b/internal/provider/resources/sensor.go @@ -2,8 +2,8 @@ package resources import ( "context" - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider/util" "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" diff --git a/internal/provider/resources/sensor_group_assignment.go b/internal/provider/resources/sensor_group_assignment.go index 8d6d6531..8f54da74 100644 --- a/internal/provider/resources/sensor_group_assignment.go +++ b/internal/provider/resources/sensor_group_assignment.go @@ -3,8 +3,8 @@ package resources import ( "context" - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider/util" config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" diff --git a/internal/provider/resources/service_group_assignment.go b/internal/provider/resources/service_group_assignment.go index 77a8a879..4fc2cb48 100644 --- a/internal/provider/resources/service_group_assignment.go +++ b/internal/provider/resources/service_group_assignment.go @@ -2,8 +2,8 @@ package resources import ( "context" - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider/util" "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" diff --git a/internal/provider/resources/wired_network.go b/internal/provider/resources/wired_network.go index 2078ce01..ce38c985 100644 --- a/internal/provider/resources/wired_network.go +++ b/internal/provider/resources/wired_network.go @@ -3,8 +3,8 @@ package resources import ( "context" - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider/util" "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" diff --git a/internal/provider/resources/wireless_network.go b/internal/provider/resources/wireless_network.go index 7cccb3f4..2244f63a 100644 --- a/internal/provider/resources/wireless_network.go +++ b/internal/provider/resources/wireless_network.go @@ -3,8 +3,8 @@ package resources import ( "context" - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider/util" "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" diff --git a/internal/provider/util/retry.go b/internal/provider/util/retry.go index 75527288..215a105f 100644 --- a/internal/provider/util/retry.go +++ b/internal/provider/util/retry.go @@ -6,7 +6,7 @@ import ( "strconv" "time" - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider/config" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/config" ) func RetryFor429[T any](f func() (T, *http.Response, error)) (T, *http.Response, error) { diff --git a/main.go b/main.go index e0592906..31678c28 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,7 @@ import ( "flag" "log" - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider" "github.com/hashicorp/terraform-plugin-framework/providerserver" ) diff --git a/test/live/provider/provider.go b/test/live/provider/provider.go index 7ae3024f..4f824e29 100644 --- a/test/live/provider/provider.go +++ b/test/live/provider/provider.go @@ -1,8 +1,8 @@ package provider import ( - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/live/util" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider" + "github.com/aruba-uxi/terraform-provider-configuration/test/live/util" "github.com/hashicorp/terraform-plugin-framework/providerserver" "github.com/hashicorp/terraform-plugin-go/tfprotov6" ) diff --git a/test/live/resources/group_test.go b/test/live/resources/group_test.go index 217b311e..50484b7b 100644 --- a/test/live/resources/group_test.go +++ b/test/live/resources/group_test.go @@ -5,8 +5,8 @@ import ( "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/live/provider" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/live/util" + "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" ) @@ -36,7 +36,7 @@ func TestGroupResource(t *testing.T) { resource.TestCheckResourceAttrPtr( "uxi_group.parent", "parent_group_id", - &rootGroup.Id, + nil, ), ), }, diff --git a/test/live/util/util.go b/test/live/util/util.go index a04cbdd0..f8a847dd 100644 --- a/test/live/util/util.go +++ b/test/live/util/util.go @@ -4,8 +4,8 @@ import ( "context" "os" - resources_util "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider/util" "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + resources_util "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" "golang.org/x/oauth2" "golang.org/x/oauth2/clientcredentials" ) diff --git a/test/mocked/data-sources/agent_test.go b/test/mocked/data-sources/agent_test.go index 92f5bd3f..062cd6b0 100644 --- a/test/mocked/data-sources/agent_test.go +++ b/test/mocked/data-sources/agent_test.go @@ -4,8 +4,8 @@ import ( "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" diff --git a/test/mocked/data-sources/group_test.go b/test/mocked/data-sources/group_test.go index cd0ccfac..650c0a8b 100644 --- a/test/mocked/data-sources/group_test.go +++ b/test/mocked/data-sources/group_test.go @@ -5,8 +5,8 @@ import ( "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -27,7 +27,7 @@ func TestGroupDataSource(t *testing.T) { "uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("uid", "", ""), + util.GenerateNonRootGroupResponseModel("uid", "", ""), }, ), 3, @@ -97,7 +97,7 @@ func TestGroupDataSource429Handling(t *testing.T) { "uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("uid", "", ""), + util.GenerateNonRootGroupResponseModel("uid", "", ""), }, ), 3, diff --git a/test/mocked/data-sources/network_group_assignment_test.go b/test/mocked/data-sources/network_group_assignment_test.go index 2ce603ed..9cfe3f17 100644 --- a/test/mocked/data-sources/network_group_assignment_test.go +++ b/test/mocked/data-sources/network_group_assignment_test.go @@ -4,8 +4,8 @@ import ( "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" diff --git a/test/mocked/data-sources/sensor_group_assignment_test.go b/test/mocked/data-sources/sensor_group_assignment_test.go index a0d9c117..b3a5212b 100644 --- a/test/mocked/data-sources/sensor_group_assignment_test.go +++ b/test/mocked/data-sources/sensor_group_assignment_test.go @@ -4,8 +4,8 @@ import ( "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" diff --git a/test/mocked/data-sources/sensor_test.go b/test/mocked/data-sources/sensor_test.go index 986956ad..4c2e0f0c 100644 --- a/test/mocked/data-sources/sensor_test.go +++ b/test/mocked/data-sources/sensor_test.go @@ -4,8 +4,8 @@ import ( "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" diff --git a/test/mocked/data-sources/wired_network_test.go b/test/mocked/data-sources/wired_network_test.go index 65f4a9c9..8b7c7661 100644 --- a/test/mocked/data-sources/wired_network_test.go +++ b/test/mocked/data-sources/wired_network_test.go @@ -4,8 +4,8 @@ import ( "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" "github.com/nbio/st" "github.com/h2non/gock" diff --git a/test/mocked/data-sources/wireless_network_test.go b/test/mocked/data-sources/wireless_network_test.go index 2b581b60..e89e3f7d 100644 --- a/test/mocked/data-sources/wireless_network_test.go +++ b/test/mocked/data-sources/wireless_network_test.go @@ -4,8 +4,8 @@ import ( "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" "github.com/nbio/st" "github.com/h2non/gock" diff --git a/test/mocked/provider/provider.go b/test/mocked/provider/provider.go index a91daa49..b8c5cd1b 100644 --- a/test/mocked/provider/provider.go +++ b/test/mocked/provider/provider.go @@ -1,7 +1,7 @@ package provider import ( - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider" "github.com/hashicorp/terraform-plugin-framework/providerserver" "github.com/hashicorp/terraform-plugin-go/tfprotov6" ) diff --git a/test/mocked/resources/agent_group_assignment_test.go b/test/mocked/resources/agent_group_assignment_test.go index f07a4c8b..fe5247c6 100644 --- a/test/mocked/resources/agent_group_assignment_test.go +++ b/test/mocked/resources/agent_group_assignment_test.go @@ -1,11 +1,11 @@ package resource_test import ( - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" "testing" - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider/resources" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/resources" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) @@ -32,14 +32,16 @@ func TestAgentGroupAssignmentResource(t *testing.T) { // required for group create util.MockPostGroup( util.GenerateGroupRequestModel("group_uid", "", ""), - util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), + util.StructToMap( + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + ), 1, ) util.MockGetGroup( "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 1, @@ -128,7 +130,7 @@ func TestAgentGroupAssignmentResource(t *testing.T) { "group_uid_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), }, ), 1, @@ -137,7 +139,7 @@ func TestAgentGroupAssignmentResource(t *testing.T) { "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 2, @@ -147,7 +149,7 @@ func TestAgentGroupAssignmentResource(t *testing.T) { util.MockPostGroup( util.GenerateGroupRequestModel("group_uid_2", "_2", "_2"), util.StructToMap( - util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), ), 1, ) @@ -250,7 +252,7 @@ func TestAgentGroupAssignmentResource(t *testing.T) { "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 2, @@ -259,7 +261,7 @@ func TestAgentGroupAssignmentResource(t *testing.T) { "group_uid_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), }, ), 1, diff --git a/test/mocked/resources/agent_test.go b/test/mocked/resources/agent_test.go index f62f5203..a4bf77f5 100644 --- a/test/mocked/resources/agent_test.go +++ b/test/mocked/resources/agent_test.go @@ -1,8 +1,8 @@ package resource_test import ( - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" diff --git a/test/mocked/resources/group_test.go b/test/mocked/resources/group_test.go index c00c41f3..4127ac36 100644 --- a/test/mocked/resources/group_test.go +++ b/test/mocked/resources/group_test.go @@ -5,8 +5,8 @@ import ( "testing" config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -29,11 +29,25 @@ func TestGroupResource(t *testing.T) { PreConfig: func() { util.MockPostGroup( util.GenerateGroupRequestModel("uid", "", ""), - util.StructToMap(util.GenerateGroupResponseModel("uid", "", "")), + util.StructToMap(util.GenerateNonRootGroupResponseModel("uid", "", "")), 1, ) - util.MockGetGroup("uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateGroupResponseModel("uid", "", "")}), + util.MockGetGroup("uid", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("uid", "", ""), + }, + ), + 2, + ) + // to indicate the group has a parent + util.MockGetGroup( + "parent_uid", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("parent_uid", "", ""), + }, + ), 1, ) }, @@ -55,8 +69,23 @@ func TestGroupResource(t *testing.T) { // ImportState testing { PreConfig: func() { - util.MockGetGroup("uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateGroupResponseModel("uid", "", "")}), + util.MockGetGroup( + "uid", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("uid", "", ""), + }, + ), + 1, + ) + // to indicate the group has a parent + util.MockGetGroup( + "parent_uid", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("parent_uid", "", ""), + }, + ), 1, ) }, @@ -69,18 +98,33 @@ func TestGroupResource(t *testing.T) { PreConfig: func() { // existing group util.MockGetGroup("uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateGroupResponseModel("uid", "", "")}), + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("uid", "", ""), + }, + ), 1, ) // updated group util.MockUpdateGroup( "uid", map[string]interface{}{"name": "name_2"}, - util.GenerateGroupResponseModel("uid", "_2", ""), + util.GenerateNonRootGroupResponseModel("uid", "_2", ""), 1, ) util.MockGetGroup("uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateGroupResponseModel("uid", "_2", "")}), + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("uid", "_2", ""), + }, + ), + 2, + ) + util.MockGetGroup( + "parent_uid", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("parent_uid", "", ""), + }, + ), 1, ) }, @@ -104,18 +148,21 @@ func TestGroupResource(t *testing.T) { PreConfig: func() { // existing group util.MockGetGroup("uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateGroupResponseModel("uid", "", "")}), + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("uid", "", ""), + }, + ), 1, ) // new group (replacement) util.MockPostGroup( util.GenerateGroupRequestModel("new_uid", "", "_2"), - util.GenerateGroupResponseModel("new_uid", "", "_2"), + util.GenerateNonRootGroupResponseModel("new_uid", "", "_2"), 1, ) util.MockGetGroup("new_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("new_uid", "", "_2"), + util.GenerateNonRootGroupResponseModel("new_uid", "", "_2"), }, ), 1, @@ -143,7 +190,7 @@ func TestGroupResource(t *testing.T) { PreConfig: func() { util.MockGetGroup("new_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("new_uid", "", "_2"), + util.GenerateNonRootGroupResponseModel("new_uid", "", "_2"), }, ), 1, @@ -193,6 +240,84 @@ func TestRootGroupResource(t *testing.T) { }`, ExpectError: regexp.MustCompile(`The root group cannot be used as a resource`), }, + // Creating a group attached to the root + { + PreConfig: func() { + util.MockPostGroup( + map[string]interface{}{"name": "name"}, + map[string]interface{}{ + "id": "uid", + "name": "name", + "parent": map[string]interface{}{"id": "root"}, + "path": "uid", + "type": "networking-uxi/group", + }, + 1, + ) + util.MockGetGroup( + "uid", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + { + "id": "uid", + "name": "name", + "parent": map[string]interface{}{"id": "root"}, + "path": "uid", + "type": "networking-uxi/group", + }, + }, + ), + 1, + ) + // to indicate the group has the root group as a parent + util.MockGetGroup( + "root", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + { + "id": "root", + "name": "root", + "path": "root", + "type": "networking-uxi/group", + }, + }, + ), + 1, + ) + }, + Config: provider.ProviderConfig + ` + resource "uxi_group" "my_group" { + name = "name" + }`, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("uxi_group.my_group", "id", "uid"), + resource.TestCheckResourceAttr("uxi_group.my_group", "name", "name"), + resource.TestCheckNoResourceAttr("uxi_group.my_group", "parent_group_id"), + ), + }, + // Delete testing + { + PreConfig: func() { + // existing group + util.MockGetGroup( + "uid", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + { + "id": "uid", + "name": "name", + "parent": map[string]interface{}{"id": "root"}, + "path": "uid", + "type": "networking-uxi/group", + }, + }, + ), + 1, + ) + util.MockDeleteGroup("uid", 1) + }, + Config: provider.ProviderConfig, + }, }, }) @@ -217,14 +342,24 @@ func TestGroupResource429Handling(t *testing.T) { SetHeaders(util.RateLimitingHeaders) util.MockPostGroup( util.GenerateGroupRequestModel("uid", "", ""), - util.GenerateGroupResponseModel("uid", "", ""), + util.GenerateNonRootGroupResponseModel("uid", "", ""), 1, ) util.MockGetGroup( "uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("uid", "", ""), + util.GenerateNonRootGroupResponseModel("uid", "", ""), + }, + ), + 2, + ) + // to indicate the group has a parent + util.MockGetGroup( + "parent_uid", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("parent_uid", "", ""), }, ), 1, @@ -248,7 +383,10 @@ func TestGroupResource429Handling(t *testing.T) { PreConfig: func() { // existing group util.MockGetGroup("uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateGroupResponseModel("uid", "", "")}), + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("uid", "", ""), + }, + ), 1, ) // new group @@ -259,11 +397,24 @@ func TestGroupResource429Handling(t *testing.T) { util.MockUpdateGroup( "uid", map[string]interface{}{"name": "name_2"}, - util.GenerateGroupResponseModel("uid", "_2", ""), + util.GenerateNonRootGroupResponseModel("uid", "_2", ""), 1, ) util.MockGetGroup("uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateGroupResponseModel("uid", "_2", "")}), + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("uid", "_2", ""), + }, + ), + 2, + ) + // to indicate the group has a parent + util.MockGetGroup( + "parent_uid", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("parent_uid", "", ""), + }, + ), 1, ) }, @@ -284,7 +435,10 @@ func TestGroupResource429Handling(t *testing.T) { { PreConfig: func() { util.MockGetGroup("uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateGroupResponseModel("uid", "", "")}), + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("uid", "", ""), + }, + ), 1, ) util.MockDeleteGroup("uid", 1) @@ -382,14 +536,24 @@ func TestGroupResourceHttpErrorHandling(t *testing.T) { PreConfig: func() { util.MockPostGroup( util.GenerateGroupRequestModel("uid", "", ""), - util.GenerateGroupResponseModel("uid", "", ""), + util.GenerateNonRootGroupResponseModel("uid", "", ""), 1, ) util.MockGetGroup( "uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("uid", "", ""), + util.GenerateNonRootGroupResponseModel("uid", "", ""), + }, + ), + 2, + ) + // to indicate the group has a parent + util.MockGetGroup( + "parent_uid", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("parent_uid", "", ""), }, ), 1, @@ -409,7 +573,10 @@ func TestGroupResourceHttpErrorHandling(t *testing.T) { PreConfig: func() { // existing group util.MockGetGroup("uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateGroupResponseModel("uid", "", "")}), + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("uid", "", ""), + }, + ), 1, ) // new group - with error @@ -437,7 +604,10 @@ func TestGroupResourceHttpErrorHandling(t *testing.T) { PreConfig: func() { // existing group util.MockGetGroup("uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateGroupResponseModel("uid", "", "")}), + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("uid", "", ""), + }, + ), 1, ) // delete group - with error @@ -461,7 +631,10 @@ func TestGroupResourceHttpErrorHandling(t *testing.T) { PreConfig: func() { // existing group util.MockGetGroup("uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateGroupResponseModel("uid", "", "")}), + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("uid", "", ""), + }, + ), 1, ) // delete group diff --git a/test/mocked/resources/network_group_assignment_test.go b/test/mocked/resources/network_group_assignment_test.go index 6ccd0b69..b5aa2ef0 100644 --- a/test/mocked/resources/network_group_assignment_test.go +++ b/test/mocked/resources/network_group_assignment_test.go @@ -4,8 +4,8 @@ import ( "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -36,12 +36,14 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { // required for group create util.MockPostGroup( util.GenerateGroupRequestModel("group_uid", "", ""), - util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), + util.StructToMap( + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + ), 1, ) util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 2, @@ -155,7 +157,7 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { "group_uid_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), }, ), 1, @@ -164,7 +166,7 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 3, @@ -174,7 +176,7 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { util.MockPostGroup( util.GenerateGroupRequestModel("group_uid_2", "_2", "_2"), util.StructToMap( - util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), ), 1, ) @@ -294,14 +296,14 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { ) util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 2, ) util.MockGetGroup("group_uid_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), }, ), 1, @@ -383,14 +385,16 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { // required for group create util.MockPostGroup( util.GenerateGroupRequestModel("group_uid", "", ""), - util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), + util.StructToMap( + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + ), 1, ) util.MockGetGroup( "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 1, @@ -506,7 +510,7 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { util.MockPostGroup( util.GenerateGroupRequestModel("group_uid_2", "_2", "_2"), util.StructToMap( - util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), ), 1, ) @@ -514,7 +518,7 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { "group_uid_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), }, ), 1, @@ -524,7 +528,7 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 3, @@ -646,7 +650,7 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 2, @@ -655,7 +659,7 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { "group_uid_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), }, ), 1, @@ -737,12 +741,14 @@ func TestNetworkGroupAssignmentResource429Handling(t *testing.T) { // required for group create util.MockPostGroup( util.GenerateGroupRequestModel("group_uid", "", ""), - util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), + util.StructToMap( + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + ), 1, ) util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 2, @@ -823,7 +829,7 @@ func TestNetworkGroupAssignmentResource429Handling(t *testing.T) { ) util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 1, @@ -892,12 +898,14 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // required for group create util.MockPostGroup( util.GenerateGroupRequestModel("group_uid", "", ""), - util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), + util.StructToMap( + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + ), 1, ) util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 2, @@ -954,12 +962,14 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // required for group create util.MockPostGroup( util.GenerateGroupRequestModel("group_uid", "", ""), - util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), + util.StructToMap( + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + ), 1, ) util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 2, @@ -1015,12 +1025,14 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // required for group create util.MockPostGroup( util.GenerateGroupRequestModel("group_uid", "", ""), - util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), + util.StructToMap( + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + ), 1, ) util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 2, @@ -1083,12 +1095,14 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // required for group create util.MockPostGroup( util.GenerateGroupRequestModel("group_uid", "", ""), - util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), + util.StructToMap( + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + ), 1, ) util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 2, @@ -1161,7 +1175,7 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { ) util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 1, @@ -1217,7 +1231,7 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { ) util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 1, diff --git a/test/mocked/resources/sensor_group_assignment_test.go b/test/mocked/resources/sensor_group_assignment_test.go index 290774e7..216b5f04 100644 --- a/test/mocked/resources/sensor_group_assignment_test.go +++ b/test/mocked/resources/sensor_group_assignment_test.go @@ -4,8 +4,8 @@ import ( "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -34,14 +34,16 @@ func TestSensorGroupAssignmentResource(t *testing.T) { // required for group create util.MockPostGroup( util.GenerateGroupRequestModel("group_uid", "", ""), - util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), + util.StructToMap( + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + ), 1, ) util.MockGetGroup( "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 1, @@ -155,7 +157,7 @@ func TestSensorGroupAssignmentResource(t *testing.T) { "group_uid_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), }, ), 1, @@ -164,7 +166,7 @@ func TestSensorGroupAssignmentResource(t *testing.T) { "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 2, @@ -175,7 +177,7 @@ func TestSensorGroupAssignmentResource(t *testing.T) { util.MockPostGroup( util.GenerateGroupRequestModel("group_uid_2", "_2", "_2"), util.StructToMap( - util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), ), 1, ) @@ -285,7 +287,7 @@ func TestSensorGroupAssignmentResource(t *testing.T) { "group_uid_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), }, ), 1, @@ -294,7 +296,7 @@ func TestSensorGroupAssignmentResource(t *testing.T) { "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 1, @@ -362,14 +364,16 @@ func TestSensorGroupAssignmentResource429Handling(t *testing.T) { // required for group create util.MockPostGroup( util.GenerateGroupRequestModel("group_uid", "", ""), - util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), + util.StructToMap( + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + ), 1, ) util.MockGetGroup( "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 1, @@ -446,7 +450,7 @@ func TestSensorGroupAssignmentResource429Handling(t *testing.T) { "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 1, @@ -522,14 +526,16 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // required for group create util.MockPostGroup( util.GenerateGroupRequestModel("group_uid", "", ""), - util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), + util.StructToMap( + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + ), 1, ) util.MockGetGroup( "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 1, @@ -588,14 +594,16 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // required for group create util.MockPostGroup( util.GenerateGroupRequestModel("group_uid", "", ""), - util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), + util.StructToMap( + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + ), 1, ) util.MockGetGroup( "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 1, @@ -653,14 +661,16 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // required for group create util.MockPostGroup( util.GenerateGroupRequestModel("group_uid", "", ""), - util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), + util.StructToMap( + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + ), 1, ) util.MockGetGroup( "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 1, @@ -725,14 +735,16 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // required for group create util.MockPostGroup( util.GenerateGroupRequestModel("group_uid", "", ""), - util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), + util.StructToMap( + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + ), 1, ) util.MockGetGroup( "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 1, @@ -801,7 +813,7 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 1, @@ -856,7 +868,7 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 1, diff --git a/test/mocked/resources/sensor_test.go b/test/mocked/resources/sensor_test.go index de87b615..fd70f8e3 100644 --- a/test/mocked/resources/sensor_test.go +++ b/test/mocked/resources/sensor_test.go @@ -1,8 +1,8 @@ package resource_test import ( - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" "regexp" "testing" diff --git a/test/mocked/resources/service_test.go b/test/mocked/resources/service_test.go index 787043af..9c8cdc75 100644 --- a/test/mocked/resources/service_test.go +++ b/test/mocked/resources/service_test.go @@ -1,12 +1,12 @@ package resource_test import ( - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider/resources" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/resources" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/tfversion" diff --git a/test/mocked/resources/service_test_group_assignment_test.go b/test/mocked/resources/service_test_group_assignment_test.go index ed3a7319..0e8991ab 100644 --- a/test/mocked/resources/service_test_group_assignment_test.go +++ b/test/mocked/resources/service_test_group_assignment_test.go @@ -5,10 +5,10 @@ import ( "testing" config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider/resources" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/resources" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -33,14 +33,16 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { // required for group create util.MockPostGroup( util.GenerateGroupRequestModel("group_uid", "", ""), - util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), + util.StructToMap( + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + ), 1, ) util.MockGetGroup( "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 1, @@ -125,7 +127,7 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { "group_uid_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), }, ), 1, @@ -134,7 +136,7 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 3, @@ -147,7 +149,7 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { util.MockPostGroup( util.GenerateGroupRequestModel("group_uid_2", "_2", "_2"), util.StructToMap( - util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), ), 1, ) @@ -238,7 +240,7 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 1, @@ -247,7 +249,7 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { "group_uid_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), }, ), 1, @@ -302,14 +304,16 @@ func TestServiceTestGroupAssignmentResource429Handling(t *testing.T) { // required for group create util.MockPostGroup( util.GenerateGroupRequestModel("group_uid", "", ""), - util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), + util.StructToMap( + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + ), 1, ) util.MockGetGroup( "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 1, @@ -380,7 +384,7 @@ func TestServiceTestGroupAssignmentResource429Handling(t *testing.T) { "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 1, @@ -422,14 +426,16 @@ func TestServiceTestGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // required for group create util.MockPostGroup( util.GenerateGroupRequestModel("group_uid", "", ""), - util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), + util.StructToMap( + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + ), 1, ) util.MockGetGroup( "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 1, @@ -477,7 +483,7 @@ func TestServiceTestGroupAssignmentResourceHttpErrorHandling(t *testing.T) { "group_uid", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_uid", "", ""), }, ), 1, diff --git a/test/mocked/resources/wired_network_test.go b/test/mocked/resources/wired_network_test.go index fde223d3..35231125 100644 --- a/test/mocked/resources/wired_network_test.go +++ b/test/mocked/resources/wired_network_test.go @@ -1,8 +1,8 @@ package resource_test import ( - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" "regexp" "testing" diff --git a/test/mocked/resources/wireless_network_test.go b/test/mocked/resources/wireless_network_test.go index 81c0a38c..a803aaf9 100644 --- a/test/mocked/resources/wireless_network_test.go +++ b/test/mocked/resources/wireless_network_test.go @@ -1,8 +1,8 @@ package resource_test import ( - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration-api/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" "regexp" "testing" diff --git a/test/mocked/util/utils.go b/test/mocked/util/utils.go index 1291ce97..efd7a77b 100644 --- a/test/mocked/util/utils.go +++ b/test/mocked/util/utils.go @@ -4,7 +4,7 @@ import ( "encoding/json" "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - "github.com/aruba-uxi/terraform-provider-configuration-api/internal/provider/resources" + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/resources" "github.com/h2non/gock" ) @@ -52,7 +52,7 @@ func GenerateMockedAgentResponseModel(uid string, postfix string) resources.Agen } } -func GenerateGroupResponseModel( +func GenerateNonRootGroupResponseModel( uid string, nonReplacementFieldPostfix string, replacementFieldPostfix string,