From bcee980cf3734c4fe05abf6402945d3ec4b96db6 Mon Sep 17 00:00:00 2001 From: 1riatsila1 Date: Wed, 9 Oct 2024 09:00:51 +0200 Subject: [PATCH] Fix breaking changes --- .../data-sources/network_group_assignment.go | 10 +- .../data-sources/sensor_group_assignment.go | 10 +- .../provider/data-sources/wired_network.go | 10 +- .../provider/data-sources/wireless_network.go | 8 +- .../provider/resources/group.go | 14 +-- .../resources/network_group_assignment.go | 8 +- .../resources/sensor_group_assignment.go | 8 +- .../provider/resources/wired_network.go | 6 +- .../provider/resources/wireless_network.go | 6 +- .../network_group_assignment_test.go | 4 +- .../sensor_group_assignment_test.go | 4 +- .../test/data-sources/wired_group_test.go | 4 +- .../test/data-sources/wireless_group_test.go | 4 +- .../network_group_assignment_test.go | 44 ++++---- .../resources/sensor_group_assignment_test.go | 10 +- .../test/resources/wired_network_test.go | 8 +- .../test/resources/wireless_network_test.go | 10 +- pkg/config-api-provider/test/util/utils.go | 104 ++++++------------ 18 files changed, 118 insertions(+), 154 deletions(-) diff --git a/pkg/config-api-provider/provider/data-sources/network_group_assignment.go b/pkg/config-api-provider/provider/data-sources/network_group_assignment.go index d358b836..55c94b3a 100644 --- a/pkg/config-api-provider/provider/data-sources/network_group_assignment.go +++ b/pkg/config-api-provider/provider/data-sources/network_group_assignment.go @@ -74,7 +74,7 @@ func (d *networkGroupAssignmentDataSource) Read(ctx context.Context, req datasou Uid(state.Filter.NetworkGroupAssignmentID) networkGroupAssignmentResponse, _, err := util.RetryFor429(request.Execute) - if err != nil || len(networkGroupAssignmentResponse.NetworkGroupAssignments) != 1 { + if err != nil || len(networkGroupAssignmentResponse.Items) != 1 { resp.Diagnostics.AddError( "Error reading Network Group Assignment", "Could not retrieve Network Group Assignment, unexpected error: "+err.Error(), @@ -82,10 +82,10 @@ func (d *networkGroupAssignmentDataSource) Read(ctx context.Context, req datasou return } - networkGroupAssignment := networkGroupAssignmentResponse.NetworkGroupAssignments[0] - state.ID = types.StringValue(networkGroupAssignment.Uid) - state.NetworkID = types.StringValue(networkGroupAssignment.NetworkUid) - state.GroupID = types.StringValue(networkGroupAssignment.GroupUid) + networkGroupAssignment := networkGroupAssignmentResponse.Items[0] + state.ID = types.StringValue(networkGroupAssignment.Id) + state.NetworkID = types.StringValue(networkGroupAssignment.Network.Id) + state.GroupID = types.StringValue(networkGroupAssignment.Group.Id) diags = resp.State.Set(ctx, &state) resp.Diagnostics.Append(diags...) diff --git a/pkg/config-api-provider/provider/data-sources/sensor_group_assignment.go b/pkg/config-api-provider/provider/data-sources/sensor_group_assignment.go index 31411a0b..e4cacac4 100644 --- a/pkg/config-api-provider/provider/data-sources/sensor_group_assignment.go +++ b/pkg/config-api-provider/provider/data-sources/sensor_group_assignment.go @@ -76,7 +76,7 @@ func (d *sensorGroupAssignmentDataSource) Read(ctx context.Context, req datasour Uid(state.Filter.SensorGroupAssignmentID) sensorGroupAssignmentResponse, _, err := util.RetryFor429(request.Execute) - if err != nil || len(sensorGroupAssignmentResponse.SensorGroupAssignments) != 1 { + if err != nil || len(sensorGroupAssignmentResponse.Items) != 1 { resp.Diagnostics.AddError( "Error reading Sensor Group Assignment", "Could not retrieve Sensor Group Assignment, unexpected error: "+err.Error(), @@ -84,10 +84,10 @@ func (d *sensorGroupAssignmentDataSource) Read(ctx context.Context, req datasour return } - sensorGroupAssignment := sensorGroupAssignmentResponse.SensorGroupAssignments[0] - state.ID = types.StringValue(sensorGroupAssignment.Uid) - state.SensorID = types.StringValue(sensorGroupAssignment.SensorUid) - state.GroupID = types.StringValue(sensorGroupAssignment.GroupUid) + sensorGroupAssignment := sensorGroupAssignmentResponse.Items[0] + state.ID = types.StringValue(sensorGroupAssignment.Id) + state.SensorID = types.StringValue(sensorGroupAssignment.Sensor.Id) + state.GroupID = types.StringValue(sensorGroupAssignment.Group.Id) // Set state diags = resp.State.Set(ctx, &state) diff --git a/pkg/config-api-provider/provider/data-sources/wired_network.go b/pkg/config-api-provider/provider/data-sources/wired_network.go index c360be1c..42a221b6 100644 --- a/pkg/config-api-provider/provider/data-sources/wired_network.go +++ b/pkg/config-api-provider/provider/data-sources/wired_network.go @@ -101,7 +101,7 @@ func (d *wiredNetworkDataSource) Read(ctx context.Context, req datasource.ReadRe Uid(state.Filter.WiredNetworkID) networkResponse, _, err := util.RetryFor429(request.Execute) - if err != nil || len(networkResponse.WiredNetworks) != 1 { + if err != nil || len(networkResponse.Items) != 1 { resp.Diagnostics.AddError( "Error reading Wired Network", "Could not retrieve Wired Network, unexpected error: "+err.Error(), @@ -109,16 +109,16 @@ func (d *wiredNetworkDataSource) Read(ctx context.Context, req datasource.ReadRe return } - network := networkResponse.WiredNetworks[0] - state.ID = types.StringValue(network.Uid) - state.Alias = types.StringValue(network.Alias) + network := networkResponse.Items[0] + state.ID = types.StringValue(network.Id) + state.Alias = types.StringValue(network.Name) state.IpVersion = types.StringValue(network.IpVersion) state.Security = types.StringValue(*network.Security.Get()) state.DnsLookupDomain = types.StringValue(*network.DnsLookupDomain.Get()) state.DisableEdns = types.BoolValue(network.DisableEdns) state.UseDns64 = types.BoolValue(network.UseDns64) state.ExternalConnectivity = types.BoolValue(network.ExternalConnectivity) - state.VlanId = types.Int64Value(int64(*network.VlanId.Get())) + state.VlanId = types.Int64Value(int64(*network.VLanId.Get())) // Set state diags = resp.State.Set(ctx, &state) diff --git a/pkg/config-api-provider/provider/data-sources/wireless_network.go b/pkg/config-api-provider/provider/data-sources/wireless_network.go index c136858f..5128a781 100644 --- a/pkg/config-api-provider/provider/data-sources/wireless_network.go +++ b/pkg/config-api-provider/provider/data-sources/wireless_network.go @@ -109,7 +109,7 @@ func (d *wirelessNetworkDataSource) Read(ctx context.Context, req datasource.Rea Uid(state.Filter.WirelessNetworkID) networkResponse, _, err := util.RetryFor429(request.Execute) - if err != nil || len(networkResponse.WirelessNetworks) != 1 { + if err != nil || len(networkResponse.Items) != 1 { resp.Diagnostics.AddError( "Error reading Wireless Network", "Could not retrieve Wireless Network, unexpected error: "+err.Error(), @@ -117,10 +117,10 @@ func (d *wirelessNetworkDataSource) Read(ctx context.Context, req datasource.Rea return } - network := networkResponse.WirelessNetworks[0] - state.ID = types.StringValue(network.Uid) + network := networkResponse.Items[0] + state.ID = types.StringValue(network.Id) state.Ssid = types.StringValue(network.Ssid) - state.Alias = types.StringValue(network.Alias) + state.Alias = types.StringValue(network.Name) state.IpVersion = types.StringValue(network.IpVersion) state.Security = types.StringValue(*network.Security.Get()) state.Hidden = types.BoolValue(network.Hidden) diff --git a/pkg/config-api-provider/provider/resources/group.go b/pkg/config-api-provider/provider/resources/group.go index ef16d3eb..32b6e840 100644 --- a/pkg/config-api-provider/provider/resources/group.go +++ b/pkg/config-api-provider/provider/resources/group.go @@ -109,9 +109,9 @@ func (r *groupResource) Create(ctx context.Context, req resource.CreateRequest, } // Update the state to match the plan (replace with response from client) - plan.ID = types.StringValue(group.Uid) + plan.ID = types.StringValue(group.Id) plan.Name = types.StringValue(group.Name) - plan.ParentGroupId = types.StringValue(group.ParentUid) + plan.ParentGroupId = types.StringValue(group.Parent.Id) // Set state to fully populated data diags = resp.State.Set(ctx, plan) @@ -178,7 +178,7 @@ func (r *groupResource) Update(ctx context.Context, req resource.UpdateRequest, // Update the state to match the plan (replace with response from client) plan.Name = types.StringValue(group.Name) - plan.ParentGroupId = types.StringValue(group.ParentUid) + plan.ParentGroupId = types.StringValue(group.Parent.Id) // Set state to fully populated data diags = resp.State.Set(ctx, plan) @@ -210,9 +210,9 @@ var UpdateGroup = func(request GroupUpdateRequestModel) config_api_client.Groups parent_uid := "mock_parent_uid" return config_api_client.GroupsPostResponse{ - Uid: "mock_uid", - Name: "mock_name", - ParentUid: parent_uid, - Path: "mock_path", + Id: "mock_uid", + Name: "mock_name", + Parent: *config_api_client.NewParent(parent_uid), + Path: "mock_path", } } diff --git a/pkg/config-api-provider/provider/resources/network_group_assignment.go b/pkg/config-api-provider/provider/resources/network_group_assignment.go index d7f56acc..00944b98 100644 --- a/pkg/config-api-provider/provider/resources/network_group_assignment.go +++ b/pkg/config-api-provider/provider/resources/network_group_assignment.go @@ -134,18 +134,18 @@ func (r *networkGroupAssignmentResource) Read(ctx context.Context, req resource. Uid(state.ID.ValueString()) networkGroupAssignmentResponse, _, err := util.RetryFor429(request.Execute) - if err != nil || len(networkGroupAssignmentResponse.NetworkGroupAssignments) != 1 { + if err != nil || len(networkGroupAssignmentResponse.Items) != 1 { resp.Diagnostics.AddError( "Error reading Network Group Assignment", "Could not retrieve Network Group Assignment, unexpected error: "+err.Error(), ) return } - networkGroupAssignment := networkGroupAssignmentResponse.NetworkGroupAssignments[0] + networkGroupAssignment := networkGroupAssignmentResponse.Items[0] // Update state from client response - state.GroupID = types.StringValue(networkGroupAssignment.GroupUid) - state.NetworkID = types.StringValue(networkGroupAssignment.NetworkUid) + state.GroupID = types.StringValue(networkGroupAssignment.Group.Id) + state.NetworkID = types.StringValue(networkGroupAssignment.Network.Id) // Set refreshed state diags = resp.State.Set(ctx, &state) diff --git a/pkg/config-api-provider/provider/resources/sensor_group_assignment.go b/pkg/config-api-provider/provider/resources/sensor_group_assignment.go index 1f0c5183..eb095713 100644 --- a/pkg/config-api-provider/provider/resources/sensor_group_assignment.go +++ b/pkg/config-api-provider/provider/resources/sensor_group_assignment.go @@ -139,7 +139,7 @@ func (r *sensorGroupAssignmentResource) Read(ctx context.Context, req resource.R Uid(state.ID.ValueString()) sensorGroupAssignmentResponse, _, err := util.RetryFor429(request.Execute) - if err != nil || len(sensorGroupAssignmentResponse.SensorGroupAssignments) != 1 { + if err != nil || len(sensorGroupAssignmentResponse.Items) != 1 { resp.Diagnostics.AddError( "Error reading Sensor Group Assignment", "Could not retrieve Sensor Group Assignment, unexpected error: "+err.Error(), @@ -147,11 +147,11 @@ func (r *sensorGroupAssignmentResource) Read(ctx context.Context, req resource.R return } - sensorGroupAssignment := sensorGroupAssignmentResponse.SensorGroupAssignments[0] + sensorGroupAssignment := sensorGroupAssignmentResponse.Items[0] // Update state from client response - state.GroupID = types.StringValue(sensorGroupAssignment.GroupUid) - state.SensorID = types.StringValue(sensorGroupAssignment.SensorUid) + state.GroupID = types.StringValue(sensorGroupAssignment.Group.Id) + state.SensorID = types.StringValue(sensorGroupAssignment.Sensor.Id) // Set refreshed state diags = resp.State.Set(ctx, &state) diff --git a/pkg/config-api-provider/provider/resources/wired_network.go b/pkg/config-api-provider/provider/resources/wired_network.go index 9d19a013..19e4d41e 100644 --- a/pkg/config-api-provider/provider/resources/wired_network.go +++ b/pkg/config-api-provider/provider/resources/wired_network.go @@ -94,7 +94,7 @@ func (r *wiredNetworkResource) Read(ctx context.Context, req resource.ReadReques Uid(state.ID.ValueString()) networkResponse, _, err := util.RetryFor429(request.Execute) - if err != nil || len(networkResponse.WiredNetworks) != 1 { + if err != nil || len(networkResponse.Items) != 1 { resp.Diagnostics.AddError( "Error reading Wired Network", "Could not retrieve Wired Network, unexpected error: "+err.Error(), @@ -102,10 +102,10 @@ func (r *wiredNetworkResource) Read(ctx context.Context, req resource.ReadReques return } - network := networkResponse.WiredNetworks[0] + network := networkResponse.Items[0] // Update state from client response - state.Alias = types.StringValue(network.Alias) + state.Alias = types.StringValue(network.Name) // Set refreshed state diags = resp.State.Set(ctx, &state) diff --git a/pkg/config-api-provider/provider/resources/wireless_network.go b/pkg/config-api-provider/provider/resources/wireless_network.go index 8280da00..8de52291 100644 --- a/pkg/config-api-provider/provider/resources/wireless_network.go +++ b/pkg/config-api-provider/provider/resources/wireless_network.go @@ -94,7 +94,7 @@ func (r *wirelessNetworkResource) Read(ctx context.Context, req resource.ReadReq Uid(state.ID.ValueString()) networkResponse, _, err := util.RetryFor429(request.Execute) - if err != nil || len(networkResponse.WirelessNetworks) != 1 { + if err != nil || len(networkResponse.Items) != 1 { resp.Diagnostics.AddError( "Error reading Wireless Networks", "Could not retrieve Wireless Network, unexpected error: "+err.Error(), @@ -102,10 +102,10 @@ func (r *wirelessNetworkResource) Read(ctx context.Context, req resource.ReadReq return } - network := networkResponse.WirelessNetworks[0] + network := networkResponse.Items[0] // Update state from client response - state.Alias = types.StringValue(network.Alias) + state.Alias = types.StringValue(network.Name) // Set refreshed state diags = resp.State.Set(ctx, &state) diff --git a/pkg/config-api-provider/test/data-sources/network_group_assignment_test.go b/pkg/config-api-provider/test/data-sources/network_group_assignment_test.go index 878d716d..7c64398a 100644 --- a/pkg/config-api-provider/test/data-sources/network_group_assignment_test.go +++ b/pkg/config-api-provider/test/data-sources/network_group_assignment_test.go @@ -23,7 +23,7 @@ func TestNetworkGroupAssignmentDataSource(t *testing.T) { PreConfig: func() { util.MockGetNetworkGroupAssignment( "uid", - util.GenerateNetworkGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("uid", "")}), 3, ) }, @@ -67,7 +67,7 @@ func TestNetworkGroupAssignmentSource429Handling(t *testing.T) { }) util.MockGetNetworkGroupAssignment( "uid", - util.GenerateNetworkGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("uid", "")}), 3, ) }, diff --git a/pkg/config-api-provider/test/data-sources/sensor_group_assignment_test.go b/pkg/config-api-provider/test/data-sources/sensor_group_assignment_test.go index 99651426..2131d7fc 100644 --- a/pkg/config-api-provider/test/data-sources/sensor_group_assignment_test.go +++ b/pkg/config-api-provider/test/data-sources/sensor_group_assignment_test.go @@ -23,7 +23,7 @@ func TestSensorGroupAssignmentDataSource(t *testing.T) { PreConfig: func() { util.MockGetSensorGroupAssignment( "uid", - util.GenerateSensorGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentGetResponse("uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentGetResponse("uid", "")}), 3, ) }, @@ -67,7 +67,7 @@ func TestSensorGroupAssignmentSource429Handling(t *testing.T) { }) util.MockGetSensorGroupAssignment( "uid", - util.GenerateSensorGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentGetResponse("uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentGetResponse("uid", "")}), 3, ) }, diff --git a/pkg/config-api-provider/test/data-sources/wired_group_test.go b/pkg/config-api-provider/test/data-sources/wired_group_test.go index 0de3cb92..524cac21 100644 --- a/pkg/config-api-provider/test/data-sources/wired_group_test.go +++ b/pkg/config-api-provider/test/data-sources/wired_group_test.go @@ -24,7 +24,7 @@ func TestWiredNetworkDataSource(t *testing.T) { PreConfig: func() { util.MockGetWiredNetwork( "uid", - util.GenerateWiredNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}), 3, ) }, @@ -74,7 +74,7 @@ func TestWiredNetworkDataSource429Handling(t *testing.T) { }) util.MockGetWiredNetwork( "uid", - util.GenerateWiredNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}), 3, ) }, diff --git a/pkg/config-api-provider/test/data-sources/wireless_group_test.go b/pkg/config-api-provider/test/data-sources/wireless_group_test.go index 4170b338..d56bc0b6 100644 --- a/pkg/config-api-provider/test/data-sources/wireless_group_test.go +++ b/pkg/config-api-provider/test/data-sources/wireless_group_test.go @@ -24,7 +24,7 @@ func TestWirelessNetworkDataSource(t *testing.T) { PreConfig: func() { util.MockGetWirelessNetwork( "uid", - util.GenerateWirelessNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}), 3, ) }, @@ -76,7 +76,7 @@ func TestWirelessNetworkDataSource429Handling(t *testing.T) { }) util.MockGetWirelessNetwork( "uid", - util.GenerateWirelessNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}), 3, ) }, diff --git a/pkg/config-api-provider/test/resources/network_group_assignment_test.go b/pkg/config-api-provider/test/resources/network_group_assignment_test.go index 5cf7ff2e..0cdb1d66 100644 --- a/pkg/config-api-provider/test/resources/network_group_assignment_test.go +++ b/pkg/config-api-provider/test/resources/network_group_assignment_test.go @@ -23,7 +23,7 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { PreConfig: func() { util.MockGetWiredNetwork( "network_uid", - util.GenerateWiredNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("network_uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("network_uid", "")}), 2, ) @@ -40,7 +40,7 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { } util.MockGetNetworkGroupAssignment( "network_group_assignment_uid", - util.GenerateNetworkGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}), 1, ) }, @@ -75,7 +75,7 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { PreConfig: func() { util.MockGetNetworkGroupAssignment( "network_group_assignment_uid", - util.GenerateNetworkGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}), 1, ) }, @@ -88,12 +88,12 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { PreConfig: func() { util.MockGetWiredNetwork( "network_uid_2", - util.GenerateWiredNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("network_uid_2", "_2")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("network_uid_2", "_2")}), 2, ) util.MockGetWiredNetwork( "network_uid", - util.GenerateWiredNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("network_uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("network_uid", "")}), 2, ) util.MockGetGroup( @@ -116,12 +116,12 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { } util.MockGetNetworkGroupAssignment( "network_group_assignment_uid_2", - util.GenerateNetworkGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid_2", "_2")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid_2", "_2")}), 2, ) util.MockGetNetworkGroupAssignment( "network_group_assignment_uid", - util.GenerateNetworkGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}), 2, ) }, @@ -172,12 +172,12 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { PreConfig: func() { util.MockGetWiredNetwork( "network_uid_2", - util.GenerateWiredNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("network_uid_2", "_2")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("network_uid_2", "_2")}), 1, ) util.MockGetWiredNetwork( "network_uid", - util.GenerateWiredNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("network_uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("network_uid", "")}), 1, ) util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( @@ -190,12 +190,12 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { ) util.MockGetNetworkGroupAssignment( "network_group_assignment_uid_2", - util.GenerateNetworkGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid_2", "_2")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid_2", "_2")}), 1, ) util.MockGetNetworkGroupAssignment( "network_group_assignment_uid", - util.GenerateNetworkGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}), 1, ) }, @@ -237,7 +237,7 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { // required for network import util.MockGetWirelessNetwork( "network_uid", - util.GenerateWirelessNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("network_uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("network_uid", "")}), 2, ) // required for group create @@ -254,7 +254,7 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { } util.MockGetNetworkGroupAssignment( "network_group_assignment_uid", - util.GenerateNetworkGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}), 1, ) }, @@ -289,7 +289,7 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { PreConfig: func() { util.MockGetNetworkGroupAssignment( "network_group_assignment_uid", - util.GenerateNetworkGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}), 1, ) }, @@ -302,12 +302,12 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { PreConfig: func() { util.MockGetWirelessNetwork( "network_uid_2", - util.GenerateWirelessNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("network_uid_2", "_2")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("network_uid_2", "_2")}), 2, ) util.MockGetWirelessNetwork( "network_uid", - util.GenerateWirelessNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("network_uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("network_uid", "")}), 2, ) @@ -328,12 +328,12 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { // required for network group assignment create util.MockGetNetworkGroupAssignment( "network_group_assignment_uid_2", - util.GenerateNetworkGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid_2", "_2")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid_2", "_2")}), 2, ) util.MockGetNetworkGroupAssignment( "network_group_assignment_uid", - util.GenerateNetworkGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}), 2, ) resources.CreateNetworkGroupAssignment = func(request resources.NetworkGroupAssignmentRequestModel) resources.NetworkGroupAssignmentResponseModel { @@ -387,12 +387,12 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { PreConfig: func() { util.MockGetWirelessNetwork( "network_uid_2", - util.GenerateWirelessNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("network_uid_2", "_2")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("network_uid_2", "_2")}), 1, ) util.MockGetWirelessNetwork( "network_uid", - util.GenerateWirelessNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("network_uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("network_uid", "")}), 1, ) util.MockGetGroup( @@ -407,12 +407,12 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { ) util.MockGetNetworkGroupAssignment( "network_group_assignment_uid_2", - util.GenerateNetworkGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid_2", "_2")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid_2", "_2")}), 1, ) util.MockGetNetworkGroupAssignment( "network_group_assignment_uid", - util.GenerateNetworkGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}), 1, ) }, diff --git a/pkg/config-api-provider/test/resources/sensor_group_assignment_test.go b/pkg/config-api-provider/test/resources/sensor_group_assignment_test.go index e44629ff..a9a8d27c 100644 --- a/pkg/config-api-provider/test/resources/sensor_group_assignment_test.go +++ b/pkg/config-api-provider/test/resources/sensor_group_assignment_test.go @@ -41,7 +41,7 @@ func TestSensorGroupAssignmentResource(t *testing.T) { ) util.MockGetSensorGroupAssignment( "sensor_group_assignment_uid", - util.GenerateSensorGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentGetResponse("sensor_group_assignment_uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentGetResponse("sensor_group_assignment_uid", "")}), 1, ) }, @@ -79,7 +79,7 @@ func TestSensorGroupAssignmentResource(t *testing.T) { PreConfig: func() { util.MockGetSensorGroupAssignment( "sensor_group_assignment_uid", - util.GenerateSensorGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentGetResponse("sensor_group_assignment_uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentGetResponse("sensor_group_assignment_uid", "")}), 1, ) }, @@ -114,12 +114,12 @@ func TestSensorGroupAssignmentResource(t *testing.T) { // required for sensor group assignment create util.MockGetSensorGroupAssignment( "sensor_group_assignment_uid", - util.GenerateSensorGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentGetResponse("sensor_group_assignment_uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentGetResponse("sensor_group_assignment_uid", "")}), 1, ) util.MockGetSensorGroupAssignment( "sensor_group_assignment_uid_2", - util.GenerateSensorGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentGetResponse("sensor_group_assignment_uid_2", "_2")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentGetResponse("sensor_group_assignment_uid_2", "_2")}), 1, ) @@ -192,7 +192,7 @@ func TestSensorGroupAssignmentResource(t *testing.T) { ) util.MockGetSensorGroupAssignment( "sensor_group_assignment_uid", - util.GenerateSensorGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentGetResponse("sensor_group_assignment_uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentGetResponse("sensor_group_assignment_uid", "")}), 1, ) }, diff --git a/pkg/config-api-provider/test/resources/wired_network_test.go b/pkg/config-api-provider/test/resources/wired_network_test.go index ccbe481f..12fcffbd 100644 --- a/pkg/config-api-provider/test/resources/wired_network_test.go +++ b/pkg/config-api-provider/test/resources/wired_network_test.go @@ -36,7 +36,7 @@ func TestWiredNetworkResource(t *testing.T) { PreConfig: func() { util.MockGetWiredNetwork( "uid", - util.GenerateWiredNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}), 2, ) }, @@ -60,7 +60,7 @@ func TestWiredNetworkResource(t *testing.T) { PreConfig: func() { util.MockGetWiredNetwork( "uid", - util.GenerateWiredNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}), 1, ) }, @@ -73,7 +73,7 @@ func TestWiredNetworkResource(t *testing.T) { PreConfig: func() { util.MockGetWiredNetwork( "uid", - util.GenerateWiredNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}), 1, ) }, @@ -88,7 +88,7 @@ func TestWiredNetworkResource(t *testing.T) { PreConfig: func() { util.MockGetWiredNetwork( "uid", - util.GenerateWiredNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}), 2, ) }, diff --git a/pkg/config-api-provider/test/resources/wireless_network_test.go b/pkg/config-api-provider/test/resources/wireless_network_test.go index d35efa4c..d5481f32 100644 --- a/pkg/config-api-provider/test/resources/wireless_network_test.go +++ b/pkg/config-api-provider/test/resources/wireless_network_test.go @@ -36,7 +36,7 @@ func TestWirelessNetworkResource(t *testing.T) { PreConfig: func() { util.MockGetWirelessNetwork( "uid", - util.GenerateWirelessNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}), 2, ) }, @@ -60,7 +60,7 @@ func TestWirelessNetworkResource(t *testing.T) { PreConfig: func() { util.MockGetWirelessNetwork( "uid", - util.GenerateWirelessNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}), 1, ) }, @@ -73,7 +73,7 @@ func TestWirelessNetworkResource(t *testing.T) { PreConfig: func() { util.MockGetWirelessNetwork( "uid", - util.GenerateWirelessNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}), 1, ) }, @@ -88,7 +88,7 @@ func TestWirelessNetworkResource(t *testing.T) { PreConfig: func() { util.MockGetWirelessNetwork( "uid", - util.GenerateWirelessNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}), 1, ) }, @@ -100,7 +100,7 @@ func TestWirelessNetworkResource(t *testing.T) { PreConfig: func() { util.MockGetWirelessNetwork( "uid", - util.GenerateWirelessNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}), 1, ) }, diff --git a/pkg/config-api-provider/test/util/utils.go b/pkg/config-api-provider/test/util/utils.go index bc8f6cf6..ac65327d 100644 --- a/pkg/config-api-provider/test/util/utils.go +++ b/pkg/config-api-provider/test/util/utils.go @@ -8,14 +8,6 @@ import ( "github.com/h2non/gock" ) -var mockPaginationResponse = map[string]interface{}{ - "limit": 10, - "first": nil, - "next": nil, - "previous": nil, - "last": nil, -} - func GenerateSensorResponseModel(uid string, postfix string) resources.SensorResponseModel { return resources.SensorResponseModel{ UID: uid, @@ -60,10 +52,10 @@ func GenerateGroupResponsePostModel(uid string, nonReplacementFieldPostfix strin parentId := "parent_uid" + replacementFieldPostfix return config_api_client.GroupsPostResponse{ - Uid: uid, - Name: "name" + nonReplacementFieldPostfix, - ParentUid: parentId, - Path: parentId + "." + uid, + Id: uid, + Name: "name" + nonReplacementFieldPostfix, + Parent: *config_api_client.NewParent(parentId), + Path: parentId + "." + uid, } } @@ -88,49 +80,35 @@ func GenerateServiceTestResponseModel(uid string, postfix string) resources.Serv func GenerateWiredNetworkResponse(uid string, postfix string) map[string]interface{} { return map[string]interface{}{ - "uid": uid, - "alias": "alias" + postfix, - "datetime_created": "2024-09-11T12:00:00.000Z", - "datetime_updated": "2024-09-11T12:00:00.000Z", - "ip_version": "ip_version" + postfix, - "security": "security" + postfix, - "dns_lookup_domain": "dns_lookup_domain" + postfix, - "disable_edns": false, - "use_dns64": false, - "external_connectivity": false, - "vlan_id": 123, - } -} - -func GenerateWiredNetworkPaginatedResponse(wiredNetworks []map[string]interface{}) map[string]interface{} { - return map[string]interface{}{ - "wired_networks": wiredNetworks, - "pagination": mockPaginationResponse, + "id": uid, + "name": "alias" + postfix, + "createdAt": "2024-09-11T12:00:00.000Z", + "updatedAt": "2024-09-11T12:00:00.000Z", + "ipVersion": "ip_version" + postfix, + "security": "security" + postfix, + "dnsLookupDomain": "dns_lookup_domain" + postfix, + "disableEdns": false, + "useDns64": false, + "externalConnectivity": false, + "vLanId": 123, } } func GenerateWirelessNetworkResponse(uid string, postfix string) map[string]interface{} { return map[string]interface{}{ - "uid": uid, - "ssid": "ssid" + postfix, - "datetime_created": "2024-09-11T12:00:00.000Z", - "datetime_updated": "2024-09-11T12:00:00.000Z", - "alias": "alias" + postfix, - "ip_version": "ip_version" + postfix, - "security": "security" + postfix, - "hidden": false, - "band_locking": "band_locking" + postfix, - "dns_lookup_domain": "dns_lookup_domain" + postfix, - "disable_edns": false, - "use_dns64": false, - "external_connectivity": false, - } -} - -func GenerateWirelessNetworkPaginatedResponse(wirelessNetworks []map[string]interface{}) map[string]interface{} { - return map[string]interface{}{ - "wireless_networks": wirelessNetworks, - "pagination": mockPaginationResponse, + "id": uid, + "ssid": "ssid" + postfix, + "createdAt": "2024-09-11T12:00:00.000Z", + "updatedAt": "2024-09-11T12:00:00.000Z", + "name": "alias" + postfix, + "ipVersion": "ip_version" + postfix, + "security": "security" + postfix, + "hidden": false, + "bandLocking": "band_locking" + postfix, + "dnsLookupDomain": "dns_lookup_domain" + postfix, + "disableEdns": false, + "useDns64": false, + "externalConnectivity": false, } } @@ -144,16 +122,9 @@ func GenerateSensorGroupAssignmentPostResponse(uid string, postfix string) map[s func GenerateSensorGroupAssignmentGetResponse(uid string, postfix string) map[string]interface{} { return map[string]interface{}{ - "uid": uid, - "group_uid": "group_uid" + postfix, - "sensor_uid": "sensor_uid" + postfix, - } -} - -func GenerateSensorGroupAssignmentPaginatedResponse(sensorGroupAssignments []map[string]interface{}) map[string]interface{} { - return map[string]interface{}{ - "sensor_group_assignments": sensorGroupAssignments, - "pagination": mockPaginationResponse, + "id": uid, + "group": map[string]string{"id": "group_uid" + postfix}, + "sensor": map[string]string{"id": "sensor_uid" + postfix}, } } @@ -173,18 +144,11 @@ func GenerateNetworkGroupAssignmentResponse(uid string, postfix string) resource } } -func GenerateNetworkGroupAssignmentPaginatedResponse(networkGroupAssignments []map[string]interface{}) map[string]interface{} { - return map[string]interface{}{ - "network_group_assignments": networkGroupAssignments, - "pagination": mockPaginationResponse, - } -} - func GenerateNetworkGroupAssignmentGetResponse(uid string, postfix string) map[string]interface{} { return map[string]interface{}{ - "uid": uid, - "group_uid": "group_uid" + postfix, - "network_uid": "network_uid" + postfix, + "id": uid, + "group": map[string]string{"id": "group_uid" + postfix}, + "network": map[string]string{"id": "network_uid" + postfix}, } }