diff --git a/pkg/config-api-provider/main.go b/pkg/config-api-provider/main.go index 30ce9153..86ff5d77 100644 --- a/pkg/config-api-provider/main.go +++ b/pkg/config-api-provider/main.go @@ -19,7 +19,12 @@ var ( func main() { var debug bool - flag.BoolVar(&debug, "debug", false, "set to true to run the provider with support for debuggers like delve") + flag.BoolVar( + &debug, + "debug", + false, + "set to true to run the provider with support for debuggers like delve", + ) flag.Parse() opts := providerserver.ServeOpts{ diff --git a/pkg/config-api-provider/provider/data-sources/agent.go b/pkg/config-api-provider/provider/data-sources/agent.go index 490138f8..18a64333 100644 --- a/pkg/config-api-provider/provider/data-sources/agent.go +++ b/pkg/config-api-provider/provider/data-sources/agent.go @@ -40,11 +40,19 @@ type agentDataSourceModel struct { } `tfsdk:"filter"` } -func (d *agentDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *agentDataSource) Metadata( + _ context.Context, + req datasource.MetadataRequest, + resp *datasource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_agent" } -func (d *agentDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { +func (d *agentDataSource) Schema( + _ context.Context, + _ datasource.SchemaRequest, + resp *datasource.SchemaResponse, +) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ @@ -92,7 +100,11 @@ func (d *agentDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, } } -func (d *agentDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { +func (d *agentDataSource) Read( + ctx context.Context, + req datasource.ReadRequest, + resp *datasource.ReadResponse, +) { var state agentDataSourceModel // Read configuration from request @@ -139,7 +151,11 @@ func (d *agentDataSource) Read(ctx context.Context, req datasource.ReadRequest, } } -func (d *agentDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { +func (d *agentDataSource) Configure( + _ context.Context, + req datasource.ConfigureRequest, + resp *datasource.ConfigureResponse, +) { // Add a nil check when handling ProviderData because Terraform // sets that data after it calls the ConfigureProvider RPC. if req.ProviderData == nil { diff --git a/pkg/config-api-provider/provider/data-sources/group.go b/pkg/config-api-provider/provider/data-sources/group.go index 73476b72..0dffd5ad 100644 --- a/pkg/config-api-provider/provider/data-sources/group.go +++ b/pkg/config-api-provider/provider/data-sources/group.go @@ -33,11 +33,19 @@ type groupDataSourceModel struct { } `tfsdk:"filter"` } -func (d *groupDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *groupDataSource) Metadata( + _ context.Context, + req datasource.MetadataRequest, + resp *datasource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_group" } -func (d *groupDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { +func (d *groupDataSource) Schema( + _ context.Context, + _ datasource.SchemaRequest, + resp *datasource.SchemaResponse, +) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ @@ -64,7 +72,11 @@ func (d *groupDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, } } -func (d *groupDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { +func (d *groupDataSource) Read( + ctx context.Context, + req datasource.ReadRequest, + resp *datasource.ReadResponse, +) { var state groupDataSourceModel // Read configuration from request @@ -112,7 +124,11 @@ func (d *groupDataSource) Read(ctx context.Context, req datasource.ReadRequest, } } -func (d *groupDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { +func (d *groupDataSource) Configure( + _ context.Context, + req datasource.ConfigureRequest, + resp *datasource.ConfigureResponse, +) { // Add a nil check when handling ProviderData because Terraform // sets that data after it calls the ConfigureProvider RPC. if req.ProviderData == nil { 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 36b6f279..17f2b058 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 @@ -32,11 +32,19 @@ type networkGroupAssignmentDataSourceModel struct { } `tfsdk:"filter"` } -func (d *networkGroupAssignmentDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *networkGroupAssignmentDataSource) Metadata( + _ context.Context, + req datasource.MetadataRequest, + resp *datasource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_network_group_assignment" } -func (d *networkGroupAssignmentDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { +func (d *networkGroupAssignmentDataSource) Schema( + _ context.Context, + _ datasource.SchemaRequest, + resp *datasource.SchemaResponse, +) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ @@ -60,7 +68,11 @@ func (d *networkGroupAssignmentDataSource) Schema(_ context.Context, _ datasourc } } -func (d *networkGroupAssignmentDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { +func (d *networkGroupAssignmentDataSource) Read( + ctx context.Context, + req datasource.ReadRequest, + resp *datasource.ReadResponse, +) { var state networkGroupAssignmentDataSourceModel diags := req.Config.Get(ctx, &state) @@ -99,7 +111,11 @@ func (d *networkGroupAssignmentDataSource) Read(ctx context.Context, req datasou } } -func (d *networkGroupAssignmentDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { +func (d *networkGroupAssignmentDataSource) Configure( + _ context.Context, + req datasource.ConfigureRequest, + resp *datasource.ConfigureResponse, +) { if req.ProviderData == nil { return } diff --git a/pkg/config-api-provider/provider/data-sources/sensor.go b/pkg/config-api-provider/provider/data-sources/sensor.go index 25f624fa..74ad3557 100644 --- a/pkg/config-api-provider/provider/data-sources/sensor.go +++ b/pkg/config-api-provider/provider/data-sources/sensor.go @@ -40,11 +40,19 @@ type sensorDataSourceModel struct { } `tfsdk:"filter"` } -func (d *sensorDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *sensorDataSource) Metadata( + _ context.Context, + req datasource.MetadataRequest, + resp *datasource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_sensor" } -func (d *sensorDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { +func (d *sensorDataSource) Schema( + _ context.Context, + _ datasource.SchemaRequest, + resp *datasource.SchemaResponse, +) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ @@ -92,7 +100,11 @@ func (d *sensorDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, } } -func (d *sensorDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { +func (d *sensorDataSource) Read( + ctx context.Context, + req datasource.ReadRequest, + resp *datasource.ReadResponse, +) { var state sensorDataSourceModel // Read configuration from request @@ -142,7 +154,11 @@ func (d *sensorDataSource) Read(ctx context.Context, req datasource.ReadRequest, } } -func (d *sensorDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { +func (d *sensorDataSource) Configure( + _ context.Context, + req datasource.ConfigureRequest, + resp *datasource.ConfigureResponse, +) { // Add a nil check when handling ProviderData because Terraform // sets that data after it calls the ConfigureProvider RPC. if req.ProviderData == nil { 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 2b2a08af..8c08841c 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 @@ -33,11 +33,19 @@ type sensorGroupAssignmentDataSourceModel struct { } `tfsdk:"filter"` } -func (d *sensorGroupAssignmentDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *sensorGroupAssignmentDataSource) Metadata( + _ context.Context, + req datasource.MetadataRequest, + resp *datasource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_sensor_group_assignment" } -func (d *sensorGroupAssignmentDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { +func (d *sensorGroupAssignmentDataSource) Schema( + _ context.Context, + _ datasource.SchemaRequest, + resp *datasource.SchemaResponse, +) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ @@ -61,7 +69,11 @@ func (d *sensorGroupAssignmentDataSource) Schema(_ context.Context, _ datasource } } -func (d *sensorGroupAssignmentDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { +func (d *sensorGroupAssignmentDataSource) Read( + ctx context.Context, + req datasource.ReadRequest, + resp *datasource.ReadResponse, +) { var state sensorGroupAssignmentDataSourceModel // Read configuration from request @@ -102,7 +114,11 @@ func (d *sensorGroupAssignmentDataSource) Read(ctx context.Context, req datasour } } -func (d *sensorGroupAssignmentDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { +func (d *sensorGroupAssignmentDataSource) Configure( + _ context.Context, + req datasource.ConfigureRequest, + resp *datasource.ConfigureResponse, +) { // Add a nil check when handling ProviderData because Terraform // sets that data after it calls the ConfigureProvider RPC. if req.ProviderData == nil { 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 b75cff07..f0e5869e 100644 --- a/pkg/config-api-provider/provider/data-sources/wired_network.go +++ b/pkg/config-api-provider/provider/data-sources/wired_network.go @@ -40,11 +40,19 @@ type wiredNetworkDataSourceModel struct { } `tfsdk:"filter"` } -func (d *wiredNetworkDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *wiredNetworkDataSource) Metadata( + _ context.Context, + req datasource.MetadataRequest, + resp *datasource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_wired_network" } -func (d *wiredNetworkDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { +func (d *wiredNetworkDataSource) Schema( + _ context.Context, + _ datasource.SchemaRequest, + resp *datasource.SchemaResponse, +) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ @@ -86,7 +94,11 @@ func (d *wiredNetworkDataSource) Schema(_ context.Context, _ datasource.SchemaRe } } -func (d *wiredNetworkDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { +func (d *wiredNetworkDataSource) Read( + ctx context.Context, + req datasource.ReadRequest, + resp *datasource.ReadResponse, +) { var state wiredNetworkDataSourceModel // Read configuration from request @@ -133,7 +145,11 @@ func (d *wiredNetworkDataSource) Read(ctx context.Context, req datasource.ReadRe } } -func (d *wiredNetworkDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { +func (d *wiredNetworkDataSource) Configure( + _ context.Context, + req datasource.ConfigureRequest, + resp *datasource.ConfigureResponse, +) { // Add a nil check when handling ProviderData because Terraform // sets that data after it calls the ConfigureProvider RPC. if req.ProviderData == nil { 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 8e8b672a..e9bdb04e 100644 --- a/pkg/config-api-provider/provider/data-sources/wireless_network.go +++ b/pkg/config-api-provider/provider/data-sources/wireless_network.go @@ -42,11 +42,19 @@ type wirelessNetworkDataSourceModel struct { } `tfsdk:"filter"` } -func (d *wirelessNetworkDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *wirelessNetworkDataSource) Metadata( + _ context.Context, + req datasource.MetadataRequest, + resp *datasource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_wireless_network" } -func (d *wirelessNetworkDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { +func (d *wirelessNetworkDataSource) Schema( + _ context.Context, + _ datasource.SchemaRequest, + resp *datasource.SchemaResponse, +) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ @@ -94,7 +102,11 @@ func (d *wirelessNetworkDataSource) Schema(_ context.Context, _ datasource.Schem } } -func (d *wirelessNetworkDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { +func (d *wirelessNetworkDataSource) Read( + ctx context.Context, + req datasource.ReadRequest, + resp *datasource.ReadResponse, +) { var state wirelessNetworkDataSourceModel // Read configuration from request @@ -143,7 +155,11 @@ func (d *wirelessNetworkDataSource) Read(ctx context.Context, req datasource.Rea } } -func (d *wirelessNetworkDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { +func (d *wirelessNetworkDataSource) Configure( + _ context.Context, + req datasource.ConfigureRequest, + resp *datasource.ConfigureResponse, +) { // Add a nil check when handling ProviderData because Terraform // sets that data after it calls the ConfigureProvider RPC. if req.ProviderData == nil { diff --git a/pkg/config-api-provider/provider/provider.go b/pkg/config-api-provider/provider/provider.go index 7f9ae59e..1032f40c 100644 --- a/pkg/config-api-provider/provider/provider.go +++ b/pkg/config-api-provider/provider/provider.go @@ -52,13 +52,21 @@ type uxiConfigurationProvider struct { } // Metadata returns the provider type name. -func (p *uxiConfigurationProvider) Metadata(_ context.Context, _ provider.MetadataRequest, resp *provider.MetadataResponse) { +func (p *uxiConfigurationProvider) Metadata( + _ context.Context, + _ provider.MetadataRequest, + resp *provider.MetadataResponse, +) { resp.TypeName = "uxi" resp.Version = p.version } // Schema defines the provider-level schema for configuration data. -func (p *uxiConfigurationProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) { +func (p *uxiConfigurationProvider) Schema( + _ context.Context, + _ provider.SchemaRequest, + resp *provider.SchemaResponse, +) { resp.Schema = schema.Schema{Attributes: map[string]schema.Attribute{ "host": schema.StringAttribute{Optional: true}, "client_id": schema.StringAttribute{Optional: true}, @@ -69,7 +77,11 @@ func (p *uxiConfigurationProvider) Schema(_ context.Context, _ provider.SchemaRe // TODO: Obtain a greenlake access token // Configure prepares a Configuration API client for data sources and resources. -func (p *uxiConfigurationProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { +func (p *uxiConfigurationProvider) Configure( + ctx context.Context, + req provider.ConfigureRequest, + resp *provider.ConfigureResponse, +) { // Init var config uxiProviderModel diags := req.Config.Get(ctx, &config) diff --git a/pkg/config-api-provider/provider/resources/agent.go b/pkg/config-api-provider/provider/resources/agent.go index 29598c3b..c622dba1 100644 --- a/pkg/config-api-provider/provider/resources/agent.go +++ b/pkg/config-api-provider/provider/resources/agent.go @@ -54,11 +54,19 @@ type agentResource struct { client *config_api_client.APIClient } -func (r *agentResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { +func (r *agentResource) Metadata( + ctx context.Context, + req resource.MetadataRequest, + resp *resource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_agent" } -func (r *agentResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { +func (r *agentResource) Schema( + _ context.Context, + _ resource.SchemaRequest, + resp *resource.SchemaResponse, +) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ @@ -80,7 +88,11 @@ func (r *agentResource) Schema(_ context.Context, _ resource.SchemaRequest, resp } } -func (r *agentResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { +func (r *agentResource) Configure( + _ context.Context, + req resource.ConfigureRequest, + resp *resource.ConfigureResponse, +) { // Add a nil check when handling ProviderData because Terraform // sets that data after it calls the ConfigureProvider RPC. if req.ProviderData == nil { @@ -100,15 +112,26 @@ func (r *agentResource) Configure(_ context.Context, req resource.ConfigureReque r.client = client } -func (r *agentResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { +func (r *agentResource) Create( + ctx context.Context, + req resource.CreateRequest, + resp *resource.CreateResponse, +) { // Retrieve values from plan var plan agentResourceModel diags := req.Plan.Get(ctx, &plan) - diags.AddError("operation not supported", "creating an agent is not supported; agents can only be imported") + diags.AddError( + "operation not supported", + "creating an agent is not supported; agents can only be imported", + ) resp.Diagnostics.Append(diags...) } -func (r *agentResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { +func (r *agentResource) Read( + ctx context.Context, + req resource.ReadRequest, + resp *resource.ReadResponse, +) { var state agentResourceModel diags := req.State.Get(ctx, &state) resp.Diagnostics.Append(diags...) @@ -146,7 +169,11 @@ func (r *agentResource) Read(ctx context.Context, req resource.ReadRequest, resp } } -func (r *agentResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { +func (r *agentResource) Update( + ctx context.Context, + req resource.UpdateRequest, + resp *resource.UpdateResponse, +) { // Retrieve values from plan var plan agentResourceModel diags := req.Plan.Get(ctx, &plan) @@ -175,7 +202,11 @@ func (r *agentResource) Update(ctx context.Context, req resource.UpdateRequest, } } -func (r *agentResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { +func (r *agentResource) Delete( + ctx context.Context, + req resource.DeleteRequest, + resp *resource.DeleteResponse, +) { // Retrieve values from state var state agentResourceModel diags := req.State.Get(ctx, &state) @@ -188,7 +219,11 @@ func (r *agentResource) Delete(ctx context.Context, req resource.DeleteRequest, // err := r.client.DeleteOrder(state.ID.ValueString()) } -func (r *agentResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *agentResource) ImportState( + ctx context.Context, + req resource.ImportStateRequest, + resp *resource.ImportStateResponse, +) { resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) } diff --git a/pkg/config-api-provider/provider/resources/agent_group_assignment.go b/pkg/config-api-provider/provider/resources/agent_group_assignment.go index 57e469e2..7af729fd 100644 --- a/pkg/config-api-provider/provider/resources/agent_group_assignment.go +++ b/pkg/config-api-provider/provider/resources/agent_group_assignment.go @@ -40,11 +40,19 @@ func NewAgentGroupAssignmentResource() resource.Resource { type agentGroupAssignmentResource struct{} -func (r *agentGroupAssignmentResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { +func (r *agentGroupAssignmentResource) Metadata( + ctx context.Context, + req resource.MetadataRequest, + resp *resource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_agent_group_assignment" } -func (r *agentGroupAssignmentResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { +func (r *agentGroupAssignmentResource) Schema( + _ context.Context, + _ resource.SchemaRequest, + resp *resource.SchemaResponse, +) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ @@ -69,10 +77,18 @@ func (r *agentGroupAssignmentResource) Schema(_ context.Context, _ resource.Sche } } -func (r *agentGroupAssignmentResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { +func (r *agentGroupAssignmentResource) Configure( + _ context.Context, + req resource.ConfigureRequest, + resp *resource.ConfigureResponse, +) { } -func (r *agentGroupAssignmentResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { +func (r *agentGroupAssignmentResource) Create( + ctx context.Context, + req resource.CreateRequest, + resp *resource.CreateResponse, +) { // Retrieve values from plan var plan agentGroupAssignmentResourceModel diags := req.Plan.Get(ctx, &plan) @@ -100,7 +116,11 @@ func (r *agentGroupAssignmentResource) Create(ctx context.Context, req resource. } } -func (r *agentGroupAssignmentResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { +func (r *agentGroupAssignmentResource) Read( + ctx context.Context, + req resource.ReadRequest, + resp *resource.ReadResponse, +) { // Get current state var state agentGroupAssignmentResourceModel diags := req.State.Get(ctx, &state) @@ -124,7 +144,11 @@ func (r *agentGroupAssignmentResource) Read(ctx context.Context, req resource.Re } } -func (r *agentGroupAssignmentResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { +func (r *agentGroupAssignmentResource) Update( + ctx context.Context, + req resource.UpdateRequest, + resp *resource.UpdateResponse, +) { // Retrieve values from plan var plan agentGroupAssignmentResourceModel diags := req.Plan.Get(ctx, &plan) @@ -135,7 +159,11 @@ func (r *agentGroupAssignmentResource) Update(ctx context.Context, req resource. } } -func (r *agentGroupAssignmentResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { +func (r *agentGroupAssignmentResource) Delete( + ctx context.Context, + req resource.DeleteRequest, + resp *resource.DeleteResponse, +) { // Retrieve values from state var state agentGroupAssignmentResourceModel diags := req.State.Get(ctx, &state) @@ -147,7 +175,11 @@ func (r *agentGroupAssignmentResource) Delete(ctx context.Context, req resource. // Delete existing agentGroupAssignment using the plan_id } -func (r *agentGroupAssignmentResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *agentGroupAssignmentResource) ImportState( + ctx context.Context, + req resource.ImportStateRequest, + resp *resource.ImportStateResponse, +) { resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) } diff --git a/pkg/config-api-provider/provider/resources/group.go b/pkg/config-api-provider/provider/resources/group.go index 6a53854e..cc6c715a 100644 --- a/pkg/config-api-provider/provider/resources/group.go +++ b/pkg/config-api-provider/provider/resources/group.go @@ -34,11 +34,19 @@ type groupResource struct { client *config_api_client.APIClient } -func (r *groupResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { +func (r *groupResource) Metadata( + ctx context.Context, + req resource.MetadataRequest, + resp *resource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_group" } -func (r *groupResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { +func (r *groupResource) Schema( + _ context.Context, + _ resource.SchemaRequest, + resp *resource.SchemaResponse, +) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ @@ -62,7 +70,11 @@ func (r *groupResource) Schema(_ context.Context, _ resource.SchemaRequest, resp } } -func (r *groupResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { +func (r *groupResource) Configure( + _ context.Context, + req resource.ConfigureRequest, + resp *resource.ConfigureResponse, +) { // Add a nil check when handling ProviderData because Terraform // sets that data after it calls the ConfigureProvider RPC. if req.ProviderData == nil { @@ -82,7 +94,11 @@ func (r *groupResource) Configure(_ context.Context, req resource.ConfigureReque r.client = client } -func (r *groupResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { +func (r *groupResource) Create( + ctx context.Context, + req resource.CreateRequest, + resp *resource.CreateResponse, +) { // Retrieve values from plan var plan groupResourceModel diags := req.Plan.Get(ctx, &plan) @@ -119,7 +135,11 @@ func (r *groupResource) Create(ctx context.Context, req resource.CreateRequest, } } -func (r *groupResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { +func (r *groupResource) Read( + ctx context.Context, + req resource.ReadRequest, + resp *resource.ReadResponse, +) { // Get current state var state groupResourceModel diags := req.State.Get(ctx, &state) @@ -164,7 +184,11 @@ func (r *groupResource) Read(ctx context.Context, req resource.ReadRequest, resp } } -func (r *groupResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { +func (r *groupResource) Update( + ctx context.Context, + req resource.UpdateRequest, + resp *resource.UpdateResponse, +) { // Retrieve values from plan var plan groupResourceModel diags := req.Plan.Get(ctx, &plan) @@ -198,7 +222,11 @@ func (r *groupResource) Update(ctx context.Context, req resource.UpdateRequest, } } -func (r *groupResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { +func (r *groupResource) Delete( + ctx context.Context, + req resource.DeleteRequest, + resp *resource.DeleteResponse, +) { // Retrieve values from state var state groupResourceModel diags := req.State.Get(ctx, &state) @@ -219,6 +247,10 @@ func (r *groupResource) Delete(ctx context.Context, req resource.DeleteRequest, } } -func (r *groupResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *groupResource) ImportState( + ctx context.Context, + req resource.ImportStateRequest, + resp *resource.ImportStateResponse, +) { resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) } 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 af22e974..dd7552c0 100644 --- a/pkg/config-api-provider/provider/resources/network_group_assignment.go +++ b/pkg/config-api-provider/provider/resources/network_group_assignment.go @@ -33,11 +33,19 @@ type networkGroupAssignmentResource struct { client *config_api_client.APIClient } -func (r *networkGroupAssignmentResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { +func (r *networkGroupAssignmentResource) Metadata( + ctx context.Context, + req resource.MetadataRequest, + resp *resource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_network_group_assignment" } -func (r *networkGroupAssignmentResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { +func (r *networkGroupAssignmentResource) Schema( + _ context.Context, + _ resource.SchemaRequest, + resp *resource.SchemaResponse, +) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ @@ -62,7 +70,11 @@ func (r *networkGroupAssignmentResource) Schema(_ context.Context, _ resource.Sc } } -func (r *networkGroupAssignmentResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { +func (r *networkGroupAssignmentResource) Configure( + _ context.Context, + req resource.ConfigureRequest, + resp *resource.ConfigureResponse, +) { if req.ProviderData == nil { return } @@ -80,7 +92,11 @@ func (r *networkGroupAssignmentResource) Configure(_ context.Context, req resour r.client = client } -func (r *networkGroupAssignmentResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { +func (r *networkGroupAssignmentResource) Create( + ctx context.Context, + req resource.CreateRequest, + resp *resource.CreateResponse, +) { // Retrieve values from plan var plan networkGroupAssignmentResourceModel diags := req.Plan.Get(ctx, &plan) @@ -100,7 +116,10 @@ func (r *networkGroupAssignmentResource) Create(ctx context.Context, req resourc errorPresent, errorDetail := util.RaiseForStatus(response, err) if errorPresent { - resp.Diagnostics.AddError(util.GenerateErrorSummary("create", "uxi_network_group_assignment"), errorDetail) + resp.Diagnostics.AddError( + util.GenerateErrorSummary("create", "uxi_network_group_assignment"), + errorDetail, + ) return } @@ -117,7 +136,11 @@ func (r *networkGroupAssignmentResource) Create(ctx context.Context, req resourc } } -func (r *networkGroupAssignmentResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { +func (r *networkGroupAssignmentResource) Read( + ctx context.Context, + req resource.ReadRequest, + resp *resource.ReadResponse, +) { // Get current state var state networkGroupAssignmentResourceModel diags := req.State.Get(ctx, &state) @@ -157,18 +180,29 @@ func (r *networkGroupAssignmentResource) Read(ctx context.Context, req resource. } } -func (r *networkGroupAssignmentResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { +func (r *networkGroupAssignmentResource) Update( + ctx context.Context, + req resource.UpdateRequest, + resp *resource.UpdateResponse, +) { // Retrieve values from plan var plan networkGroupAssignmentResourceModel diags := req.Plan.Get(ctx, &plan) - diags.AddError("operation not supported", "updating a network group assignment is not supported") + diags.AddError( + "operation not supported", + "updating a network group assignment is not supported", + ) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { return } } -func (r *networkGroupAssignmentResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { +func (r *networkGroupAssignmentResource) Delete( + ctx context.Context, + req resource.DeleteRequest, + resp *resource.DeleteResponse, +) { // Retrieve values from state var state networkGroupAssignmentResourceModel diags := req.State.Get(ctx, &state) @@ -183,11 +217,18 @@ func (r *networkGroupAssignmentResource) Delete(ctx context.Context, req resourc errorPresent, errorDetail := util.RaiseForStatus(response, err) if errorPresent { - resp.Diagnostics.AddError(util.GenerateErrorSummary("delete", "uxi_network_group_assignment"), errorDetail) + resp.Diagnostics.AddError( + util.GenerateErrorSummary("delete", "uxi_network_group_assignment"), + errorDetail, + ) return } } -func (r *networkGroupAssignmentResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *networkGroupAssignmentResource) ImportState( + ctx context.Context, + req resource.ImportStateRequest, + resp *resource.ImportStateResponse, +) { resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) } diff --git a/pkg/config-api-provider/provider/resources/sensor.go b/pkg/config-api-provider/provider/resources/sensor.go index 725f3159..58d23144 100644 --- a/pkg/config-api-provider/provider/resources/sensor.go +++ b/pkg/config-api-provider/provider/resources/sensor.go @@ -58,11 +58,19 @@ type sensorResource struct { client *config_api_client.APIClient } -func (r *sensorResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { +func (r *sensorResource) Metadata( + ctx context.Context, + req resource.MetadataRequest, + resp *resource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_sensor" } -func (r *sensorResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { +func (r *sensorResource) Schema( + _ context.Context, + _ resource.SchemaRequest, + resp *resource.SchemaResponse, +) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ @@ -87,7 +95,11 @@ func (r *sensorResource) Schema(_ context.Context, _ resource.SchemaRequest, res } } -func (r *sensorResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { +func (r *sensorResource) Configure( + _ context.Context, + req resource.ConfigureRequest, + resp *resource.ConfigureResponse, +) { // Add a nil check when handling ProviderData because Terraform // sets that data after it calls the ConfigureProvider RPC. if req.ProviderData == nil { @@ -107,15 +119,26 @@ func (r *sensorResource) Configure(_ context.Context, req resource.ConfigureRequ r.client = client } -func (r *sensorResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { +func (r *sensorResource) Create( + ctx context.Context, + req resource.CreateRequest, + resp *resource.CreateResponse, +) { // Retrieve values from plan var plan sensorResourceModel diags := req.Plan.Get(ctx, &plan) - diags.AddError("operation not supported", "creating a sensor is not supported; sensors can only be imported") + diags.AddError( + "operation not supported", + "creating a sensor is not supported; sensors can only be imported", + ) resp.Diagnostics.Append(diags...) } -func (r *sensorResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { +func (r *sensorResource) Read( + ctx context.Context, + req resource.ReadRequest, + resp *resource.ReadResponse, +) { // Get current state var state sensorResourceModel diags := req.State.Get(ctx, &state) @@ -157,7 +180,11 @@ func (r *sensorResource) Read(ctx context.Context, req resource.ReadRequest, res } } -func (r *sensorResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { +func (r *sensorResource) Update( + ctx context.Context, + req resource.UpdateRequest, + resp *resource.UpdateResponse, +) { // Retrieve values from plan var plan sensorResourceModel diags := req.Plan.Get(ctx, &plan) @@ -188,15 +215,26 @@ func (r *sensorResource) Update(ctx context.Context, req resource.UpdateRequest, } } -func (r *sensorResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { +func (r *sensorResource) Delete( + ctx context.Context, + req resource.DeleteRequest, + resp *resource.DeleteResponse, +) { // Retrieve values from state var state sensorResourceModel diags := req.State.Get(ctx, &state) - diags.AddError("operation not supported", "deleting a sensor is not supported; sensors can only removed from state") + diags.AddError( + "operation not supported", + "deleting a sensor is not supported; sensors can only removed from state", + ) resp.Diagnostics.Append(diags...) } -func (r *sensorResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *sensorResource) ImportState( + ctx context.Context, + req resource.ImportStateRequest, + resp *resource.ImportStateResponse, +) { resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) } 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 f5bc99ff..6f4fd945 100644 --- a/pkg/config-api-provider/provider/resources/sensor_group_assignment.go +++ b/pkg/config-api-provider/provider/resources/sensor_group_assignment.go @@ -38,11 +38,19 @@ type sensorGroupAssignmentResource struct { client *config_api_client.APIClient } -func (r *sensorGroupAssignmentResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { +func (r *sensorGroupAssignmentResource) Metadata( + ctx context.Context, + req resource.MetadataRequest, + resp *resource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_sensor_group_assignment" } -func (r *sensorGroupAssignmentResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { +func (r *sensorGroupAssignmentResource) Schema( + _ context.Context, + _ resource.SchemaRequest, + resp *resource.SchemaResponse, +) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ @@ -67,7 +75,11 @@ func (r *sensorGroupAssignmentResource) Schema(_ context.Context, _ resource.Sch } } -func (r *sensorGroupAssignmentResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { +func (r *sensorGroupAssignmentResource) Configure( + _ context.Context, + req resource.ConfigureRequest, + resp *resource.ConfigureResponse, +) { // Add a nil check when handling ProviderData because Terraform // sets that data after it calls the ConfigureProvider RPC. if req.ProviderData == nil { @@ -88,7 +100,11 @@ func (r *sensorGroupAssignmentResource) Configure(_ context.Context, req resourc } -func (r *sensorGroupAssignmentResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { +func (r *sensorGroupAssignmentResource) Create( + ctx context.Context, + req resource.CreateRequest, + resp *resource.CreateResponse, +) { // Retrieve values from plan var plan sensorGroupAssignmentResourceModel diags := req.Plan.Get(ctx, &plan) @@ -97,7 +113,10 @@ func (r *sensorGroupAssignmentResource) Create(ctx context.Context, req resource return } - postRequest := config_api_client.NewSensorGroupAssignmentsPostRequest(plan.GroupID.ValueString(), plan.SensorID.ValueString()) + postRequest := config_api_client.NewSensorGroupAssignmentsPostRequest( + plan.GroupID.ValueString(), + plan.SensorID.ValueString(), + ) request := r.client.ConfigurationAPI. SensorGroupAssignmentsPost(ctx). SensorGroupAssignmentsPostRequest(*postRequest) @@ -105,7 +124,10 @@ func (r *sensorGroupAssignmentResource) Create(ctx context.Context, req resource errorPresent, errorDetail := util.RaiseForStatus(response, err) if errorPresent { - resp.Diagnostics.AddError(util.GenerateErrorSummary("create", "uxi_sensor_group_assignment"), errorDetail) + resp.Diagnostics.AddError( + util.GenerateErrorSummary("create", "uxi_sensor_group_assignment"), + errorDetail, + ) return } @@ -120,7 +142,11 @@ func (r *sensorGroupAssignmentResource) Create(ctx context.Context, req resource } } -func (r *sensorGroupAssignmentResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { +func (r *sensorGroupAssignmentResource) Read( + ctx context.Context, + req resource.ReadRequest, + resp *resource.ReadResponse, +) { // Get current state var state sensorGroupAssignmentResourceModel diags := req.State.Get(ctx, &state) @@ -161,7 +187,11 @@ func (r *sensorGroupAssignmentResource) Read(ctx context.Context, req resource.R } } -func (r *sensorGroupAssignmentResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { +func (r *sensorGroupAssignmentResource) Update( + ctx context.Context, + req resource.UpdateRequest, + resp *resource.UpdateResponse, +) { // Retrieve values from plan var plan sensorGroupAssignmentResourceModel diags := req.Plan.Get(ctx, &plan) @@ -172,7 +202,11 @@ func (r *sensorGroupAssignmentResource) Update(ctx context.Context, req resource } } -func (r *sensorGroupAssignmentResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { +func (r *sensorGroupAssignmentResource) Delete( + ctx context.Context, + req resource.DeleteRequest, + resp *resource.DeleteResponse, +) { // Retrieve values from state var state sensorGroupAssignmentResourceModel diags := req.State.Get(ctx, &state) @@ -188,11 +222,18 @@ func (r *sensorGroupAssignmentResource) Delete(ctx context.Context, req resource errorPresent, errorDetail := util.RaiseForStatus(response, err) if errorPresent { - resp.Diagnostics.AddError(util.GenerateErrorSummary("delete", "uxi_sensor_group_assignment"), errorDetail) + resp.Diagnostics.AddError( + util.GenerateErrorSummary("delete", "uxi_sensor_group_assignment"), + errorDetail, + ) return } } -func (r *sensorGroupAssignmentResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *sensorGroupAssignmentResource) ImportState( + ctx context.Context, + req resource.ImportStateRequest, + resp *resource.ImportStateResponse, +) { resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) } diff --git a/pkg/config-api-provider/provider/resources/service.go b/pkg/config-api-provider/provider/resources/service.go index e3990cdf..120dc5e8 100644 --- a/pkg/config-api-provider/provider/resources/service.go +++ b/pkg/config-api-provider/provider/resources/service.go @@ -39,11 +39,19 @@ func NewServiceTestResource() resource.Resource { type serviceTestResource struct{} -func (r *serviceTestResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { +func (r *serviceTestResource) Metadata( + ctx context.Context, + req resource.MetadataRequest, + resp *resource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_service_test" } -func (r *serviceTestResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { +func (r *serviceTestResource) Schema( + _ context.Context, + _ resource.SchemaRequest, + resp *resource.SchemaResponse, +) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ @@ -59,18 +67,33 @@ func (r *serviceTestResource) Schema(_ context.Context, _ resource.SchemaRequest } } -func (r *serviceTestResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { +func (r *serviceTestResource) Configure( + _ context.Context, + req resource.ConfigureRequest, + resp *resource.ConfigureResponse, +) { } -func (r *serviceTestResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { +func (r *serviceTestResource) Create( + ctx context.Context, + req resource.CreateRequest, + resp *resource.CreateResponse, +) { // Retrieve values from plan var plan serviceTestResourceModel diags := req.Plan.Get(ctx, &plan) - diags.AddError("operation not supported", "creating a service_test is not supported; service_tests can only be imported") + diags.AddError( + "operation not supported", + "creating a service_test is not supported; service_tests can only be imported", + ) resp.Diagnostics.Append(diags...) } -func (r *serviceTestResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { +func (r *serviceTestResource) Read( + ctx context.Context, + req resource.ReadRequest, + resp *resource.ReadResponse, +) { // Get current state var state serviceTestResourceModel diags := req.State.Get(ctx, &state) @@ -92,23 +115,41 @@ func (r *serviceTestResource) Read(ctx context.Context, req resource.ReadRequest } } -func (r *serviceTestResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { +func (r *serviceTestResource) Update( + ctx context.Context, + req resource.UpdateRequest, + resp *resource.UpdateResponse, +) { // Retrieve values from plan var plan serviceTestResourceModel diags := req.Plan.Get(ctx, &plan) - diags.AddError("operation not supported", "updating a service_test is not supported; service_tests can only be updated through the dashboard") + diags.AddError( + "operation not supported", + "updating a service_test is not supported; service_tests can only be updated through the dashboard", + ) resp.Diagnostics.Append(diags...) } -func (r *serviceTestResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { +func (r *serviceTestResource) Delete( + ctx context.Context, + req resource.DeleteRequest, + resp *resource.DeleteResponse, +) { // Retrieve values from state var state serviceTestResourceModel diags := req.State.Get(ctx, &state) - diags.AddError("operation not supported", "deleting a service_test is not supported; service_tests can only removed from state") + diags.AddError( + "operation not supported", + "deleting a service_test is not supported; service_tests can only removed from state", + ) resp.Diagnostics.Append(diags...) } -func (r *serviceTestResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *serviceTestResource) ImportState( + ctx context.Context, + req resource.ImportStateRequest, + resp *resource.ImportStateResponse, +) { resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) } diff --git a/pkg/config-api-provider/provider/resources/service_group_assignment.go b/pkg/config-api-provider/provider/resources/service_group_assignment.go index a8c40ecd..6da541bb 100644 --- a/pkg/config-api-provider/provider/resources/service_group_assignment.go +++ b/pkg/config-api-provider/provider/resources/service_group_assignment.go @@ -33,11 +33,19 @@ type serviceTestGroupAssignmentResource struct { client *config_api_client.APIClient } -func (r *serviceTestGroupAssignmentResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { +func (r *serviceTestGroupAssignmentResource) Metadata( + ctx context.Context, + req resource.MetadataRequest, + resp *resource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_service_test_group_assignment" } -func (r *serviceTestGroupAssignmentResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { +func (r *serviceTestGroupAssignmentResource) Schema( + _ context.Context, + _ resource.SchemaRequest, + resp *resource.SchemaResponse, +) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ @@ -62,7 +70,11 @@ func (r *serviceTestGroupAssignmentResource) Schema(_ context.Context, _ resourc } } -func (r *serviceTestGroupAssignmentResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { +func (r *serviceTestGroupAssignmentResource) Configure( + _ context.Context, + req resource.ConfigureRequest, + resp *resource.ConfigureResponse, +) { if req.ProviderData == nil { return } @@ -80,7 +92,11 @@ func (r *serviceTestGroupAssignmentResource) Configure(_ context.Context, req re r.client = client } -func (r *serviceTestGroupAssignmentResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { +func (r *serviceTestGroupAssignmentResource) Create( + ctx context.Context, + req resource.CreateRequest, + resp *resource.CreateResponse, +) { // Retrieve values from plan var plan serviceTestGroupAssignmentResourceModel diags := req.Plan.Get(ctx, &plan) @@ -100,7 +116,10 @@ func (r *serviceTestGroupAssignmentResource) Create(ctx context.Context, req res errorPresent, errorDetail := util.RaiseForStatus(response, err) if errorPresent { - resp.Diagnostics.AddError(util.GenerateErrorSummary("delete", "uxi_service_test_group_assignment"), errorDetail) + resp.Diagnostics.AddError( + util.GenerateErrorSummary("delete", "uxi_service_test_group_assignment"), + errorDetail, + ) return } @@ -117,7 +136,11 @@ func (r *serviceTestGroupAssignmentResource) Create(ctx context.Context, req res } } -func (r *serviceTestGroupAssignmentResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { +func (r *serviceTestGroupAssignmentResource) Read( + ctx context.Context, + req resource.ReadRequest, + resp *resource.ReadResponse, +) { // Get current state var state serviceTestGroupAssignmentResourceModel diags := req.State.Get(ctx, &state) @@ -141,18 +164,29 @@ func (r *serviceTestGroupAssignmentResource) Read(ctx context.Context, req resou } } -func (r *serviceTestGroupAssignmentResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { +func (r *serviceTestGroupAssignmentResource) Update( + ctx context.Context, + req resource.UpdateRequest, + resp *resource.UpdateResponse, +) { // Retrieve values from plan var plan serviceTestGroupAssignmentResourceModel diags := req.Plan.Get(ctx, &plan) - diags.AddError("operation not supported", "updating a service_test group assignment is not supported") + diags.AddError( + "operation not supported", + "updating a service_test group assignment is not supported", + ) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { return } } -func (r *serviceTestGroupAssignmentResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { +func (r *serviceTestGroupAssignmentResource) Delete( + ctx context.Context, + req resource.DeleteRequest, + resp *resource.DeleteResponse, +) { // Retrieve values from state var state serviceTestGroupAssignmentResourceModel diags := req.State.Get(ctx, &state) @@ -168,12 +202,19 @@ func (r *serviceTestGroupAssignmentResource) Delete(ctx context.Context, req res errorPresent, errorDetail := util.RaiseForStatus(response, err) if errorPresent { - resp.Diagnostics.AddError(util.GenerateErrorSummary("delete", "uxi_service_test_group_assignment"), errorDetail) + resp.Diagnostics.AddError( + util.GenerateErrorSummary("delete", "uxi_service_test_group_assignment"), + errorDetail, + ) return } } -func (r *serviceTestGroupAssignmentResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *serviceTestGroupAssignmentResource) ImportState( + ctx context.Context, + req resource.ImportStateRequest, + resp *resource.ImportStateResponse, +) { resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) } diff --git a/pkg/config-api-provider/provider/resources/wired_network.go b/pkg/config-api-provider/provider/resources/wired_network.go index 066dac01..368c46a5 100644 --- a/pkg/config-api-provider/provider/resources/wired_network.go +++ b/pkg/config-api-provider/provider/resources/wired_network.go @@ -32,11 +32,19 @@ type wiredNetworkResource struct { client *config_api_client.APIClient } -func (r *wiredNetworkResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { +func (r *wiredNetworkResource) Metadata( + ctx context.Context, + req resource.MetadataRequest, + resp *resource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_wired_network" } -func (r *wiredNetworkResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { +func (r *wiredNetworkResource) Schema( + _ context.Context, + _ resource.SchemaRequest, + resp *resource.SchemaResponse, +) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ @@ -52,7 +60,11 @@ func (r *wiredNetworkResource) Schema(_ context.Context, _ resource.SchemaReques } } -func (r *wiredNetworkResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { +func (r *wiredNetworkResource) Configure( + _ context.Context, + req resource.ConfigureRequest, + resp *resource.ConfigureResponse, +) { // Add a nil check when handling ProviderData because Terraform // sets that data after it calls the ConfigureProvider RPC. if req.ProviderData == nil { @@ -72,15 +84,26 @@ func (r *wiredNetworkResource) Configure(_ context.Context, req resource.Configu r.client = client } -func (r *wiredNetworkResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { +func (r *wiredNetworkResource) Create( + ctx context.Context, + req resource.CreateRequest, + resp *resource.CreateResponse, +) { // Retrieve values from plan var plan wiredNetworkResourceModel diags := req.Plan.Get(ctx, &plan) - diags.AddError("operation not supported", "creating a wired_network is not supported; wired_networks can only be imported") + diags.AddError( + "operation not supported", + "creating a wired_network is not supported; wired_networks can only be imported", + ) resp.Diagnostics.Append(diags...) } -func (r *wiredNetworkResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { +func (r *wiredNetworkResource) Read( + ctx context.Context, + req resource.ReadRequest, + resp *resource.ReadResponse, +) { // Get current state var state wiredNetworkResourceModel diags := req.State.Get(ctx, &state) @@ -120,22 +143,40 @@ func (r *wiredNetworkResource) Read(ctx context.Context, req resource.ReadReques } } -func (r *wiredNetworkResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { +func (r *wiredNetworkResource) Update( + ctx context.Context, + req resource.UpdateRequest, + resp *resource.UpdateResponse, +) { // Retrieve values from plan var plan wiredNetworkResourceModel diags := req.Plan.Get(ctx, &plan) - diags.AddError("operation not supported", "updating a wired_network is not supported; wired_networks can only be updated through the dashboard") + diags.AddError( + "operation not supported", + "updating a wired_network is not supported; wired_networks can only be updated through the dashboard", + ) resp.Diagnostics.Append(diags...) } -func (r *wiredNetworkResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { +func (r *wiredNetworkResource) Delete( + ctx context.Context, + req resource.DeleteRequest, + resp *resource.DeleteResponse, +) { // Retrieve values from state var state wiredNetworkResourceModel diags := req.State.Get(ctx, &state) - diags.AddError("operation not supported", "deleting a wired_network is not supported; wired_networks can only removed from state") + diags.AddError( + "operation not supported", + "deleting a wired_network is not supported; wired_networks can only removed from state", + ) resp.Diagnostics.Append(diags...) } -func (r *wiredNetworkResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *wiredNetworkResource) ImportState( + ctx context.Context, + req resource.ImportStateRequest, + resp *resource.ImportStateResponse, +) { resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) } diff --git a/pkg/config-api-provider/provider/resources/wireless_network.go b/pkg/config-api-provider/provider/resources/wireless_network.go index ebc84741..be6da395 100644 --- a/pkg/config-api-provider/provider/resources/wireless_network.go +++ b/pkg/config-api-provider/provider/resources/wireless_network.go @@ -32,11 +32,19 @@ type wirelessNetworkResource struct { client *config_api_client.APIClient } -func (r *wirelessNetworkResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { +func (r *wirelessNetworkResource) Metadata( + ctx context.Context, + req resource.MetadataRequest, + resp *resource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_wireless_network" } -func (r *wirelessNetworkResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { +func (r *wirelessNetworkResource) Schema( + _ context.Context, + _ resource.SchemaRequest, + resp *resource.SchemaResponse, +) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ @@ -52,7 +60,11 @@ func (r *wirelessNetworkResource) Schema(_ context.Context, _ resource.SchemaReq } } -func (r *wirelessNetworkResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { +func (r *wirelessNetworkResource) Configure( + _ context.Context, + req resource.ConfigureRequest, + resp *resource.ConfigureResponse, +) { // Add a nil check when handling ProviderData because Terraform // sets that data after it calls the ConfigureProvider RPC. if req.ProviderData == nil { @@ -72,15 +84,26 @@ func (r *wirelessNetworkResource) Configure(_ context.Context, req resource.Conf r.client = client } -func (r *wirelessNetworkResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { +func (r *wirelessNetworkResource) Create( + ctx context.Context, + req resource.CreateRequest, + resp *resource.CreateResponse, +) { // Retrieve values from plan var plan wirelessNetworkResourceModel diags := req.Plan.Get(ctx, &plan) - diags.AddError("operation not supported", "creating a wireless_network is not supported; wireless_networks can only be imported") + diags.AddError( + "operation not supported", + "creating a wireless_network is not supported; wireless_networks can only be imported", + ) resp.Diagnostics.Append(diags...) } -func (r *wirelessNetworkResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { +func (r *wirelessNetworkResource) Read( + ctx context.Context, + req resource.ReadRequest, + resp *resource.ReadResponse, +) { // Get current state var state wirelessNetworkResourceModel diags := req.State.Get(ctx, &state) @@ -120,22 +143,40 @@ func (r *wirelessNetworkResource) Read(ctx context.Context, req resource.ReadReq } } -func (r *wirelessNetworkResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { +func (r *wirelessNetworkResource) Update( + ctx context.Context, + req resource.UpdateRequest, + resp *resource.UpdateResponse, +) { // Retrieve values from plan var plan wirelessNetworkResourceModel diags := req.Plan.Get(ctx, &plan) - diags.AddError("operation not supported", "updating a wireless_network is not supported; wireless_networks can only be updated through the dashboard") + diags.AddError( + "operation not supported", + "updating a wireless_network is not supported; wireless_networks can only be updated through the dashboard", + ) resp.Diagnostics.Append(diags...) } -func (r *wirelessNetworkResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { +func (r *wirelessNetworkResource) Delete( + ctx context.Context, + req resource.DeleteRequest, + resp *resource.DeleteResponse, +) { // Retrieve values from state var state wirelessNetworkResourceModel diags := req.State.Get(ctx, &state) - diags.AddError("operation not supported", "deleting a wireless_network is not supported; wireless_networks can only removed from state") + diags.AddError( + "operation not supported", + "deleting a wireless_network is not supported; wireless_networks can only removed from state", + ) resp.Diagnostics.Append(diags...) } -func (r *wirelessNetworkResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *wirelessNetworkResource) ImportState( + ctx context.Context, + req resource.ImportStateRequest, + resp *resource.ImportStateResponse, +) { resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) } diff --git a/pkg/config-api-provider/provider/util/retry.go b/pkg/config-api-provider/provider/util/retry.go index 5c73e74d..7d9f03d4 100644 --- a/pkg/config-api-provider/provider/util/retry.go +++ b/pkg/config-api-provider/provider/util/retry.go @@ -23,12 +23,18 @@ func RetryFor429[T any](f func() (T, *http.Response, error)) (T, *http.Response, waitForSeconds := httpResponse.Header.Get("X-Ratelimit-Reset") if waitForSeconds == "" { - return result, httpResponse, errors.Join(err, errors.New("header X-Ratelimit-Reset is missing or contains non valid value")) + return result, httpResponse, errors.Join( + err, + errors.New("header X-Ratelimit-Reset is missing or contains non valid value"), + ) } rateLimitedFor, _ := strconv.Atoi(httpResponse.Header.Get("X-Ratelimit-Reset")) time.Sleep(time.Duration(rateLimitedFor) * time.Second) } - return result, httpResponse, errors.Join(err, errors.New("number of retries exceeded for 429 retries")) + return result, httpResponse, errors.Join( + err, + errors.New("number of retries exceeded for 429 retries"), + ) } diff --git a/pkg/config-api-provider/test/data-sources/agent_test.go b/pkg/config-api-provider/test/data-sources/agent_test.go index aee72f2c..458373b3 100644 --- a/pkg/config-api-provider/test/data-sources/agent_test.go +++ b/pkg/config-api-provider/test/data-sources/agent_test.go @@ -24,7 +24,9 @@ func TestAgentDataSource(t *testing.T) { PreConfig: func() { util.MockGetAgent( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}, + ), 3, ) }, @@ -63,7 +65,9 @@ func TestAgentDataSource429Handling(t *testing.T) { SetHeaders(util.RateLimitingHeaders) util.MockGetAgent( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}, + ), 3, ) }, @@ -114,7 +118,9 @@ func TestAgentDataSourceHttpErrorHandling(t *testing.T) { } } `, - ExpectError: regexp.MustCompile(`(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`), + ExpectError: regexp.MustCompile( + `(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`, + ), }, // Not found error { diff --git a/pkg/config-api-provider/test/data-sources/group_test.go b/pkg/config-api-provider/test/data-sources/group_test.go index e8ffbef9..cb8ffa0a 100644 --- a/pkg/config-api-provider/test/data-sources/group_test.go +++ b/pkg/config-api-provider/test/data-sources/group_test.go @@ -25,7 +25,11 @@ func TestGroupDataSource(t *testing.T) { PreConfig: func() { util.MockGetGroup( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("uid", "", ""), + }, + ), 3, ) }, @@ -45,12 +49,16 @@ func TestGroupDataSource(t *testing.T) { PreConfig: func() { util.MockGetGroup( "my_root_group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.StructToMap(config_api_client.GroupsGetItem{ - Id: "my_root_group_uid", - Name: "root", - Parent: *config_api_client.NewNullableParent(nil), - Path: "my_root_group_uid", - })}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.StructToMap(config_api_client.GroupsGetItem{ + Id: "my_root_group_uid", + Name: "root", + Parent: *config_api_client.NewNullableParent(nil), + Path: "my_root_group_uid", + }), + }, + ), 1, ) }, @@ -87,7 +95,11 @@ func TestGroupDataSource429Handling(t *testing.T) { SetHeaders(util.RateLimitingHeaders) util.MockGetGroup( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("uid", "", ""), + }, + ), 3, ) }, @@ -138,7 +150,9 @@ func TestGroupDataSourceHttpErrorHandling(t *testing.T) { } } `, - ExpectError: regexp.MustCompile(`(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`), + ExpectError: regexp.MustCompile( + `(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`, + ), }, // Not found error { 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 d854e30c..e4bae6a0 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 @@ -24,7 +24,11 @@ func TestNetworkGroupAssignmentDataSource(t *testing.T) { PreConfig: func() { util.MockGetNetworkGroupAssignment( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNetworkGroupAssignmentResponse("uid", ""), + }, + ), 3, ) }, @@ -36,9 +40,21 @@ func TestNetworkGroupAssignmentDataSource(t *testing.T) { } `, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.uxi_network_group_assignment.my_network_group_assignment", "id", "uid"), - resource.TestCheckResourceAttr("data.uxi_network_group_assignment.my_network_group_assignment", "group_id", "group_uid"), - resource.TestCheckResourceAttr("data.uxi_network_group_assignment.my_network_group_assignment", "network_id", "network_uid"), + resource.TestCheckResourceAttr( + "data.uxi_network_group_assignment.my_network_group_assignment", + "id", + "uid", + ), + resource.TestCheckResourceAttr( + "data.uxi_network_group_assignment.my_network_group_assignment", + "group_id", + "group_uid", + ), + resource.TestCheckResourceAttr( + "data.uxi_network_group_assignment.my_network_group_assignment", + "network_id", + "network_uid", + ), ), }, }, @@ -64,7 +80,11 @@ func TestNetworkGroupAssignmentDataSource429Handling(t *testing.T) { SetHeaders(util.RateLimitingHeaders) util.MockGetNetworkGroupAssignment( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNetworkGroupAssignmentResponse("uid", ""), + }, + ), 3, ) }, @@ -76,7 +96,11 @@ func TestNetworkGroupAssignmentDataSource429Handling(t *testing.T) { } `, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.uxi_network_group_assignment.my_network_group_assignment", "id", "uid"), + resource.TestCheckResourceAttr( + "data.uxi_network_group_assignment.my_network_group_assignment", + "id", + "uid", + ), func(s *terraform.State) error { st.Assert(t, mock429.Mock.Request().Counter, 0) return nil @@ -114,7 +138,9 @@ func TestNetworkGroupAssignmentDataSourceHttpErrorHandling(t *testing.T) { } } `, - ExpectError: regexp.MustCompile(`(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`), + ExpectError: regexp.MustCompile( + `(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`, + ), }, { PreConfig: func() { 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 31e4a84a..530a752b 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 @@ -24,7 +24,11 @@ func TestSensorGroupAssignmentDataSource(t *testing.T) { PreConfig: func() { util.MockGetSensorGroupAssignment( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentResponse("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateSensorGroupAssignmentResponse("uid", ""), + }, + ), 3, ) }, @@ -36,9 +40,21 @@ func TestSensorGroupAssignmentDataSource(t *testing.T) { } `, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.uxi_sensor_group_assignment.my_sensor_group_assignment", "id", "uid"), - resource.TestCheckResourceAttr("data.uxi_sensor_group_assignment.my_sensor_group_assignment", "group_id", "group_uid"), - resource.TestCheckResourceAttr("data.uxi_sensor_group_assignment.my_sensor_group_assignment", "sensor_id", "sensor_uid"), + resource.TestCheckResourceAttr( + "data.uxi_sensor_group_assignment.my_sensor_group_assignment", + "id", + "uid", + ), + resource.TestCheckResourceAttr( + "data.uxi_sensor_group_assignment.my_sensor_group_assignment", + "group_id", + "group_uid", + ), + resource.TestCheckResourceAttr( + "data.uxi_sensor_group_assignment.my_sensor_group_assignment", + "sensor_id", + "sensor_uid", + ), ), }, }, @@ -64,7 +80,11 @@ func TestSensorGroupAssignmentDataSource429Handling(t *testing.T) { SetHeaders(util.RateLimitingHeaders) util.MockGetSensorGroupAssignment( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentResponse("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateSensorGroupAssignmentResponse("uid", ""), + }, + ), 3, ) }, @@ -76,7 +96,11 @@ func TestSensorGroupAssignmentDataSource429Handling(t *testing.T) { } `, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.uxi_sensor_group_assignment.my_sensor_group_assignment", "id", "uid"), + resource.TestCheckResourceAttr( + "data.uxi_sensor_group_assignment.my_sensor_group_assignment", + "id", + "uid", + ), func(s *terraform.State) error { st.Assert(t, mock429.Mock.Request().Counter, 0) return nil @@ -113,7 +137,9 @@ func TestSensorGroupAssignmentDataSourceHttpErrorHandling(t *testing.T) { } } `, - ExpectError: regexp.MustCompile(`(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`), + ExpectError: regexp.MustCompile( + `(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`, + ), }, { PreConfig: func() { diff --git a/pkg/config-api-provider/test/data-sources/sensor_test.go b/pkg/config-api-provider/test/data-sources/sensor_test.go index 488c58fe..1ffb89ab 100644 --- a/pkg/config-api-provider/test/data-sources/sensor_test.go +++ b/pkg/config-api-provider/test/data-sources/sensor_test.go @@ -24,7 +24,9 @@ func TestSensorDataSource(t *testing.T) { PreConfig: func() { util.MockGetSensor( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorResponseModel("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateSensorResponseModel("uid", "")}, + ), 3, ) }, @@ -63,7 +65,9 @@ func TestSensorDataSource429Handling(t *testing.T) { SetHeaders(util.RateLimitingHeaders) util.MockGetSensor( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorResponseModel("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateSensorResponseModel("uid", "")}, + ), 3, ) }, @@ -114,7 +118,9 @@ func TestSensorDataSourceHttpErrorHandling(t *testing.T) { } } `, - ExpectError: regexp.MustCompile(`(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`), + ExpectError: regexp.MustCompile( + `(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`, + ), }, // Not found error { diff --git a/pkg/config-api-provider/test/data-sources/wired_network_test.go b/pkg/config-api-provider/test/data-sources/wired_network_test.go index 6c141474..0be48206 100644 --- a/pkg/config-api-provider/test/data-sources/wired_network_test.go +++ b/pkg/config-api-provider/test/data-sources/wired_network_test.go @@ -25,7 +25,9 @@ func TestWiredNetworkDataSource(t *testing.T) { PreConfig: func() { util.MockGetWiredNetwork( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}, + ), 3, ) }, @@ -37,15 +39,51 @@ func TestWiredNetworkDataSource(t *testing.T) { } `, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "id", "uid"), - resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "name", "name"), - resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "ip_version", "ip_version"), - resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "security", "security"), - resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "dns_lookup_domain", "dns_lookup_domain"), - resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "disable_edns", "false"), - resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "use_dns64", "false"), - resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "external_connectivity", "false"), - resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "vlan_id", "123"), + resource.TestCheckResourceAttr( + "data.uxi_wired_network.my_wired_network", + "id", + "uid", + ), + resource.TestCheckResourceAttr( + "data.uxi_wired_network.my_wired_network", + "name", + "name", + ), + resource.TestCheckResourceAttr( + "data.uxi_wired_network.my_wired_network", + "ip_version", + "ip_version", + ), + resource.TestCheckResourceAttr( + "data.uxi_wired_network.my_wired_network", + "security", + "security", + ), + resource.TestCheckResourceAttr( + "data.uxi_wired_network.my_wired_network", + "dns_lookup_domain", + "dns_lookup_domain", + ), + resource.TestCheckResourceAttr( + "data.uxi_wired_network.my_wired_network", + "disable_edns", + "false", + ), + resource.TestCheckResourceAttr( + "data.uxi_wired_network.my_wired_network", + "use_dns64", + "false", + ), + resource.TestCheckResourceAttr( + "data.uxi_wired_network.my_wired_network", + "external_connectivity", + "false", + ), + resource.TestCheckResourceAttr( + "data.uxi_wired_network.my_wired_network", + "vlan_id", + "123", + ), ), }, }, @@ -71,7 +109,9 @@ func TestWiredNetworkDataSource429Handling(t *testing.T) { SetHeaders(util.RateLimitingHeaders) util.MockGetWiredNetwork( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}, + ), 3, ) }, @@ -83,7 +123,11 @@ func TestWiredNetworkDataSource429Handling(t *testing.T) { } `, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "id", "uid"), + resource.TestCheckResourceAttr( + "data.uxi_wired_network.my_wired_network", + "id", + "uid", + ), func(s *terraform.State) error { st.Assert(t, mock429.Mock.Request().Counter, 0) return nil @@ -121,7 +165,9 @@ func TestWiredNetworkAssignmentDataSourceHttpErrorHandling(t *testing.T) { } } `, - ExpectError: regexp.MustCompile(`(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`), + ExpectError: regexp.MustCompile( + `(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`, + ), }, { PreConfig: func() { diff --git a/pkg/config-api-provider/test/data-sources/wireless_network_test.go b/pkg/config-api-provider/test/data-sources/wireless_network_test.go index 9117f0bb..32723160 100644 --- a/pkg/config-api-provider/test/data-sources/wireless_network_test.go +++ b/pkg/config-api-provider/test/data-sources/wireless_network_test.go @@ -25,7 +25,11 @@ func TestWirelessNetworkDataSource(t *testing.T) { PreConfig: func() { util.MockGetWirelessNetwork( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateWirelessNetworkResponse("uid", ""), + }, + ), 3, ) }, @@ -37,17 +41,61 @@ func TestWirelessNetworkDataSource(t *testing.T) { } `, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "id", "uid"), - resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "ssid", "ssid"), - resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "name", "name"), - resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "ip_version", "ip_version"), - resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "security", "security"), - resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "hidden", "false"), - resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "band_locking", "band_locking"), - resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "dns_lookup_domain", "dns_lookup_domain"), - resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "disable_edns", "false"), - resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "use_dns64", "false"), - resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "external_connectivity", "false"), + resource.TestCheckResourceAttr( + "data.uxi_wireless_network.my_wireless_network", + "id", + "uid", + ), + resource.TestCheckResourceAttr( + "data.uxi_wireless_network.my_wireless_network", + "ssid", + "ssid", + ), + resource.TestCheckResourceAttr( + "data.uxi_wireless_network.my_wireless_network", + "name", + "name", + ), + resource.TestCheckResourceAttr( + "data.uxi_wireless_network.my_wireless_network", + "ip_version", + "ip_version", + ), + resource.TestCheckResourceAttr( + "data.uxi_wireless_network.my_wireless_network", + "security", + "security", + ), + resource.TestCheckResourceAttr( + "data.uxi_wireless_network.my_wireless_network", + "hidden", + "false", + ), + resource.TestCheckResourceAttr( + "data.uxi_wireless_network.my_wireless_network", + "band_locking", + "band_locking", + ), + resource.TestCheckResourceAttr( + "data.uxi_wireless_network.my_wireless_network", + "dns_lookup_domain", + "dns_lookup_domain", + ), + resource.TestCheckResourceAttr( + "data.uxi_wireless_network.my_wireless_network", + "disable_edns", + "false", + ), + resource.TestCheckResourceAttr( + "data.uxi_wireless_network.my_wireless_network", + "use_dns64", + "false", + ), + resource.TestCheckResourceAttr( + "data.uxi_wireless_network.my_wireless_network", + "external_connectivity", + "false", + ), ), }, }, @@ -73,7 +121,11 @@ func TestWirelessNetworkDataSource429Handling(t *testing.T) { SetHeaders(util.RateLimitingHeaders) util.MockGetWirelessNetwork( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateWirelessNetworkResponse("uid", ""), + }, + ), 3, ) }, @@ -85,7 +137,11 @@ func TestWirelessNetworkDataSource429Handling(t *testing.T) { } `, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "id", "uid"), + resource.TestCheckResourceAttr( + "data.uxi_wireless_network.my_wireless_network", + "id", + "uid", + ), func(s *terraform.State) error { st.Assert(t, mock429.Mock.Request().Counter, 0) return nil @@ -123,7 +179,9 @@ func TestWirelessNetworkAssignmentDataSourceHttpErrorHandling(t *testing.T) { } } `, - ExpectError: regexp.MustCompile(`(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`), + ExpectError: regexp.MustCompile( + `(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`, + ), }, { PreConfig: func() { diff --git a/pkg/config-api-provider/test/resources/agent_group_assignment_test.go b/pkg/config-api-provider/test/resources/agent_group_assignment_test.go index 8510958e..707b1f39 100644 --- a/pkg/config-api-provider/test/resources/agent_group_assignment_test.go +++ b/pkg/config-api-provider/test/resources/agent_group_assignment_test.go @@ -23,7 +23,9 @@ func TestAgentGroupAssignmentResource(t *testing.T) { // required for agent import util.MockGetAgent( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}, + ), 2, ) @@ -35,12 +37,19 @@ func TestAgentGroupAssignmentResource(t *testing.T) { ) util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 1, ) // required for agent group assignment create - agentGroupAssignmentResponse := util.GenerateAgentGroupAssignmentResponse("agent_group_assignment_uid", "") + agentGroupAssignmentResponse := util.GenerateAgentGroupAssignmentResponse( + "agent_group_assignment_uid", + "", + ) resources.CreateAgentGroupAssignment = func(request resources.AgentGroupAssignmentRequestModel) resources.AgentGroupAssignmentResponseModel { return agentGroupAssignmentResponse } @@ -71,9 +80,21 @@ func TestAgentGroupAssignmentResource(t *testing.T) { group_id = uxi_group.my_group.id }`, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_agent_group_assignment.my_agent_group_assignment", "agent_id", "agent_uid"), - resource.TestCheckResourceAttr("uxi_agent_group_assignment.my_agent_group_assignment", "group_id", "group_uid"), - resource.TestCheckResourceAttr("uxi_agent_group_assignment.my_agent_group_assignment", "id", "agent_group_assignment_uid"), + resource.TestCheckResourceAttr( + "uxi_agent_group_assignment.my_agent_group_assignment", + "agent_id", + "agent_uid", + ), + resource.TestCheckResourceAttr( + "uxi_agent_group_assignment.my_agent_group_assignment", + "group_id", + "group_uid", + ), + resource.TestCheckResourceAttr( + "uxi_agent_group_assignment.my_agent_group_assignment", + "id", + "agent_group_assignment_uid", + ), ), }, // ImportState testing @@ -87,29 +108,47 @@ func TestAgentGroupAssignmentResource(t *testing.T) { PreConfig: func() { util.MockGetAgent( "agent_uid_2", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateAgentResponseModel("agent_uid_2", "_2")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateAgentResponseModel("agent_uid_2", "_2"), + }, + ), 2, ) util.MockGetAgent( "agent_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateAgentResponseModel("agent_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateAgentResponseModel("agent_uid", ""), + }, + ), 2, ) util.MockGetGroup( "group_uid_2", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + }, + ), 1, ) util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 2, ) // required for creating another group util.MockPostGroup( util.GenerateGroupRequestModel("group_uid_2", "_2", "_2"), - util.StructToMap(util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")), + util.StructToMap( + util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + ), 1, ) @@ -122,7 +161,10 @@ func TestAgentGroupAssignmentResource(t *testing.T) { } } resources.CreateAgentGroupAssignment = func(request resources.AgentGroupAssignmentRequestModel) resources.AgentGroupAssignmentResponseModel { - return util.GenerateAgentGroupAssignmentResponse("agent_group_assignment_uid_2", "_2") + return util.GenerateAgentGroupAssignmentResponse( + "agent_group_assignment_uid_2", + "_2", + ) } }, Config: provider.ProviderConfig + ` @@ -166,9 +208,21 @@ func TestAgentGroupAssignmentResource(t *testing.T) { group_id = uxi_group.my_group_2.id }`, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_agent_group_assignment.my_agent_group_assignment", "agent_id", "agent_uid_2"), - resource.TestCheckResourceAttr("uxi_agent_group_assignment.my_agent_group_assignment", "group_id", "group_uid_2"), - resource.TestCheckResourceAttr("uxi_agent_group_assignment.my_agent_group_assignment", "id", "agent_group_assignment_uid_2"), + resource.TestCheckResourceAttr( + "uxi_agent_group_assignment.my_agent_group_assignment", + "agent_id", + "agent_uid_2", + ), + resource.TestCheckResourceAttr( + "uxi_agent_group_assignment.my_agent_group_assignment", + "group_id", + "group_uid_2", + ), + resource.TestCheckResourceAttr( + "uxi_agent_group_assignment.my_agent_group_assignment", + "id", + "agent_group_assignment_uid_2", + ), ), }, // Delete testing automatically occurs in TestCase @@ -176,22 +230,38 @@ func TestAgentGroupAssignmentResource(t *testing.T) { PreConfig: func() { util.MockGetAgent( "agent_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateAgentResponseModel("agent_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateAgentResponseModel("agent_uid", ""), + }, + ), 2, ) util.MockGetAgent( "agent_uid_2", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateAgentResponseModel("agent_uid_2", "_2")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateAgentResponseModel("agent_uid_2", "_2"), + }, + ), 1, ) util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 2, ) util.MockGetGroup( "group_uid_2", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + }, + ), 1, ) util.MockDeleteGroup("group_uid", 1) diff --git a/pkg/config-api-provider/test/resources/agent_test.go b/pkg/config-api-provider/test/resources/agent_test.go index cd34160b..ec6eef64 100644 --- a/pkg/config-api-provider/test/resources/agent_test.go +++ b/pkg/config-api-provider/test/resources/agent_test.go @@ -28,14 +28,18 @@ func TestAgentResource(t *testing.T) { pcap_mode = "light" }`, - ExpectError: regexp.MustCompile(`creating an agent is not supported; agents can only be imported`), + ExpectError: regexp.MustCompile( + `creating an agent is not supported; agents can only be imported`, + ), }, // Importing an agent { PreConfig: func() { util.MockGetAgent( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}, + ), 2, ) }, @@ -63,7 +67,9 @@ func TestAgentResource(t *testing.T) { PreConfig: func() { util.MockGetAgent( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}, + ), 1, ) }, @@ -77,13 +83,17 @@ func TestAgentResource(t *testing.T) { // original util.MockGetAgent( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}, + ), 1, ) // updated util.MockGetAgent( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateAgentResponseModel("uid", "_2")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateAgentResponseModel("uid", "_2")}, + ), 1, ) }, @@ -193,7 +203,9 @@ func TestAgentResourceHttpErrorHandling(t *testing.T) { id = "uid" }`, - ExpectError: regexp.MustCompile(`(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`), + ExpectError: regexp.MustCompile( + `(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`, + ), }, // Read not found { diff --git a/pkg/config-api-provider/test/resources/group_test.go b/pkg/config-api-provider/test/resources/group_test.go index f65c89ed..fa2f4261 100644 --- a/pkg/config-api-provider/test/resources/group_test.go +++ b/pkg/config-api-provider/test/resources/group_test.go @@ -44,7 +44,11 @@ func TestGroupResource(t *testing.T) { }`, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("uxi_group.my_group", "name", "name"), - resource.TestCheckResourceAttr("uxi_group.my_group", "parent_group_id", "parent_uid"), + resource.TestCheckResourceAttr( + "uxi_group.my_group", + "parent_group_id", + "parent_uid", + ), resource.TestCheckResourceAttr("uxi_group.my_group", "id", "uid"), ), }, @@ -87,7 +91,11 @@ func TestGroupResource(t *testing.T) { }`, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("uxi_group.my_group", "name", "name_2"), - resource.TestCheckResourceAttr("uxi_group.my_group", "parent_group_id", "parent_uid"), + resource.TestCheckResourceAttr( + "uxi_group.my_group", + "parent_group_id", + "parent_uid", + ), resource.TestCheckResourceAttr("uxi_group.my_group", "id", "uid"), ), }, @@ -106,7 +114,10 @@ func TestGroupResource(t *testing.T) { 1, ) util.MockGetGroup("new_uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateGroupResponseModel("new_uid", "", "_2")}), + []map[string]interface{}{ + util.GenerateGroupResponseModel("new_uid", "", "_2"), + }, + ), 1, ) // delete old group (being replaced) @@ -119,7 +130,11 @@ func TestGroupResource(t *testing.T) { }`, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("uxi_group.my_group", "name", "name"), - resource.TestCheckResourceAttr("uxi_group.my_group", "parent_group_id", "parent_uid_2"), + resource.TestCheckResourceAttr( + "uxi_group.my_group", + "parent_group_id", + "parent_uid_2", + ), resource.TestCheckResourceAttr("uxi_group.my_group", "id", "new_uid"), ), }, @@ -127,7 +142,10 @@ func TestGroupResource(t *testing.T) { { PreConfig: func() { util.MockGetGroup("new_uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateGroupResponseModel("new_uid", "", "_2")}), + []map[string]interface{}{ + util.GenerateGroupResponseModel("new_uid", "", "_2"), + }, + ), 1, ) util.MockDeleteGroup("new_uid", 1) @@ -204,7 +222,11 @@ func TestGroupResource429Handling(t *testing.T) { ) util.MockGetGroup( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("uid", "", ""), + }, + ), 1, ) }, @@ -306,7 +328,9 @@ func TestGroupResourceHttpErrorHandling(t *testing.T) { id = "uid" } `, - ExpectError: regexp.MustCompile(`(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`), + ExpectError: regexp.MustCompile( + `(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`, + ), }, // Read not found { @@ -349,7 +373,9 @@ func TestGroupResourceHttpErrorHandling(t *testing.T) { name = "name" parent_group_id = "parent_uid" }`, - ExpectError: regexp.MustCompile(`(?s)Validation error - bad request\s*DebugID: 12312-123123-123123-1231212`), + ExpectError: regexp.MustCompile( + `(?s)Validation error - bad request\s*DebugID: 12312-123123-123123-1231212`, + ), }, // Create group in prep for next step { @@ -361,7 +387,11 @@ func TestGroupResourceHttpErrorHandling(t *testing.T) { ) util.MockGetGroup( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("uid", "", ""), + }, + ), 1, ) }, @@ -398,7 +428,9 @@ func TestGroupResourceHttpErrorHandling(t *testing.T) { name = "name_2" parent_group_id = "parent_uid" }`, - ExpectError: regexp.MustCompile(`(?s)Unable to create group - a sibling group already has the specified name\s*DebugID: 12312-123123-123123-1231212`), + ExpectError: regexp.MustCompile( + `(?s)Unable to create group - a sibling group already has the specified name\s*DebugID: 12312-123123-123123-1231212`, + ), }, // Delete 4xx { @@ -419,8 +451,10 @@ func TestGroupResourceHttpErrorHandling(t *testing.T) { "debugId": "12312-123123-123123-1231212", }) }, - Config: provider.ProviderConfig, - ExpectError: regexp.MustCompile(`(?s)Unable to delete group\s*DebugID: 12312-123123-123123-1231212`), + Config: provider.ProviderConfig, + ExpectError: regexp.MustCompile( + `(?s)Unable to delete group\s*DebugID: 12312-123123-123123-1231212`, + ), }, // Actually delete group for cleanup reasons { 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 63b294aa..0585a229 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 @@ -25,7 +25,11 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { PreConfig: func() { util.MockGetWiredNetwork( "network_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("network_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateWiredNetworkResponse("network_uid", ""), + }, + ), 2, ) @@ -36,19 +40,35 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { 1, ) util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 2, ) // required for network group assignment create util.MockPostNetworkGroupAssignment( - util.GenerateNetworkGroupAssignmentRequest("network_group_assignment_uid", ""), - util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", ""), + util.GenerateNetworkGroupAssignmentRequest( + "network_group_assignment_uid", + "", + ), + util.GenerateNetworkGroupAssignmentResponse( + "network_group_assignment_uid", + "", + ), 1, ) util.MockGetNetworkGroupAssignment( "network_group_assignment_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNetworkGroupAssignmentResponse( + "network_group_assignment_uid", + "", + ), + }, + ), 1, ) }, @@ -73,9 +93,21 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { group_id = uxi_group.my_group.id }`, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_network_group_assignment.my_network_group_assignment", "network_id", "network_uid"), - resource.TestCheckResourceAttr("uxi_network_group_assignment.my_network_group_assignment", "group_id", "group_uid"), - resource.TestCheckResourceAttr("uxi_network_group_assignment.my_network_group_assignment", "id", "network_group_assignment_uid"), + resource.TestCheckResourceAttr( + "uxi_network_group_assignment.my_network_group_assignment", + "network_id", + "network_uid", + ), + resource.TestCheckResourceAttr( + "uxi_network_group_assignment.my_network_group_assignment", + "group_id", + "group_uid", + ), + resource.TestCheckResourceAttr( + "uxi_network_group_assignment.my_network_group_assignment", + "id", + "network_group_assignment_uid", + ), ), }, // ImportState testing @@ -83,7 +115,14 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { PreConfig: func() { util.MockGetNetworkGroupAssignment( "network_group_assignment_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNetworkGroupAssignmentResponse( + "network_group_assignment_uid", + "", + ), + }, + ), 1, ) }, @@ -96,47 +135,85 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { PreConfig: func() { util.MockGetWiredNetwork( "network_uid_2", - util.GeneratePaginatedResponse([]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.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("network_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateWiredNetworkResponse("network_uid", ""), + }, + ), 2, ) util.MockGetGroup( "group_uid_2", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + }, + ), 1, ) util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 3, ) // required for creating another group util.MockPostGroup( util.GenerateGroupRequestModel("group_uid_2", "_2", "_2"), - util.StructToMap(util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")), + util.StructToMap( + util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + ), 1, ) // required for network group assignment create util.MockDeleteNetworkGroupAssignment("network_group_assignment_uid", 1) util.MockPostNetworkGroupAssignment( - util.GenerateNetworkGroupAssignmentRequest("network_group_assignment_uid_2", "_2"), - util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid_2", "_2"), + util.GenerateNetworkGroupAssignmentRequest( + "network_group_assignment_uid_2", + "_2", + ), + util.GenerateNetworkGroupAssignmentResponse( + "network_group_assignment_uid_2", + "_2", + ), 1, ) util.MockGetNetworkGroupAssignment( "network_group_assignment_uid_2", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid_2", "_2")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNetworkGroupAssignmentResponse( + "network_group_assignment_uid_2", + "_2", + ), + }, + ), 2, ) util.MockGetNetworkGroupAssignment( "network_group_assignment_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNetworkGroupAssignmentResponse( + "network_group_assignment_uid", + "", + ), + }, + ), 2, ) }, @@ -177,9 +254,21 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { group_id = uxi_group.my_group_2.id }`, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_network_group_assignment.my_network_group_assignment", "network_id", "network_uid_2"), - resource.TestCheckResourceAttr("uxi_network_group_assignment.my_network_group_assignment", "group_id", "group_uid_2"), - resource.TestCheckResourceAttr("uxi_network_group_assignment.my_network_group_assignment", "id", "network_group_assignment_uid_2"), + resource.TestCheckResourceAttr( + "uxi_network_group_assignment.my_network_group_assignment", + "network_id", + "network_uid_2", + ), + resource.TestCheckResourceAttr( + "uxi_network_group_assignment.my_network_group_assignment", + "group_id", + "group_uid_2", + ), + resource.TestCheckResourceAttr( + "uxi_network_group_assignment.my_network_group_assignment", + "id", + "network_group_assignment_uid_2", + ), ), }, // Delete network-group-assignments and remove networks from state @@ -187,30 +276,58 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { PreConfig: func() { util.MockGetWiredNetwork( "network_uid_2", - util.GeneratePaginatedResponse([]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.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("network_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateWiredNetworkResponse("network_uid", ""), + }, + ), 1, ) util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 2, ) util.MockGetGroup("group_uid_2", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")}), + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + }, + ), 1, ) util.MockGetNetworkGroupAssignment( "network_group_assignment_uid_2", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid_2", "_2")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNetworkGroupAssignmentResponse( + "network_group_assignment_uid_2", + "_2", + ), + }, + ), 1, ) util.MockGetNetworkGroupAssignment( "network_group_assignment_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNetworkGroupAssignmentResponse( + "network_group_assignment_uid", + "", + ), + }, + ), 1, ) @@ -256,7 +373,11 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { // required for network import util.MockGetWirelessNetwork( "network_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("network_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateWirelessNetworkResponse("network_uid", ""), + }, + ), 2, ) // required for group create @@ -267,19 +388,36 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { ) util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 1, ) // required for network group assignment create util.MockPostNetworkGroupAssignment( - util.GenerateNetworkGroupAssignmentRequest("network_group_assignment_uid", ""), - util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", ""), + util.GenerateNetworkGroupAssignmentRequest( + "network_group_assignment_uid", + "", + ), + util.GenerateNetworkGroupAssignmentResponse( + "network_group_assignment_uid", + "", + ), 1, ) util.MockGetNetworkGroupAssignment( "network_group_assignment_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNetworkGroupAssignmentResponse( + "network_group_assignment_uid", + "", + ), + }, + ), 1, ) }, @@ -304,9 +442,21 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { group_id = uxi_group.my_group.id }`, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_network_group_assignment.my_network_group_assignment", "network_id", "network_uid"), - resource.TestCheckResourceAttr("uxi_network_group_assignment.my_network_group_assignment", "group_id", "group_uid"), - resource.TestCheckResourceAttr("uxi_network_group_assignment.my_network_group_assignment", "id", "network_group_assignment_uid"), + resource.TestCheckResourceAttr( + "uxi_network_group_assignment.my_network_group_assignment", + "network_id", + "network_uid", + ), + resource.TestCheckResourceAttr( + "uxi_network_group_assignment.my_network_group_assignment", + "group_id", + "group_uid", + ), + resource.TestCheckResourceAttr( + "uxi_network_group_assignment.my_network_group_assignment", + "id", + "network_group_assignment_uid", + ), ), }, // ImportState testing @@ -314,7 +464,14 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { PreConfig: func() { util.MockGetNetworkGroupAssignment( "network_group_assignment_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNetworkGroupAssignmentResponse( + "network_group_assignment_uid", + "", + ), + }, + ), 1, ) }, @@ -327,12 +484,20 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { PreConfig: func() { util.MockGetWirelessNetwork( "network_uid_2", - util.GeneratePaginatedResponse([]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.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("network_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateWirelessNetworkResponse("network_uid", ""), + }, + ), 2, ) @@ -340,35 +505,65 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { util.MockDeleteNetworkGroupAssignment("network_group_assignment_uid", 1) util.MockPostGroup( util.GenerateGroupRequestModel("group_uid_2", "_2", "_2"), - util.StructToMap(util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")), + util.StructToMap( + util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + ), 1, ) util.MockGetGroup( "group_uid_2", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + }, + ), 1, ) util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 3, ) // required for network group assignment create util.MockGetNetworkGroupAssignment( "network_group_assignment_uid_2", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid_2", "_2")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNetworkGroupAssignmentResponse( + "network_group_assignment_uid_2", + "_2", + ), + }, + ), 2, ) util.MockGetNetworkGroupAssignment( "network_group_assignment_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNetworkGroupAssignmentResponse( + "network_group_assignment_uid", + "", + ), + }, + ), 2, ) util.MockPostNetworkGroupAssignment( - util.GenerateNetworkGroupAssignmentRequest("network_group_assignment_uid_2", "_2"), - util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid_2", "_2"), + util.GenerateNetworkGroupAssignmentRequest( + "network_group_assignment_uid_2", + "_2", + ), + util.GenerateNetworkGroupAssignmentResponse( + "network_group_assignment_uid_2", + "_2", + ), 1, ) }, @@ -409,9 +604,21 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { group_id = uxi_group.my_group_2.id }`, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_network_group_assignment.my_network_group_assignment", "network_id", "network_uid_2"), - resource.TestCheckResourceAttr("uxi_network_group_assignment.my_network_group_assignment", "group_id", "group_uid_2"), - resource.TestCheckResourceAttr("uxi_network_group_assignment.my_network_group_assignment", "id", "network_group_assignment_uid_2"), + resource.TestCheckResourceAttr( + "uxi_network_group_assignment.my_network_group_assignment", + "network_id", + "network_uid_2", + ), + resource.TestCheckResourceAttr( + "uxi_network_group_assignment.my_network_group_assignment", + "group_id", + "group_uid_2", + ), + resource.TestCheckResourceAttr( + "uxi_network_group_assignment.my_network_group_assignment", + "id", + "network_group_assignment_uid_2", + ), ), }, // Delete network-group-assignments and remove networks from state @@ -419,32 +626,62 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { PreConfig: func() { util.MockGetWirelessNetwork( "network_uid_2", - util.GeneratePaginatedResponse([]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.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("network_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateWirelessNetworkResponse("network_uid", ""), + }, + ), 1, ) util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 2, ) util.MockGetGroup( "group_uid_2", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + }, + ), 1, ) util.MockGetNetworkGroupAssignment( "network_group_assignment_uid_2", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid_2", "_2")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNetworkGroupAssignmentResponse( + "network_group_assignment_uid_2", + "_2", + ), + }, + ), 1, ) util.MockGetNetworkGroupAssignment( "network_group_assignment_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNetworkGroupAssignmentResponse( + "network_group_assignment_uid", + "", + ), + }, + ), 1, ) @@ -489,7 +726,11 @@ func TestNetworkGroupAssignmentResource429Handling(t *testing.T) { PreConfig: func() { util.MockGetWiredNetwork( "network_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("network_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateWiredNetworkResponse("network_uid", ""), + }, + ), 2, ) @@ -500,7 +741,10 @@ func TestNetworkGroupAssignmentResource429Handling(t *testing.T) { 1, ) util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 2, ) @@ -510,13 +754,26 @@ func TestNetworkGroupAssignmentResource429Handling(t *testing.T) { Reply(429). SetHeaders(util.RateLimitingHeaders) util.MockPostNetworkGroupAssignment( - util.GenerateNetworkGroupAssignmentRequest("network_group_assignment_uid", ""), - util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", ""), + util.GenerateNetworkGroupAssignmentRequest( + "network_group_assignment_uid", + "", + ), + util.GenerateNetworkGroupAssignmentResponse( + "network_group_assignment_uid", + "", + ), 1, ) util.MockGetNetworkGroupAssignment( "network_group_assignment_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNetworkGroupAssignmentResponse( + "network_group_assignment_uid", + "", + ), + }, + ), 1, ) }, @@ -541,7 +798,11 @@ func TestNetworkGroupAssignmentResource429Handling(t *testing.T) { group_id = uxi_group.my_group.id }`, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_network_group_assignment.my_network_group_assignment", "network_id", "network_uid"), + resource.TestCheckResourceAttr( + "uxi_network_group_assignment.my_network_group_assignment", + "network_id", + "network_uid", + ), func(s *terraform.State) error { st.Assert(t, mock429.Mock.Request().Counter, 0) return nil @@ -553,16 +814,30 @@ func TestNetworkGroupAssignmentResource429Handling(t *testing.T) { PreConfig: func() { util.MockGetWiredNetwork( "network_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("network_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateWiredNetworkResponse("network_uid", ""), + }, + ), 1, ) util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 1, ) util.MockGetNetworkGroupAssignment( "network_group_assignment_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNetworkGroupAssignmentResponse( + "network_group_assignment_uid", + "", + ), + }, + ), 1, ) @@ -606,7 +881,11 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { PreConfig: func() { util.MockGetWiredNetwork( "network_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("network_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateWiredNetworkResponse("network_uid", ""), + }, + ), 2, ) @@ -617,7 +896,10 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { 1, ) util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 2, ) @@ -652,14 +934,20 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { network_id = uxi_wired_network.my_network.id group_id = uxi_group.my_group.id }`, - ExpectError: regexp.MustCompile(`(?s)Validation error - bad request\s*DebugID: 12312-123123-123123-1231212`), + ExpectError: regexp.MustCompile( + `(?s)Validation error - bad request\s*DebugID: 12312-123123-123123-1231212`, + ), }, // read not found error { PreConfig: func() { util.MockGetWiredNetwork( "network_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("network_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateWiredNetworkResponse("network_uid", ""), + }, + ), 2, ) @@ -670,7 +958,10 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { 1, ) util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 2, ) @@ -713,7 +1004,11 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { PreConfig: func() { util.MockGetWiredNetwork( "network_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("network_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateWiredNetworkResponse("network_uid", ""), + }, + ), 2, ) @@ -724,7 +1019,10 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { 1, ) util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 2, ) @@ -765,14 +1063,20 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { } `, - ExpectError: regexp.MustCompile(`(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`), + ExpectError: regexp.MustCompile( + `(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`, + ), }, // Actually creating a network group assignment - for next step { PreConfig: func() { util.MockGetWiredNetwork( "network_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("network_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateWiredNetworkResponse("network_uid", ""), + }, + ), 2, ) @@ -783,19 +1087,35 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { 1, ) util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 2, ) // required for network group assignment create util.MockPostNetworkGroupAssignment( - util.GenerateNetworkGroupAssignmentRequest("network_group_assignment_uid", ""), - util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", ""), + util.GenerateNetworkGroupAssignmentRequest( + "network_group_assignment_uid", + "", + ), + util.GenerateNetworkGroupAssignmentResponse( + "network_group_assignment_uid", + "", + ), 1, ) util.MockGetNetworkGroupAssignment( "network_group_assignment_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNetworkGroupAssignmentResponse( + "network_group_assignment_uid", + "", + ), + }, + ), 1, ) }, @@ -820,7 +1140,11 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { group_id = uxi_group.my_group.id }`, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_network_group_assignment.my_network_group_assignment", "network_id", "network_uid"), + resource.TestCheckResourceAttr( + "uxi_network_group_assignment.my_network_group_assignment", + "network_id", + "network_uid", + ), ), }, // Delete network-group assignment and remove networks from state - errors @@ -828,16 +1152,30 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { PreConfig: func() { util.MockGetWiredNetwork( "network_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("network_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateWiredNetworkResponse("network_uid", ""), + }, + ), 1, ) util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 1, ) util.MockGetNetworkGroupAssignment( "network_group_assignment_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNetworkGroupAssignmentResponse( + "network_group_assignment_uid", + "", + ), + }, + ), 1, ) @@ -861,23 +1199,39 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { destroy = false } }`, - ExpectError: regexp.MustCompile(`(?s)Forbidden - user has insufficient permissions to complete the request\s*DebugID: 12312-123123-123123-1231212`), + ExpectError: regexp.MustCompile( + `(?s)Forbidden - user has insufficient permissions to complete the request\s*DebugID: 12312-123123-123123-1231212`, + ), }, // Actually delete network-group assignment and remove networks from state { PreConfig: func() { util.MockGetWiredNetwork( "network_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("network_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateWiredNetworkResponse("network_uid", ""), + }, + ), 1, ) util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 1, ) util.MockGetNetworkGroupAssignment( "network_group_assignment_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNetworkGroupAssignmentResponse( + "network_group_assignment_uid", + "", + ), + }, + ), 1, ) util.MockDeleteGroup("group_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 f42f8514..952928c4 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 @@ -24,7 +24,10 @@ func TestSensorGroupAssignmentResource(t *testing.T) { PreConfig: func() { // required for sensor import util.MockGetSensor("uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateSensorResponseModel("sensor_uid", "")}), + []map[string]interface{}{ + util.GenerateSensorResponseModel("sensor_uid", ""), + }, + ), 2, ) @@ -36,19 +39,36 @@ func TestSensorGroupAssignmentResource(t *testing.T) { ) util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 1, ) // required for sensor group assignment create util.MockPostSensorGroupAssignment( - util.GenerateSensorGroupAssignmentRequest("sensor_group_assignment_uid", ""), - util.GenerateSensorGroupAssignmentResponse("sensor_group_assignment_uid", ""), + util.GenerateSensorGroupAssignmentRequest( + "sensor_group_assignment_uid", + "", + ), + util.GenerateSensorGroupAssignmentResponse( + "sensor_group_assignment_uid", + "", + ), 1, ) util.MockGetSensorGroupAssignment( "sensor_group_assignment_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentResponse("sensor_group_assignment_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateSensorGroupAssignmentResponse( + "sensor_group_assignment_uid", + "", + ), + }, + ), 1, ) }, @@ -76,9 +96,21 @@ func TestSensorGroupAssignmentResource(t *testing.T) { group_id = uxi_group.my_group.id }`, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_sensor_group_assignment.my_sensor_group_assignment", "sensor_id", "sensor_uid"), - resource.TestCheckResourceAttr("uxi_sensor_group_assignment.my_sensor_group_assignment", "group_id", "group_uid"), - resource.TestCheckResourceAttr("uxi_sensor_group_assignment.my_sensor_group_assignment", "id", "sensor_group_assignment_uid"), + resource.TestCheckResourceAttr( + "uxi_sensor_group_assignment.my_sensor_group_assignment", + "sensor_id", + "sensor_uid", + ), + resource.TestCheckResourceAttr( + "uxi_sensor_group_assignment.my_sensor_group_assignment", + "group_id", + "group_uid", + ), + resource.TestCheckResourceAttr( + "uxi_sensor_group_assignment.my_sensor_group_assignment", + "id", + "sensor_group_assignment_uid", + ), ), }, // ImportState testing @@ -86,7 +118,14 @@ func TestSensorGroupAssignmentResource(t *testing.T) { PreConfig: func() { util.MockGetSensorGroupAssignment( "sensor_group_assignment_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentResponse("sensor_group_assignment_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateSensorGroupAssignmentResponse( + "sensor_group_assignment_uid", + "", + ), + }, + ), 1, ) }, @@ -98,22 +137,36 @@ func TestSensorGroupAssignmentResource(t *testing.T) { { PreConfig: func() { util.MockGetSensor("sensor_uid_2", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateSensorResponseModel("sensor_uid_2", "_2")}), + []map[string]interface{}{ + util.GenerateSensorResponseModel("sensor_uid_2", "_2"), + }, + ), 2, ) util.MockGetSensor("sensor_uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateSensorResponseModel("sensor_uid", "")}), + []map[string]interface{}{ + util.GenerateSensorResponseModel("sensor_uid", ""), + }, + ), 3, ) util.MockGetGroup( "group_uid_2", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + }, + ), 1, ) util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 2, ) @@ -121,25 +174,47 @@ func TestSensorGroupAssignmentResource(t *testing.T) { util.MockDeleteSensorGroupAssignment("sensor_group_assignment_uid", 1) util.MockPostGroup( util.GenerateGroupRequestModel("group_uid_2", "_2", "_2"), - util.StructToMap(util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")), + util.StructToMap( + util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + ), 1, ) // required for sensor group assignment create util.MockGetSensorGroupAssignment( "sensor_group_assignment_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentResponse("sensor_group_assignment_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateSensorGroupAssignmentResponse( + "sensor_group_assignment_uid", + "", + ), + }, + ), 1, ) util.MockGetSensorGroupAssignment( "sensor_group_assignment_uid_2", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentResponse("sensor_group_assignment_uid_2", "_2")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateSensorGroupAssignmentResponse( + "sensor_group_assignment_uid_2", + "_2", + ), + }, + ), 1, ) util.MockPostSensorGroupAssignment( - util.GenerateSensorGroupAssignmentRequest("sensor_group_assignment_uid_2", "_2"), - util.GenerateSensorGroupAssignmentResponse("sensor_group_assignment_uid_2", "_2"), + util.GenerateSensorGroupAssignmentRequest( + "sensor_group_assignment_uid_2", + "_2", + ), + util.GenerateSensorGroupAssignmentResponse( + "sensor_group_assignment_uid_2", + "_2", + ), 1, ) }, @@ -186,9 +261,21 @@ func TestSensorGroupAssignmentResource(t *testing.T) { group_id = uxi_group.my_group_2.id }`, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_sensor_group_assignment.my_sensor_group_assignment", "sensor_id", "sensor_uid_2"), - resource.TestCheckResourceAttr("uxi_sensor_group_assignment.my_sensor_group_assignment", "group_id", "group_uid_2"), - resource.TestCheckResourceAttr("uxi_sensor_group_assignment.my_sensor_group_assignment", "id", "sensor_group_assignment_uid_2"), + resource.TestCheckResourceAttr( + "uxi_sensor_group_assignment.my_sensor_group_assignment", + "sensor_id", + "sensor_uid_2", + ), + resource.TestCheckResourceAttr( + "uxi_sensor_group_assignment.my_sensor_group_assignment", + "group_id", + "group_uid_2", + ), + resource.TestCheckResourceAttr( + "uxi_sensor_group_assignment.my_sensor_group_assignment", + "id", + "sensor_group_assignment_uid_2", + ), ), }, // Delete sensor-group assignments and remove sensors from state @@ -196,17 +283,32 @@ func TestSensorGroupAssignmentResource(t *testing.T) { PreConfig: func() { util.MockGetGroup( "group_uid_2", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + }, + ), 1, ) util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 1, ) util.MockGetSensorGroupAssignment( "sensor_group_assignment_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentResponse("sensor_group_assignment_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateSensorGroupAssignmentResponse( + "sensor_group_assignment_uid", + "", + ), + }, + ), 1, ) @@ -250,7 +352,10 @@ func TestSensorGroupAssignmentResource429Handling(t *testing.T) { PreConfig: func() { // required for sensor import util.MockGetSensor("sensor_uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateSensorResponseModel("sensor_uid", "")}), + []map[string]interface{}{ + util.GenerateSensorResponseModel("sensor_uid", ""), + }, + ), 2, ) @@ -262,7 +367,11 @@ func TestSensorGroupAssignmentResource429Handling(t *testing.T) { ) util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 1, ) @@ -272,13 +381,26 @@ func TestSensorGroupAssignmentResource429Handling(t *testing.T) { Reply(429). SetHeaders(util.RateLimitingHeaders) util.MockPostSensorGroupAssignment( - util.GenerateSensorGroupAssignmentRequest("sensor_group_assignment_uid", ""), - util.GenerateSensorGroupAssignmentResponse("sensor_group_assignment_uid", ""), + util.GenerateSensorGroupAssignmentRequest( + "sensor_group_assignment_uid", + "", + ), + util.GenerateSensorGroupAssignmentResponse( + "sensor_group_assignment_uid", + "", + ), 1, ) util.MockGetSensorGroupAssignment( "sensor_group_assignment_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentResponse("sensor_group_assignment_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateSensorGroupAssignmentResponse( + "sensor_group_assignment_uid", + "", + ), + }, + ), 1, ) }, @@ -306,7 +428,11 @@ func TestSensorGroupAssignmentResource429Handling(t *testing.T) { group_id = uxi_group.my_group.id }`, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_sensor_group_assignment.my_sensor_group_assignment", "id", "sensor_group_assignment_uid"), + resource.TestCheckResourceAttr( + "uxi_sensor_group_assignment.my_sensor_group_assignment", + "id", + "sensor_group_assignment_uid", + ), func(s *terraform.State) error { st.Assert(t, mock429.Mock.Request().Counter, 0) return nil @@ -318,12 +444,23 @@ func TestSensorGroupAssignmentResource429Handling(t *testing.T) { PreConfig: func() { util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 1, ) util.MockGetSensorGroupAssignment( "sensor_group_assignment_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentResponse("sensor_group_assignment_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateSensorGroupAssignmentResponse( + "sensor_group_assignment_uid", + "", + ), + }, + ), 1, ) @@ -375,7 +512,10 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { PreConfig: func() { // required for sensor import util.MockGetSensor("sensor_uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateSensorResponseModel("sensor_uid", "")}), + []map[string]interface{}{ + util.GenerateSensorResponseModel("sensor_uid", ""), + }, + ), 1, ) @@ -387,7 +527,11 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { ) util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 1, ) @@ -425,14 +569,19 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { sensor_id = uxi_sensor.my_sensor.id group_id = uxi_group.my_group.id }`, - ExpectError: regexp.MustCompile(`(?s)Validation error - bad request\s*DebugID: 12312-123123-123123-1231212`), + ExpectError: regexp.MustCompile( + `(?s)Validation error - bad request\s*DebugID: 12312-123123-123123-1231212`, + ), }, // read not found error { PreConfig: func() { // required for sensor import util.MockGetSensor("sensor_uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateSensorResponseModel("sensor_uid", "")}), + []map[string]interface{}{ + util.GenerateSensorResponseModel("sensor_uid", ""), + }, + ), 1, ) @@ -444,7 +593,11 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { ) util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 1, ) @@ -490,7 +643,10 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { PreConfig: func() { // required for sensor import util.MockGetSensor("sensor_uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateSensorResponseModel("sensor_uid", "")}), + []map[string]interface{}{ + util.GenerateSensorResponseModel("sensor_uid", ""), + }, + ), 1, ) @@ -502,7 +658,11 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { ) util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 1, ) @@ -546,14 +706,19 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { } `, - ExpectError: regexp.MustCompile(`(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`), + ExpectError: regexp.MustCompile( + `(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`, + ), }, // Actually Creating a sensor group assignment - needed for next step { PreConfig: func() { // required for sensor import util.MockGetSensor("sensor_uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateSensorResponseModel("sensor_uid", "")}), + []map[string]interface{}{ + util.GenerateSensorResponseModel("sensor_uid", ""), + }, + ), 2, ) @@ -565,19 +730,36 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { ) util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 1, ) // required for sensor group assignment create util.MockPostSensorGroupAssignment( - util.GenerateSensorGroupAssignmentRequest("sensor_group_assignment_uid", ""), - util.GenerateSensorGroupAssignmentResponse("sensor_group_assignment_uid", ""), + util.GenerateSensorGroupAssignmentRequest( + "sensor_group_assignment_uid", + "", + ), + util.GenerateSensorGroupAssignmentResponse( + "sensor_group_assignment_uid", + "", + ), 1, ) util.MockGetSensorGroupAssignment( "sensor_group_assignment_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentResponse("sensor_group_assignment_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateSensorGroupAssignmentResponse( + "sensor_group_assignment_uid", + "", + ), + }, + ), 1, ) }, @@ -605,7 +787,11 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { group_id = uxi_group.my_group.id }`, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_sensor_group_assignment.my_sensor_group_assignment", "id", "sensor_group_assignment_uid"), + resource.TestCheckResourceAttr( + "uxi_sensor_group_assignment.my_sensor_group_assignment", + "id", + "sensor_group_assignment_uid", + ), ), }, // Delete sensor-group assignments and remove sensors from state - errors @@ -613,12 +799,23 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { PreConfig: func() { util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 1, ) util.MockGetSensorGroupAssignment( "sensor_group_assignment_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentResponse("sensor_group_assignment_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateSensorGroupAssignmentResponse( + "sensor_group_assignment_uid", + "", + ), + }, + ), 1, ) @@ -648,19 +845,32 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { destroy = false } }`, - ExpectError: regexp.MustCompile(`(?s)Validation error - bad request\s*DebugID: 12312-123123-123123-1231212`), + ExpectError: regexp.MustCompile( + `(?s)Validation error - bad request\s*DebugID: 12312-123123-123123-1231212`, + ), }, // Actually Delete sensor-group assignments and remove sensors from state { PreConfig: func() { util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 1, ) util.MockGetSensorGroupAssignment( "sensor_group_assignment_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentResponse("sensor_group_assignment_uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateSensorGroupAssignmentResponse( + "sensor_group_assignment_uid", + "", + ), + }, + ), 1, ) util.MockDeleteGroup("group_uid", 1) diff --git a/pkg/config-api-provider/test/resources/sensor_test.go b/pkg/config-api-provider/test/resources/sensor_test.go index 0cee7715..6c84d0a4 100644 --- a/pkg/config-api-provider/test/resources/sensor_test.go +++ b/pkg/config-api-provider/test/resources/sensor_test.go @@ -34,7 +34,9 @@ func TestSensorResource(t *testing.T) { pcap_mode = "light" }`, - ExpectError: regexp.MustCompile(`creating a sensor is not supported; sensors can only be imported`), + ExpectError: regexp.MustCompile( + `creating a sensor is not supported; sensors can only be imported`, + ), }, // Importing a sensor { @@ -59,7 +61,11 @@ func TestSensorResource(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "name", "name"), - resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "address_note", "address_note"), + resource.TestCheckResourceAttr( + "uxi_sensor.my_sensor", + "address_note", + "address_note", + ), resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "notes", "notes"), resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "pcap_mode", "light"), resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "id", "uid"), @@ -100,7 +106,11 @@ func TestSensorResource(t *testing.T) { }`, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "name", "name_2"), - resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "address_note", "address_note_2"), + resource.TestCheckResourceAttr( + "uxi_sensor.my_sensor", + "address_note", + "address_note_2", + ), resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "notes", "notes_2"), resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "pcap_mode", "light_2"), resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "id", "uid"), @@ -114,8 +124,10 @@ func TestSensorResource(t *testing.T) { 1, ) }, - Config: provider.ProviderConfig + ``, - ExpectError: regexp.MustCompile(`deleting a sensor is not supported; sensors can only removed from state`), + Config: provider.ProviderConfig + ``, + ExpectError: regexp.MustCompile( + `deleting a sensor is not supported; sensors can only removed from state`, + ), }, // Remove sensor from state { @@ -233,7 +245,9 @@ func TestSensorResourceHttpErrorHandling(t *testing.T) { id = "uid" }`, - ExpectError: regexp.MustCompile(`(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`), + ExpectError: regexp.MustCompile( + `(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`, + ), }, // Read not found { diff --git a/pkg/config-api-provider/test/resources/service_test.go b/pkg/config-api-provider/test/resources/service_test.go index 28f286cd..b69e97de 100644 --- a/pkg/config-api-provider/test/resources/service_test.go +++ b/pkg/config-api-provider/test/resources/service_test.go @@ -30,7 +30,9 @@ func TestServiceTestResource(t *testing.T) { name = "name" }`, - ExpectError: regexp.MustCompile(`(?s)creating a service_test is not supported; service_tests can only be\s*imported`), + ExpectError: regexp.MustCompile( + `(?s)creating a service_test is not supported; service_tests can only be\s*imported`, + ), }, // Importing a service_test { @@ -50,7 +52,11 @@ func TestServiceTestResource(t *testing.T) { }`, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_service_test.my_service_test", "name", "name"), + resource.TestCheckResourceAttr( + "uxi_service_test.my_service_test", + "name", + "name", + ), resource.TestCheckResourceAttr("uxi_service_test.my_service_test", "id", "uid"), ), }, @@ -66,12 +72,16 @@ func TestServiceTestResource(t *testing.T) { resource "uxi_service_test" "my_service_test" { name = "updated_name" }`, - ExpectError: regexp.MustCompile(`(?s)updating a service_test is not supported; service_tests can only be updated\s*through the dashboard`), + ExpectError: regexp.MustCompile( + `(?s)updating a service_test is not supported; service_tests can only be updated\s*through the dashboard`, + ), }, // Deleting a service_test is not allowed { - Config: provider.ProviderConfig + ``, - ExpectError: regexp.MustCompile(`(?s)deleting a service_test is not supported; service_tests can only removed from\s*state`), + Config: provider.ProviderConfig + ``, + ExpectError: regexp.MustCompile( + `(?s)deleting a service_test is not supported; service_tests can only removed from\s*state`, + ), }, // Remove service_test from state { diff --git a/pkg/config-api-provider/test/resources/service_test_group_assignment_test.go b/pkg/config-api-provider/test/resources/service_test_group_assignment_test.go index 6842770b..4986c7e9 100644 --- a/pkg/config-api-provider/test/resources/service_test_group_assignment_test.go +++ b/pkg/config-api-provider/test/resources/service_test_group_assignment_test.go @@ -38,18 +38,33 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { ) util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 1, ) // required for serviceTest group assignment create util.MockPostServiceTestGroupAssignment( - util.GenerateServiceTestGroupAssignmentRequest("service_test_group_assignment_uid", ""), - util.StructToMap(util.GenerateServiceTestGroupAssignmentResponse("service_test_group_assignment_uid", "")), + util.GenerateServiceTestGroupAssignmentRequest( + "service_test_group_assignment_uid", + "", + ), + util.StructToMap( + util.GenerateServiceTestGroupAssignmentResponse( + "service_test_group_assignment_uid", + "", + ), + ), 1, ) resources.GetServiceTestGroupAssignment = func(uid string) config_api_client.ServiceTestGroupAssignmentsPostResponse { - return util.GenerateServiceTestGroupAssignmentResponse("service_test_group_assignment_uid", "") + return util.GenerateServiceTestGroupAssignmentResponse( + "service_test_group_assignment_uid", + "", + ) } }, @@ -73,9 +88,21 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { group_id = uxi_group.my_group.id }`, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_service_test_group_assignment.my_service_test_group_assignment", "service_test_id", "service_test_uid"), - resource.TestCheckResourceAttr("uxi_service_test_group_assignment.my_service_test_group_assignment", "group_id", "group_uid"), - resource.TestCheckResourceAttr("uxi_service_test_group_assignment.my_service_test_group_assignment", "id", "service_test_group_assignment_uid"), + resource.TestCheckResourceAttr( + "uxi_service_test_group_assignment.my_service_test_group_assignment", + "service_test_id", + "service_test_uid", + ), + resource.TestCheckResourceAttr( + "uxi_service_test_group_assignment.my_service_test_group_assignment", + "group_id", + "group_uid", + ), + resource.TestCheckResourceAttr( + "uxi_service_test_group_assignment.my_service_test_group_assignment", + "id", + "service_test_group_assignment_uid", + ), ), }, // ImportState testing @@ -96,12 +123,20 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { } util.MockGetGroup( "group_uid_2", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + }, + ), 1, ) util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 3, ) @@ -111,21 +146,34 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { // required for creating another group util.MockPostGroup( util.GenerateGroupRequestModel("group_uid_2", "_2", "_2"), - util.StructToMap(util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")), + util.StructToMap( + util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + ), 1, ) // required for serviceTest group assignment create resources.GetServiceTestGroupAssignment = func(uid string) config_api_client.ServiceTestGroupAssignmentsPostResponse { if uid == "service_test_group_assignment_uid" { - return util.GenerateServiceTestGroupAssignmentResponse("service_test_group_assignment_uid", "") + return util.GenerateServiceTestGroupAssignmentResponse( + "service_test_group_assignment_uid", + "", + ) } else { return util.GenerateServiceTestGroupAssignmentResponse("service_test_group_assignment_uid_2", "_2") } } util.MockPostServiceTestGroupAssignment( - util.GenerateServiceTestGroupAssignmentRequest("service_test_group_assignment_uid_2", "_2"), - util.StructToMap(util.GenerateServiceTestGroupAssignmentResponse("service_test_group_assignment_uid_2", "_2")), + util.GenerateServiceTestGroupAssignmentRequest( + "service_test_group_assignment_uid_2", + "_2", + ), + util.StructToMap( + util.GenerateServiceTestGroupAssignmentResponse( + "service_test_group_assignment_uid_2", + "_2", + ), + ), 1, ) }, @@ -166,9 +214,21 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { group_id = uxi_group.my_group_2.id }`, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_service_test_group_assignment.my_service_test_group_assignment", "service_test_id", "service_test_uid_2"), - resource.TestCheckResourceAttr("uxi_service_test_group_assignment.my_service_test_group_assignment", "group_id", "group_uid_2"), - resource.TestCheckResourceAttr("uxi_service_test_group_assignment.my_service_test_group_assignment", "id", "service_test_group_assignment_uid_2"), + resource.TestCheckResourceAttr( + "uxi_service_test_group_assignment.my_service_test_group_assignment", + "service_test_id", + "service_test_uid_2", + ), + resource.TestCheckResourceAttr( + "uxi_service_test_group_assignment.my_service_test_group_assignment", + "group_id", + "group_uid_2", + ), + resource.TestCheckResourceAttr( + "uxi_service_test_group_assignment.my_service_test_group_assignment", + "id", + "service_test_group_assignment_uid_2", + ), ), }, // Remove serviceTests from state @@ -176,18 +236,29 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { PreConfig: func() { util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 1, ) util.MockGetGroup( "group_uid_2", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid_2", "_2", "_2"), + }, + ), 1, ) util.MockDeleteGroup("group_uid", 1) util.MockDeleteGroup("group_uid_2", 1) - util.MockDeleteServiceTestGroupAssignment("service_test_group_assignment_uid_2", 1) + util.MockDeleteServiceTestGroupAssignment( + "service_test_group_assignment_uid_2", + 1, + ) }, Config: provider.ProviderConfig + ` removed { @@ -236,7 +307,11 @@ func TestServiceTestGroupAssignmentResource429Handling(t *testing.T) { ) util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 1, ) @@ -247,12 +322,23 @@ func TestServiceTestGroupAssignmentResource429Handling(t *testing.T) { SetHeaders(util.RateLimitingHeaders) util.MockPostServiceTestGroupAssignment( - util.GenerateServiceTestGroupAssignmentRequest("service_test_group_assignment_uid", ""), - util.StructToMap(util.GenerateServiceTestGroupAssignmentResponse("service_test_group_assignment_uid", "")), + util.GenerateServiceTestGroupAssignmentRequest( + "service_test_group_assignment_uid", + "", + ), + util.StructToMap( + util.GenerateServiceTestGroupAssignmentResponse( + "service_test_group_assignment_uid", + "", + ), + ), 1, ) resources.GetServiceTestGroupAssignment = func(uid string) config_api_client.ServiceTestGroupAssignmentsPostResponse { - return util.GenerateServiceTestGroupAssignmentResponse("service_test_group_assignment_uid", "") + return util.GenerateServiceTestGroupAssignmentResponse( + "service_test_group_assignment_uid", + "", + ) } }, @@ -276,7 +362,11 @@ func TestServiceTestGroupAssignmentResource429Handling(t *testing.T) { group_id = uxi_group.my_group.id }`, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_service_test_group_assignment.my_service_test_group_assignment", "id", "service_test_group_assignment_uid"), + resource.TestCheckResourceAttr( + "uxi_service_test_group_assignment.my_service_test_group_assignment", + "id", + "service_test_group_assignment_uid", + ), func(s *terraform.State) error { st.Assert(t, mock429.Mock.Request().Counter, 0) return nil @@ -288,7 +378,11 @@ func TestServiceTestGroupAssignmentResource429Handling(t *testing.T) { PreConfig: func() { util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 1, ) @@ -333,7 +427,11 @@ func TestServiceTestGroupAssignmentResourceHttpErrorHandling(t *testing.T) { ) util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_uid", "", ""), + }, + ), 1, ) @@ -368,14 +466,20 @@ func TestServiceTestGroupAssignmentResourceHttpErrorHandling(t *testing.T) { service_test_id = uxi_service_test.my_service_test.id group_id = uxi_group.my_group.id }`, - ExpectError: regexp.MustCompile(`(?s)Validation error - bad request\s*DebugID: 12312-123123-123123-1231212`), + ExpectError: regexp.MustCompile( + `(?s)Validation error - bad request\s*DebugID: 12312-123123-123123-1231212`, + ), }, // Remove serviceTests from state { PreConfig: func() { util.MockGetGroup( "group_uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateGroupResponseModel("group_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 33b0de16..ec0c97ce 100644 --- a/pkg/config-api-provider/test/resources/wired_network_test.go +++ b/pkg/config-api-provider/test/resources/wired_network_test.go @@ -29,14 +29,18 @@ func TestWiredNetworkResource(t *testing.T) { name = "name" }`, - ExpectError: regexp.MustCompile(`(?s)creating a wired_network is not supported; wired_networks can only be\s*imported`), + ExpectError: regexp.MustCompile( + `(?s)creating a wired_network is not supported; wired_networks can only be\s*imported`, + ), }, // Importing a wired_network { PreConfig: func() { util.MockGetWiredNetwork( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}, + ), 2, ) }, @@ -51,8 +55,16 @@ func TestWiredNetworkResource(t *testing.T) { }`, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_wired_network.my_wired_network", "name", "name"), - resource.TestCheckResourceAttr("uxi_wired_network.my_wired_network", "id", "uid"), + resource.TestCheckResourceAttr( + "uxi_wired_network.my_wired_network", + "name", + "name", + ), + resource.TestCheckResourceAttr( + "uxi_wired_network.my_wired_network", + "id", + "uid", + ), ), }, // ImportState testing @@ -60,7 +72,9 @@ func TestWiredNetworkResource(t *testing.T) { PreConfig: func() { util.MockGetWiredNetwork( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}, + ), 1, ) }, @@ -73,7 +87,9 @@ func TestWiredNetworkResource(t *testing.T) { PreConfig: func() { util.MockGetWiredNetwork( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}, + ), 1, ) }, @@ -81,19 +97,25 @@ func TestWiredNetworkResource(t *testing.T) { resource "uxi_wired_network" "my_wired_network" { name = "updated_name" }`, - ExpectError: regexp.MustCompile(`(?s)updating a wired_network is not supported; wired_networks can only be updated\s*through the dashboard`), + ExpectError: regexp.MustCompile( + `(?s)updating a wired_network is not supported; wired_networks can only be updated\s*through the dashboard`, + ), }, // Deleting a wired_network is not allowed { PreConfig: func() { util.MockGetWiredNetwork( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}, + ), 2, ) }, - Config: provider.ProviderConfig + ``, - ExpectError: regexp.MustCompile(`(?s)deleting a wired_network is not supported; wired_networks can only removed\s*from state`), + Config: provider.ProviderConfig + ``, + ExpectError: regexp.MustCompile( + `(?s)deleting a wired_network is not supported; wired_networks can only removed\s*from state`, + ), }, // Remove wired_network from state { @@ -163,7 +185,9 @@ func TestWiredNetworkResourceHttpErrorHandling(t *testing.T) { to = uxi_wired_network.my_wired_network id = "uid" }`, - ExpectError: regexp.MustCompile(`(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`), + ExpectError: regexp.MustCompile( + `(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`, + ), }, }, }) 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 6e725f26..54fdf7f0 100644 --- a/pkg/config-api-provider/test/resources/wireless_network_test.go +++ b/pkg/config-api-provider/test/resources/wireless_network_test.go @@ -29,14 +29,20 @@ func TestWirelessNetworkResource(t *testing.T) { name = "name" }`, - ExpectError: regexp.MustCompile(`(?s)creating a wireless_network is not supported; wireless_networks can only be\s*imported`), + ExpectError: regexp.MustCompile( + `(?s)creating a wireless_network is not supported; wireless_networks can only be\s*imported`, + ), }, // Importing a wireless_network { PreConfig: func() { util.MockGetWirelessNetwork( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateWirelessNetworkResponse("uid", ""), + }, + ), 2, ) }, @@ -51,8 +57,16 @@ func TestWirelessNetworkResource(t *testing.T) { }`, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_wireless_network.my_wireless_network", "name", "name"), - resource.TestCheckResourceAttr("uxi_wireless_network.my_wireless_network", "id", "uid"), + resource.TestCheckResourceAttr( + "uxi_wireless_network.my_wireless_network", + "name", + "name", + ), + resource.TestCheckResourceAttr( + "uxi_wireless_network.my_wireless_network", + "id", + "uid", + ), ), }, // ImportState testing @@ -60,7 +74,11 @@ func TestWirelessNetworkResource(t *testing.T) { PreConfig: func() { util.MockGetWirelessNetwork( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateWirelessNetworkResponse("uid", ""), + }, + ), 1, ) }, @@ -73,7 +91,11 @@ func TestWirelessNetworkResource(t *testing.T) { PreConfig: func() { util.MockGetWirelessNetwork( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateWirelessNetworkResponse("uid", ""), + }, + ), 1, ) }, @@ -81,26 +103,38 @@ func TestWirelessNetworkResource(t *testing.T) { resource "uxi_wireless_network" "my_wireless_network" { name = "updated_name" }`, - ExpectError: regexp.MustCompile(`(?s)updating a wireless_network is not supported; wireless_networks can only be\s*updated through the dashboard`), + ExpectError: regexp.MustCompile( + `(?s)updating a wireless_network is not supported; wireless_networks can only be\s*updated through the dashboard`, + ), }, // Deleting a wireless_network is not allowed { PreConfig: func() { util.MockGetWirelessNetwork( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateWirelessNetworkResponse("uid", ""), + }, + ), 1, ) }, - Config: provider.ProviderConfig + ``, - ExpectError: regexp.MustCompile(`(?s)deleting a wireless_network is not supported; wireless_networks can only\s*removed from state`), + Config: provider.ProviderConfig + ``, + ExpectError: regexp.MustCompile( + `(?s)deleting a wireless_network is not supported; wireless_networks can only\s*removed from state`, + ), }, // Remove wireless_network from state { PreConfig: func() { util.MockGetWirelessNetwork( "uid", - util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}), + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateWirelessNetworkResponse("uid", ""), + }, + ), 1, ) }, @@ -170,7 +204,9 @@ func TestWirelessNetworkResourceHttpErrorHandling(t *testing.T) { to = uxi_wireless_network.my_wireless_network id = "uid" }`, - ExpectError: regexp.MustCompile(`(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`), + ExpectError: regexp.MustCompile( + `(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`, + ), }, }, }) diff --git a/pkg/config-api-provider/test/util/utils.go b/pkg/config-api-provider/test/util/utils.go index 50a68704..a7880024 100644 --- a/pkg/config-api-provider/test/util/utils.go +++ b/pkg/config-api-provider/test/util/utils.go @@ -52,7 +52,11 @@ func GenerateMockedAgentResponseModel(uid string, postfix string) resources.Agen } } -func GenerateGroupResponseModel(uid string, nonReplacementFieldPostfix string, replacementFieldPostfix string) map[string]interface{} { +func GenerateGroupResponseModel( + uid string, + nonReplacementFieldPostfix string, + replacementFieldPostfix string, +) map[string]interface{} { parentId := "parent_uid" + replacementFieldPostfix return map[string]interface{}{ @@ -64,7 +68,11 @@ func GenerateGroupResponseModel(uid string, nonReplacementFieldPostfix string, r } } -func GenerateGroupRequestModel(uid string, nonReplacementFieldPostfix string, replacementFieldPostfix string) map[string]interface{} { +func GenerateGroupRequestModel( + uid string, + nonReplacementFieldPostfix string, + replacementFieldPostfix string, +) map[string]interface{} { return map[string]interface{}{ "name": "name" + nonReplacementFieldPostfix, "parentId": "parent_uid" + replacementFieldPostfix, @@ -79,7 +87,10 @@ func GeneratePaginatedResponse(items []map[string]interface{}) map[string]interf } } -func GenerateServiceTestResponseModel(uid string, postfix string) resources.ServiceTestResponseModel { +func GenerateServiceTestResponseModel( + uid string, + postfix string, +) resources.ServiceTestResponseModel { return resources.ServiceTestResponseModel{ Uid: uid, Category: "external" + postfix, @@ -142,7 +153,10 @@ func GenerateSensorGroupAssignmentRequest(uid string, postfix string) map[string } } -func GenerateAgentGroupAssignmentResponse(uid string, postfix string) resources.AgentGroupAssignmentResponseModel { +func GenerateAgentGroupAssignmentResponse( + uid string, + postfix string, +) resources.AgentGroupAssignmentResponseModel { return resources.AgentGroupAssignmentResponseModel{ UID: uid, GroupUID: "group_uid" + postfix, @@ -166,7 +180,10 @@ func GenerateNetworkGroupAssignmentRequest(uid string, postfix string) map[strin } } -func GenerateServiceTestGroupAssignmentResponse(uid string, postfix string) config_api_client.ServiceTestGroupAssignmentsPostResponse { +func GenerateServiceTestGroupAssignmentResponse( + uid string, + postfix string, +) config_api_client.ServiceTestGroupAssignmentsPostResponse { return config_api_client.ServiceTestGroupAssignmentsPostResponse{ Id: uid, Group: *config_api_client.NewGroup("group_uid" + postfix), @@ -237,7 +254,12 @@ func MockGetGroup(uid string, response map[string]interface{}, times int) { JSON(response) } -func MockUpdateGroup(uid string, request map[string]interface{}, response map[string]interface{}, times int) { +func MockUpdateGroup( + uid string, + request map[string]interface{}, + response map[string]interface{}, + times int, +) { body, _ := json.Marshal(request) gock.New("https://test.api.capenetworks.com"). Patch("/networking-uxi/v1alpha1/groups/"+uid). @@ -297,7 +319,11 @@ func MockGetSensorGroupAssignment(uid string, response map[string]interface{}, t JSON(response) } -func MockPostSensorGroupAssignment(request map[string]interface{}, response map[string]interface{}, times int) { +func MockPostSensorGroupAssignment( + request map[string]interface{}, + response map[string]interface{}, + times int, +) { gock.New("https://test.api.capenetworks.com"). Post("/networking-uxi/v1alpha1/sensor-group-assignments"). MatchHeader("Content-Type", "application/json"). @@ -326,7 +352,11 @@ func MockGetNetworkGroupAssignment(uid string, response map[string]interface{}, JSON(response) } -func MockPostNetworkGroupAssignment(request map[string]interface{}, response map[string]interface{}, times int) { +func MockPostNetworkGroupAssignment( + request map[string]interface{}, + response map[string]interface{}, + times int, +) { gock.New("https://test.api.capenetworks.com"). Post("/networking-uxi/v1alpha1/network-group-assignments"). MatchHeader("Content-Type", "application/json"). @@ -345,7 +375,11 @@ func MockDeleteNetworkGroupAssignment(uid string, times int) { Reply(204) } -func MockPostServiceTestGroupAssignment(request map[string]interface{}, response map[string]interface{}, times int) { +func MockPostServiceTestGroupAssignment( + request map[string]interface{}, + response map[string]interface{}, + times int, +) { gock.New("https://test.api.capenetworks.com"). Post("/networking-uxi/v1alpha1/service-test-group-assignments"). MatchHeader("Content-Type", "application/json").