diff --git a/.golangci.yaml b/.golangci.yaml index a57de576..2b047eac 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -27,8 +27,6 @@ linters: - cyclop # we have gocyclo, apparently its better - execinquery # deprecated - - canonicalheader # for checking copyright headers - - bodyclose # we want this - contextcheck # we want this - copyloopvar # if we update to later than go 1.22 - depguard # for banning specific dependencies @@ -39,18 +37,15 @@ linters: - funlen # we want this - goconst # we want this - gocritic # we want this - - gosec # we want this - intrange # later version of go - - ireturn # we want this + # - ireturn # we want this - lll # we want this - maintidx # we want this - mnd # we want this todo: also see gomnd - gomnd # disabled in gl provider todo: also see mnd - - nlreturn # we want this - noctx # we want this - nestif # we want this - revive # we want this - - stylecheck # we want this - tagliatelle # we want this - testifylint # we want this - thelper # we want this @@ -93,6 +88,10 @@ issues: - dupl path: _test\.go + - linters: + - stylecheck + path: pkg/config-api-client + - linters: - dupl path: ".*generated.*go" @@ -109,4 +108,12 @@ issues: - stylecheck text: "ST1005:" + - linters: + - ireturn + path: internal/provider/resources + + - linters: + - ireturn + path: internal/provider/util/retry.go + max-same-issues: 0 diff --git a/internal/provider/config/config.go b/internal/provider/config/config.go index 48214eaf..d6498b53 100644 --- a/internal/provider/config/config.go +++ b/internal/provider/config/config.go @@ -8,7 +8,7 @@ import "os" const ( MaxRetriesForTooManyRequests = 10 - TokenURL = "https://sso.common.cloud.hpe.com/as/token.oauth2" + TokenURL = "https://sso.common.cloud.hpe.com/as/token.oauth2" // #nosec G101 UXIDefaultHost = "api.capenetworks.com" ) @@ -23,6 +23,7 @@ func getEnv(key, fallback string) string { if value == "" { return fallback } + return value } diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 6f2c68a9..0f1cdcbc 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -135,7 +135,7 @@ func (p *uxiConfigurationProvider) Configure( uxiConfiguration := config_api_client.NewConfiguration() uxiConfiguration.Host = configuration.Host uxiConfiguration.Scheme = "https" - uxiConfiguration.HTTPClient = getHttpClient(clientID, clientSecret, configuration.TokenURL) + uxiConfiguration.HTTPClient = getHTTPClient(clientID, clientSecret, configuration.TokenURL) uxiClient := config_api_client.NewAPIClient(uxiConfiguration) resp.DataSourceData = uxiClient @@ -172,7 +172,7 @@ func (p *uxiConfigurationProvider) Resources(_ context.Context) []func() resourc } } -func getHttpClient(clientID string, clientSecret string, tokenURL string) *http.Client { +func getHTTPClient(clientID string, clientSecret string, tokenURL string) *http.Client { config := &clientcredentials.Config{ ClientID: clientID, ClientSecret: clientSecret, diff --git a/internal/provider/resources/data_source_agent.go b/internal/provider/resources/data_source_agent.go index 61241f45..d0acb2d6 100644 --- a/internal/provider/resources/data_source_agent.go +++ b/internal/provider/resources/data_source_agent.go @@ -123,17 +123,20 @@ func (d *agentDataSource) Read( agentResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - errorSummary := util.GenerateErrorSummary("read", "uxi_agent") if errorPresent { resp.Diagnostics.AddError(errorSummary, errorDetail) + return } + defer response.Body.Close() + if len(agentResponse.Items) != 1 { resp.Diagnostics.AddError(errorSummary, "Could not find specified data source") resp.State.RemoveResource(ctx) + return } @@ -171,6 +174,7 @@ func (d *agentDataSource) Configure( "Unexpected Data Source Configure Type", "Data Source type: Agent. Please report this issue to the provider developers.", ) + return } diff --git a/internal/provider/resources/data_source_agent_group_assignment.go b/internal/provider/resources/data_source_agent_group_assignment.go index e69cc892..1a70cf9e 100644 --- a/internal/provider/resources/data_source_agent_group_assignment.go +++ b/internal/provider/resources/data_source_agent_group_assignment.go @@ -97,17 +97,20 @@ func (d *agentGroupAssignmentDataSource) Read( Id(state.Filter.ID) agentGroupAssignmentResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - errorSummary := util.GenerateErrorSummary("read", "uxi_agent_group_assignment") if errorPresent { resp.Diagnostics.AddError(errorSummary, errorDetail) + return } + defer response.Body.Close() + if len(agentGroupAssignmentResponse.Items) != 1 { resp.Diagnostics.AddError(errorSummary, "Could not find specified data source") resp.State.RemoveResource(ctx) + return } @@ -139,6 +142,7 @@ func (d *agentGroupAssignmentDataSource) Configure( "Unexpected Data Source Configure Type", "Data Source type: Agent Group Assignment. Please report this issue to the provider developers.", ) + return } diff --git a/internal/provider/resources/data_source_group.go b/internal/provider/resources/data_source_group.go index de5812d4..856cd888 100644 --- a/internal/provider/resources/data_source_group.go +++ b/internal/provider/resources/data_source_group.go @@ -103,23 +103,27 @@ func (d *groupDataSource) Read( groupResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - errorSummary := util.GenerateErrorSummary("read", "uxi_group") if errorPresent { resp.Diagnostics.AddError(errorSummary, errorDetail) + return } + defer response.Body.Close() + if len(groupResponse.Items) != 1 { resp.Diagnostics.AddError(errorSummary, "Could not find specified data source") resp.State.RemoveResource(ctx) + return } group := groupResponse.Items[0] if util.IsRoot(group) { resp.Diagnostics.AddError(errorSummary, "The root group cannot be used as a data source") + return } @@ -151,6 +155,7 @@ func (d *groupDataSource) Configure( "Unexpected Data Source Configure Type", "Data Source type: Group. Please report this issue to the provider developers.", ) + return } diff --git a/internal/provider/resources/data_source_network_group_assignment.go b/internal/provider/resources/data_source_network_group_assignment.go index 1d14924b..485c3062 100644 --- a/internal/provider/resources/data_source_network_group_assignment.go +++ b/internal/provider/resources/data_source_network_group_assignment.go @@ -97,17 +97,20 @@ func (d *networkGroupAssignmentDataSource) Read( Id(state.Filter.ID) networkGroupAssignmentResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - errorSummary := util.GenerateErrorSummary("read", "uxi_network_group_assignment") if errorPresent { resp.Diagnostics.AddError(errorSummary, errorDetail) + return } + defer response.Body.Close() + if len(networkGroupAssignmentResponse.Items) != 1 { resp.Diagnostics.AddError(errorSummary, "Could not find specified data source") resp.State.RemoveResource(ctx) + return } @@ -139,6 +142,7 @@ func (d *networkGroupAssignmentDataSource) Configure( "Unexpected Data Source Configure Type", "Data Source type: Network Group Assignment. Please report this issue to the provider developers.", ) + return } diff --git a/internal/provider/resources/data_source_sensor.go b/internal/provider/resources/data_source_sensor.go index 1fd556fb..fb2ce12b 100644 --- a/internal/provider/resources/data_source_sensor.go +++ b/internal/provider/resources/data_source_sensor.go @@ -138,17 +138,20 @@ func (d *sensorDataSource) Read( sensorResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - errorSummary := util.GenerateErrorSummary("read", "uxi_sensor") if errorPresent { resp.Diagnostics.AddError(errorSummary, errorDetail) + return } + defer response.Body.Close() + if len(sensorResponse.Items) != 1 { resp.Diagnostics.AddError(errorSummary, "Could not find specified data source") resp.State.RemoveResource(ctx) + return } @@ -189,6 +192,7 @@ func (d *sensorDataSource) Configure( "Unexpected Data Source Configure Type", "Data Source type: Sensor. Please report this issue to the provider developers.", ) + return } diff --git a/internal/provider/resources/data_source_sensor_group_assignment.go b/internal/provider/resources/data_source_sensor_group_assignment.go index c00927d4..72fc153c 100644 --- a/internal/provider/resources/data_source_sensor_group_assignment.go +++ b/internal/provider/resources/data_source_sensor_group_assignment.go @@ -97,17 +97,20 @@ func (d *sensorGroupAssignmentDataSource) Read( Id(state.Filter.ID) sensorGroupAssignmentResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - errorSummary := util.GenerateErrorSummary("read", "uxi_sensor_group_assignment") if errorPresent { resp.Diagnostics.AddError(errorSummary, errorDetail) + return } + defer response.Body.Close() + if len(sensorGroupAssignmentResponse.Items) != 1 { resp.Diagnostics.AddError(errorSummary, "Could not find specified data source") resp.State.RemoveResource(ctx) + return } @@ -139,6 +142,7 @@ func (d *sensorGroupAssignmentDataSource) Configure( "Unexpected Data Source Configure Type", "Data Source type: Sensor Group Assignment. Please report this issue to the provider developers.", ) + return } diff --git a/internal/provider/resources/data_source_service.go b/internal/provider/resources/data_source_service.go index eacc35c0..d2749cc8 100644 --- a/internal/provider/resources/data_source_service.go +++ b/internal/provider/resources/data_source_service.go @@ -116,17 +116,20 @@ func (d *serviceTestDataSource) Read( serviceTestResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - errorSummary := util.GenerateErrorSummary("read", "uxi_service_test") if errorPresent { resp.Diagnostics.AddError(errorSummary, errorDetail) + return } + defer response.Body.Close() + if len(serviceTestResponse.Items) != 1 { resp.Diagnostics.AddError(errorSummary, "Could not find specified data source") resp.State.RemoveResource(ctx) + return } @@ -162,6 +165,7 @@ func (d *serviceTestDataSource) Configure( "Unexpected Data Source Configure Type", "Data Source type: ServiceTest. Please report this issue to the provider developers.", ) + return } diff --git a/internal/provider/resources/data_source_service_test_group_assignment.go b/internal/provider/resources/data_source_service_test_group_assignment.go index e2617fbf..71f32e9a 100644 --- a/internal/provider/resources/data_source_service_test_group_assignment.go +++ b/internal/provider/resources/data_source_service_test_group_assignment.go @@ -99,17 +99,20 @@ func (d *serviceTestGroupAssignmentDataSource) Read( request.Execute, ) errorPresent, errorDetail := util.RaiseForStatus(response, err) - errorSummary := util.GenerateErrorSummary("read", "uxi_service_test_group_assignment") if errorPresent { resp.Diagnostics.AddError(errorSummary, errorDetail) + return } + defer response.Body.Close() + if len(serviceTestGroupAssignmentResponse.Items) != 1 { resp.Diagnostics.AddError(errorSummary, "Could not find specified data source") resp.State.RemoveResource(ctx) + return } @@ -141,6 +144,7 @@ func (d *serviceTestGroupAssignmentDataSource) Configure( "Unexpected Data Source Configure Type", "Data Source type: ServiceTest Group Assignment. Please report this issue to the provider developers.", ) + return } diff --git a/internal/provider/resources/data_source_wired_network.go b/internal/provider/resources/data_source_wired_network.go index f210683d..2998aa03 100644 --- a/internal/provider/resources/data_source_wired_network.go +++ b/internal/provider/resources/data_source_wired_network.go @@ -127,17 +127,20 @@ func (d *wiredNetworkDataSource) Read( Id(state.Filter.ID) networkResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - errorSummary := util.GenerateErrorSummary("read", "uxi_wired_network") if errorPresent { resp.Diagnostics.AddError(errorSummary, errorDetail) + return } + defer response.Body.Close() + if len(networkResponse.Items) != 1 { resp.Diagnostics.AddError(errorSummary, "Could not find specified data source") resp.State.RemoveResource(ctx) + return } @@ -175,6 +178,7 @@ func (d *wiredNetworkDataSource) Configure( "Unexpected Data Source Configure Type", "Data Source type: Wired Network. Please report this issue to the provider developers.", ) + return } diff --git a/internal/provider/resources/data_source_wireless_network.go b/internal/provider/resources/data_source_wireless_network.go index d1f91092..8a6d31e3 100644 --- a/internal/provider/resources/data_source_wireless_network.go +++ b/internal/provider/resources/data_source_wireless_network.go @@ -137,17 +137,20 @@ func (d *wirelessNetworkDataSource) Read( Id(state.Filter.ID) networkResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - errorSummary := util.GenerateErrorSummary("read", "uxi_wireless_network") if errorPresent { resp.Diagnostics.AddError(errorSummary, errorDetail) + return } + defer response.Body.Close() + if len(networkResponse.Items) != 1 { resp.Diagnostics.AddError(errorSummary, "Could not find specified data source") resp.State.RemoveResource(ctx) + return } @@ -187,6 +190,7 @@ func (d *wirelessNetworkDataSource) Configure( "Unexpected Data Source Configure Type", "Data Source type: Wireless Network. Please report this issue to the provider developers.", ) + return } diff --git a/internal/provider/resources/resource_agent.go b/internal/provider/resources/resource_agent.go index 1bac4a9f..fd5a1837 100644 --- a/internal/provider/resources/resource_agent.go +++ b/internal/provider/resources/resource_agent.go @@ -116,6 +116,7 @@ func (r *agentResource) Configure( "Unexpected Data Source Configure Type", "Resource type: Group. Please report this issue to the provider developers.", ) + return } @@ -153,16 +154,19 @@ func (r *agentResource) Read( Id(state.ID.ValueString()) agentResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - errorSummary := util.GenerateErrorSummary("read", "uxi_agent") if errorPresent { resp.Diagnostics.AddError(errorSummary, errorDetail) + return } + defer response.Body.Close() + if len(agentResponse.Items) != 1 { resp.State.RemoveResource(ctx) + return } agent := agentResponse.Items[0] @@ -206,6 +210,7 @@ func (r *agentResource) Update( pcapMode, err := config_api_client.NewPcapModeFromValue(*plannedPcapMode) if err != nil { resp.Diagnostics.AddError(errorSummary, err.Error()) + return } patchRequest.PcapMode = pcapMode @@ -214,14 +219,16 @@ func (r *agentResource) Update( AgentsPatch(ctx, plan.ID.ValueString()). AgentsPatchRequest(*patchRequest) agent, response, err := util.RetryForTooManyRequests(request.Execute) - errorPresent, errorDetail := util.RaiseForStatus(response, err) if errorPresent { resp.Diagnostics.AddError(errorSummary, errorDetail) + return } + defer response.Body.Close() + plan.ID = types.StringValue(agent.Id) plan.Name = types.StringValue(agent.Name) plan.Serial = types.StringValue(agent.Serial) @@ -256,15 +263,18 @@ func (r *agentResource) Delete( _, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - if errorPresent { if response != nil && response.StatusCode == http.StatusNotFound { resp.State.RemoveResource(ctx) + return } resp.Diagnostics.AddError(util.GenerateErrorSummary("delete", "uxi_agent"), errorDetail) + return } + + defer response.Body.Close() } func (r *agentResource) ImportState( diff --git a/internal/provider/resources/resource_agent_group_assignment.go b/internal/provider/resources/resource_agent_group_assignment.go index a4641202..ca046677 100644 --- a/internal/provider/resources/resource_agent_group_assignment.go +++ b/internal/provider/resources/resource_agent_group_assignment.go @@ -101,6 +101,7 @@ func (r *agentGroupAssignmentResource) Configure( "Unexpected Data Source Configure Type", "Resource type: Network Group Assignment. Please report this issue to the provider developers.", ) + return } @@ -128,15 +129,17 @@ func (r *agentGroupAssignmentResource) Create( AgentGroupAssignmentsPostRequest(*postRequest) agentGroupAssignment, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - if errorPresent { resp.Diagnostics.AddError( util.GenerateErrorSummary("create", "uxi_agent_group_assignment"), errorDetail, ) + return } + defer response.Body.Close() + plan.ID = types.StringValue(agentGroupAssignment.Id) plan.GroupID = types.StringValue(agentGroupAssignment.Group.Id) plan.AgentID = types.StringValue(agentGroupAssignment.Agent.Id) @@ -165,16 +168,19 @@ func (r *agentGroupAssignmentResource) Read( Id(state.ID.ValueString()) agentGroupAssignmentResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - errorSummary := util.GenerateErrorSummary("read", "uxi_agent_group_assignment") if errorPresent { resp.Diagnostics.AddError(errorSummary, errorDetail) + return } + defer response.Body.Close() + if len(agentGroupAssignmentResponse.Items) != 1 { resp.State.RemoveResource(ctx) + return } agentGroupAssignment := agentGroupAssignmentResponse.Items[0] @@ -220,18 +226,21 @@ func (r *agentGroupAssignmentResource) Delete( AgentGroupAssignmentDelete(ctx, state.ID.ValueString()) _, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - if errorPresent { if response != nil && response.StatusCode == http.StatusNotFound { resp.State.RemoveResource(ctx) + return } resp.Diagnostics.AddError( util.GenerateErrorSummary("delete", "uxi_agent_group_assignment"), errorDetail, ) + return } + + defer response.Body.Close() } func (r *agentGroupAssignmentResource) ImportState( diff --git a/internal/provider/resources/resource_group.go b/internal/provider/resources/resource_group.go index 4c017750..b35d0178 100644 --- a/internal/provider/resources/resource_group.go +++ b/internal/provider/resources/resource_group.go @@ -6,6 +6,7 @@ package resources import ( "context" + "errors" "net/http" "github.com/hashicorp/terraform-plugin-framework/path" @@ -97,6 +98,7 @@ func (r *groupResource) Configure( "Unexpected Data Source Configure Type", "Resource type: Group. Please report this issue to the provider developers.", ) + return } @@ -115,21 +117,23 @@ func (r *groupResource) Create( return } - groups_post_request := config_api_client.NewGroupsPostRequest(plan.Name.ValueString()) + groupsPostRequest := config_api_client.NewGroupsPostRequest(plan.Name.ValueString()) if !plan.ParentGroupID.IsUnknown() && !plan.ParentGroupID.IsNull() { - groups_post_request.SetParentId(plan.ParentGroupID.ValueString()) + groupsPostRequest.SetParentId(plan.ParentGroupID.ValueString()) } request := r.client.ConfigurationAPI. GroupsPost(ctx). - GroupsPostRequest(*groups_post_request) + GroupsPostRequest(*groupsPostRequest) group, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - if errorPresent { resp.Diagnostics.AddError(util.GenerateErrorSummary("create", "uxi_group"), errorDetail) + return } + defer response.Body.Close() + plan.ID = types.StringValue(group.Id) plan.Name = types.StringValue(group.Name) // only update parent if not attached to root node (else leave it as null) @@ -162,16 +166,19 @@ func (r *groupResource) Read( errorSummary := util.GenerateErrorSummary("read", "uxi_group") if errorDetail != nil { - if *errorDetail == groupNotFoundError { + if errorDetail.Error() == groupNotFoundError { resp.State.RemoveResource(ctx) + return } - resp.Diagnostics.AddError(errorSummary, *errorDetail) + resp.Diagnostics.AddError(errorSummary, errorDetail.Error()) + return } if util.IsRoot(*group) { resp.Diagnostics.AddError(errorSummary, "The root group cannot be used as a resource") + return } @@ -209,14 +216,15 @@ func (r *groupResource) Update( GroupsPatch(ctx, plan.ID.ValueString()). GroupsPatchRequest(*patchRequest) group, response, err := util.RetryForTooManyRequests(request.Execute) - errorPresent, errorDetail := util.RaiseForStatus(response, err) - if errorPresent { resp.Diagnostics.AddError(util.GenerateErrorSummary("update", "uxi_group"), errorDetail) + return } + defer response.Body.Close() + plan.ID = types.StringValue(group.Id) plan.Name = types.StringValue(group.Name) // only update parent if not attached to root node (else leave it as null) @@ -248,15 +256,18 @@ func (r *groupResource) Delete( _, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - if errorPresent { if response != nil && response.StatusCode == http.StatusNotFound { resp.State.RemoveResource(ctx) + return } resp.Diagnostics.AddError(util.GenerateErrorSummary("delete", "uxi_group"), errorDetail) + return } + + defer response.Body.Close() } func (r *groupResource) ImportState( @@ -270,19 +281,23 @@ func (r *groupResource) ImportState( func (r *groupResource) getGroup( ctx context.Context, id string, -) (*config_api_client.GroupsGetItem, *string) { +) (*config_api_client.GroupsGetItem, error) { request := r.client.ConfigurationAPI.GroupsGet(ctx).Id(id) + groupResponse, response, err := util.RetryForTooManyRequests(request.Execute) + // groupResponse, response, err := request.Execute() + // this causes a segfault errorPresent, errorDetail := util.RaiseForStatus(response, err) - if errorPresent { - return nil, &errorDetail + return nil, errors.New(errorDetail) } - if len(groupResponse.Items) != 1 { notFound := groupNotFoundError - return nil, ¬Found + + return nil, errors.New(notFound) } + defer response.Body.Close() + return &groupResponse.Items[0], nil } diff --git a/internal/provider/resources/resource_network_group_assignment.go b/internal/provider/resources/resource_network_group_assignment.go index 275cd0a4..40d1ea93 100644 --- a/internal/provider/resources/resource_network_group_assignment.go +++ b/internal/provider/resources/resource_network_group_assignment.go @@ -104,6 +104,7 @@ func (r *networkGroupAssignmentResource) Configure( "Unexpected Data Source Configure Type", "Resource type: Network Group Assignment. Please report this issue to the provider developers.", ) + return } @@ -131,15 +132,17 @@ func (r *networkGroupAssignmentResource) Create( NetworkGroupAssignmentsPostRequest(*postRequest) networkGroupAssignment, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - if errorPresent { resp.Diagnostics.AddError( util.GenerateErrorSummary("create", "uxi_network_group_assignment"), errorDetail, ) + return } + defer response.Body.Close() + plan.ID = types.StringValue(networkGroupAssignment.Id) plan.GroupID = types.StringValue(networkGroupAssignment.Group.Id) plan.NetworkID = types.StringValue(networkGroupAssignment.Network.Id) @@ -168,16 +171,19 @@ func (r *networkGroupAssignmentResource) Read( Id(state.ID.ValueString()) networkGroupAssignmentResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - errorSummary := util.GenerateErrorSummary("read", "uxi_network_group_assignment") if errorPresent { resp.Diagnostics.AddError(errorSummary, errorDetail) + return } + defer response.Body.Close() + if len(networkGroupAssignmentResponse.Items) != 1 { resp.State.RemoveResource(ctx) + return } networkGroupAssignment := networkGroupAssignmentResponse.Items[0] @@ -226,18 +232,21 @@ func (r *networkGroupAssignmentResource) Delete( NetworkGroupAssignmentsDelete(ctx, state.ID.ValueString()) _, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - if errorPresent { if response != nil && response.StatusCode == http.StatusNotFound { resp.State.RemoveResource(ctx) + return } resp.Diagnostics.AddError( util.GenerateErrorSummary("delete", "uxi_network_group_assignment"), errorDetail, ) + return } + + defer response.Body.Close() } func (r *networkGroupAssignmentResource) ImportState( diff --git a/internal/provider/resources/resource_sensor.go b/internal/provider/resources/resource_sensor.go index f09db864..2386d8e7 100644 --- a/internal/provider/resources/resource_sensor.go +++ b/internal/provider/resources/resource_sensor.go @@ -134,6 +134,7 @@ func (r *sensorResource) Configure( "Unexpected Data Source Configure Type", "Resource type: Group. Please report this issue to the provider developers.", ) + return } @@ -171,16 +172,19 @@ func (r *sensorResource) Read( Id(state.ID.ValueString()) sensorResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - errorSummary := util.GenerateErrorSummary("read", "uxi_sensor") if errorPresent { resp.Diagnostics.AddError(errorSummary, errorDetail) + return } + defer response.Body.Close() + if len(sensorResponse.Items) != 1 { resp.State.RemoveResource(ctx) + return } sensor := sensorResponse.Items[0] @@ -226,6 +230,7 @@ func (r *sensorResource) Update( pcapMode, err := config_api_client.NewPcapModeFromValue(*plannedPcapMode) if err != nil { resp.Diagnostics.AddError(errorSummary, err.Error()) + return } patchRequest.PcapMode = pcapMode @@ -235,14 +240,16 @@ func (r *sensorResource) Update( SensorsPatch(ctx, plan.ID.ValueString()). SensorsPatchRequest(*patchRequest) sensor, response, err := util.RetryForTooManyRequests(request.Execute) - errorPresent, errorDetail := util.RaiseForStatus(response, err) if errorPresent { resp.Diagnostics.AddError(errorSummary, errorDetail) + return } + defer response.Body.Close() + plan.ID = types.StringValue(sensor.Id) plan.Name = types.StringValue(sensor.Name) plan.Serial = types.StringValue(sensor.Serial) diff --git a/internal/provider/resources/resource_sensor_group_assignment.go b/internal/provider/resources/resource_sensor_group_assignment.go index 38039d39..a218ef7e 100644 --- a/internal/provider/resources/resource_sensor_group_assignment.go +++ b/internal/provider/resources/resource_sensor_group_assignment.go @@ -101,6 +101,7 @@ func (r *sensorGroupAssignmentResource) Configure( "Unexpected Data Source Configure Type", "Resource type: Sensor Group Assignment. Please report this issue to the provider developers.", ) + return } @@ -128,15 +129,17 @@ func (r *sensorGroupAssignmentResource) Create( SensorGroupAssignmentsPostRequest(*postRequest) sensorGroupAssignment, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - if errorPresent { resp.Diagnostics.AddError( util.GenerateErrorSummary("create", "uxi_sensor_group_assignment"), errorDetail, ) + return } + defer response.Body.Close() + plan.ID = types.StringValue(sensorGroupAssignment.Id) plan.GroupID = types.StringValue(sensorGroupAssignment.Group.Id) plan.SensorID = types.StringValue(sensorGroupAssignment.Sensor.Id) @@ -165,16 +168,19 @@ func (r *sensorGroupAssignmentResource) Read( Id(state.ID.ValueString()) sensorGroupAssignmentResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - errorSummary := util.GenerateErrorSummary("read", "uxi_sensor_group_assignment") if errorPresent { resp.Diagnostics.AddError(errorSummary, errorDetail) + return } + defer response.Body.Close() + if len(sensorGroupAssignmentResponse.Items) != 1 { resp.State.RemoveResource(ctx) + return } @@ -221,18 +227,21 @@ func (r *sensorGroupAssignmentResource) Delete( SensorGroupAssignmentsDelete(ctx, state.ID.ValueString()) _, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - if errorPresent { if response != nil && response.StatusCode == http.StatusNotFound { resp.State.RemoveResource(ctx) + return } resp.Diagnostics.AddError( util.GenerateErrorSummary("delete", "uxi_sensor_group_assignment"), errorDetail, ) + return } + + defer response.Body.Close() } func (r *sensorGroupAssignmentResource) ImportState( diff --git a/internal/provider/resources/resource_service.go b/internal/provider/resources/resource_service.go index 4ec99a45..26716fa9 100644 --- a/internal/provider/resources/resource_service.go +++ b/internal/provider/resources/resource_service.go @@ -106,6 +106,7 @@ func (r *serviceTestResource) Configure( "Unexpected Data Source Configure Type", "Resource type: Group. Please report this issue to the provider developers.", ) + return } @@ -143,16 +144,19 @@ func (r *serviceTestResource) Read( Id(state.ID.ValueString()) sensorResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - errorSummary := util.GenerateErrorSummary("read", "uxi_service_test") if errorPresent { resp.Diagnostics.AddError(errorSummary, errorDetail) + return } + defer response.Body.Close() + if len(sensorResponse.Items) != 1 { resp.State.RemoveResource(ctx) + return } serviceTest := sensorResponse.Items[0] diff --git a/internal/provider/resources/resource_service_group_assignment.go b/internal/provider/resources/resource_service_group_assignment.go index b477e63b..f008281a 100644 --- a/internal/provider/resources/resource_service_group_assignment.go +++ b/internal/provider/resources/resource_service_group_assignment.go @@ -101,6 +101,7 @@ func (r *serviceTestGroupAssignmentResource) Configure( "Unexpected Data Source Configure Type", "Resource type: Service Test Group Assignment. Please report this issue to the provider developers.", ) + return } @@ -128,15 +129,17 @@ func (r *serviceTestGroupAssignmentResource) Create( ServiceTestGroupAssignmentsPostRequest(*postRequest) serviceTestGroupAssignment, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - if errorPresent { resp.Diagnostics.AddError( util.GenerateErrorSummary("create", "uxi_service_test_group_assignment"), errorDetail, ) + return } + defer response.Body.Close() + plan.ID = types.StringValue(serviceTestGroupAssignment.Id) plan.GroupID = types.StringValue(serviceTestGroupAssignment.Group.Id) plan.ServiceTestID = types.StringValue(serviceTestGroupAssignment.ServiceTest.Id) @@ -167,16 +170,19 @@ func (r *serviceTestGroupAssignmentResource) Read( request.Execute, ) errorPresent, errorDetail := util.RaiseForStatus(response, err) - errorSummary := util.GenerateErrorSummary("read", "uxi_service_test_group_assignment") if errorPresent { resp.Diagnostics.AddError(errorSummary, errorDetail) + return } + defer response.Body.Close() + if len(serviceTestGroupAssignmentResponse.Items) != 1 { resp.State.RemoveResource(ctx) + return } serviceTestGroupAssignment := serviceTestGroupAssignmentResponse.Items[0] @@ -226,18 +232,21 @@ func (r *serviceTestGroupAssignmentResource) Delete( _, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - if errorPresent { if response != nil && response.StatusCode == http.StatusNotFound { resp.State.RemoveResource(ctx) + return } resp.Diagnostics.AddError( util.GenerateErrorSummary("delete", "uxi_service_test_group_assignment"), errorDetail, ) + return } + + defer response.Body.Close() } func (r *serviceTestGroupAssignmentResource) ImportState( diff --git a/internal/provider/resources/resource_wired_network.go b/internal/provider/resources/resource_wired_network.go index bf36485a..a174f319 100644 --- a/internal/provider/resources/resource_wired_network.go +++ b/internal/provider/resources/resource_wired_network.go @@ -118,6 +118,7 @@ func (r *wiredNetworkResource) Configure( "Unexpected Data Source Configure Type", "Resource type: Wired Network. Please report this issue to the provider developers.", ) + return } @@ -155,16 +156,19 @@ func (r *wiredNetworkResource) Read( Id(state.ID.ValueString()) networkResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - errorSummary := util.GenerateErrorSummary("read", "uxi_wired_network") if errorPresent { resp.Diagnostics.AddError(errorSummary, errorDetail) + return } + defer response.Body.Close() + if len(networkResponse.Items) != 1 { resp.State.RemoveResource(ctx) + return } diff --git a/internal/provider/resources/resource_wireless_network.go b/internal/provider/resources/resource_wireless_network.go index 76fff7c3..5f622e47 100644 --- a/internal/provider/resources/resource_wireless_network.go +++ b/internal/provider/resources/resource_wireless_network.go @@ -129,6 +129,7 @@ func (r *wirelessNetworkResource) Configure( "Unexpected Data Source Configure Type", "Resource type: Wireless Network. Please report this issue to the provider developers.", ) + return } @@ -166,16 +167,19 @@ func (r *wirelessNetworkResource) Read( Id(state.ID.ValueString()) networkResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) - errorSummary := util.GenerateErrorSummary("read", "uxi_wireless_network") if errorPresent { resp.Diagnostics.AddError(errorSummary, errorDetail) + return } + defer response.Body.Close() + if len(networkResponse.Items) != 1 { resp.State.RemoveResource(ctx) + return } diff --git a/internal/provider/util/error_handling.go b/internal/provider/util/error_handling.go index 5adc6a94..b53efcf2 100644 --- a/internal/provider/util/error_handling.go +++ b/internal/provider/util/error_handling.go @@ -34,8 +34,8 @@ func RaiseForStatus(response *http.Response, err error) (bool, string) { ) } else if message, ok := data["message"]; ok { detail = message.(string) - if debugId, ok := data["debugId"]; ok { - detail += "\nDebugID: " + debugId.(string) + if debugID, ok := data["debugId"]; ok { + detail += "\nDebugID: " + debugID.(string) } } else { detail = "Unexpected error: " + e.Error() @@ -46,6 +46,7 @@ func RaiseForStatus(response *http.Response, err error) (bool, string) { return true, detail } + return false, "" } diff --git a/internal/provider/util/group.go b/internal/provider/util/group.go index 7b16807f..81290946 100644 --- a/internal/provider/util/group.go +++ b/internal/provider/util/group.go @@ -10,5 +10,6 @@ import ( func IsRoot(group config_api_client.GroupsGetItem) bool { _, set := group.Parent.Get().GetIdOk() + return !set } diff --git a/pkg/config-api-client/test/api_configuration_test.go b/pkg/config-api-client/test/api_configuration_test.go index 2f15d8fd..a4729151 100644 --- a/pkg/config-api-client/test/api_configuration_test.go +++ b/pkg/config-api-client/test/api_configuration_test.go @@ -53,14 +53,15 @@ func TestConfigurationAPI(t *testing.T) { Limit(10). Next("some-cursor"). Execute() - modelNumber := "model_number" + wifiMacAddress := "wifi_mac_address" ethernetMacAddress := "ethernet_mac_address" notes := "notes" pcapMode := "pcap_mode" - require.Nil(t, err) + + defer httpRes.Body.Close() assert.Equal(t, http.StatusOK, httpRes.StatusCode) assert.Equal(t, resp, &config_api_client.AgentsResponse{ Items: []config_api_client.AgentItem{ @@ -111,12 +112,13 @@ func TestConfigurationAPI(t *testing.T) { AgentsPatch(context.Background(), "uid"). AgentsPatchRequest(agentsPatchRequest). Execute() - wifiMacAddress := "wifi_mac_address" + ethernetMacAddress := "ethernet_mac_address" modelNumber := "model_number" - require.Nil(t, err) + + defer httpRes.Body.Close() assert.Equal(t, http.StatusOK, httpRes.StatusCode) assert.Equal(t, resp, &config_api_client.AgentsPatchResponse{ Id: "uid", @@ -139,8 +141,9 @@ func TestConfigurationAPI(t *testing.T) { _, httpRes, err := apiClient.ConfigurationAPI. AgentsDelete(context.Background(), "uid"). Execute() - require.Nil(t, err) + + defer httpRes.Body.Close() assert.Equal(t, http.StatusNoContent, httpRes.StatusCode) }) @@ -169,8 +172,9 @@ func TestConfigurationAPI(t *testing.T) { Limit(10). Next("some-cursor"). Execute() - require.Nil(t, err) + + defer httpRes.Body.Close() assert.Equal(t, http.StatusOK, httpRes.StatusCode) assert.Equal(t, resp, &config_api_client.GroupsGetResponse{ Items: []config_api_client.GroupsGetItem{ @@ -207,8 +211,9 @@ func TestConfigurationAPI(t *testing.T) { resp, httpRes, err := apiClient.ConfigurationAPI. GroupsPost(context.Background()). GroupsPostRequest(*groupsPostRequest).Execute() - require.Nil(t, err) + + defer httpRes.Body.Close() assert.Equal(t, http.StatusOK, httpRes.StatusCode) assert.Equal(t, resp, &config_api_client.GroupsPostResponse{ Id: "node", @@ -237,8 +242,9 @@ func TestConfigurationAPI(t *testing.T) { resp, httpRes, err := apiClient.ConfigurationAPI. GroupsPatch(context.Background(), "node"). GroupsPatchRequest(*groupsPatchRequest).Execute() - require.Nil(t, err) + + defer httpRes.Body.Close() assert.Equal(t, http.StatusOK, httpRes.StatusCode) assert.Equal(t, resp, &config_api_client.GroupsPatchResponse{ Id: "node", @@ -257,8 +263,9 @@ func TestConfigurationAPI(t *testing.T) { _, httpRes, err := apiClient.ConfigurationAPI. GroupsDelete(context.Background(), "uid"). Execute() - require.Nil(t, err) + + defer httpRes.Body.Close() assert.Equal(t, http.StatusNoContent, httpRes.StatusCode) }) @@ -294,16 +301,17 @@ func TestConfigurationAPI(t *testing.T) { Limit(10). Next("some-cursor"). Execute() - WifiMacAddress := "wifi_mac_address" + EthernetMacAddress := "ethernet_mac_address" AddressNote := "address_note" var Longitude float32 = 0.0 var Latitude float32 = 0.0 Notes := "notes" pcapMode := "light" - require.Nil(t, err) + + defer httpRes.Body.Close() assert.Equal(t, http.StatusOK, httpRes.StatusCode) assert.Equal(t, resp, &config_api_client.SensorsResponse{ Items: []config_api_client.SensorItem{ @@ -362,13 +370,14 @@ func TestConfigurationAPI(t *testing.T) { SensorsPatch(context.Background(), "uid"). SensorsPatchRequest(sensorsPatchRequest). Execute() - wifiMacAddress := "wifi_mac_address" + ethernetMacAddress := "ethernet_mac_address" var longitude float32 = 0.0 var latitude float32 = 0.0 - require.Nil(t, err) + + defer httpRes.Body.Close() assert.Equal(t, http.StatusOK, httpRes.StatusCode) assert.Equal(t, resp, &config_api_client.SensorsPatchResponse{ Id: "uid", @@ -409,8 +418,9 @@ func TestConfigurationAPI(t *testing.T) { Limit(10). Next("some-cursor"). Execute() - require.Nil(t, err) + + defer httpRes.Body.Close() assert.Equal(t, http.StatusOK, httpRes.StatusCode) assert.Equal(t, resp, &config_api_client.AgentGroupAssignmentsResponse{ Items: []config_api_client.AgentGroupAssignmentsItem{ @@ -449,8 +459,9 @@ func TestConfigurationAPI(t *testing.T) { AgentGroupAssignmentsPost(context.Background()). AgentGroupAssignmentsPostRequest(*postRequest). Execute() - require.Nil(t, err) + + defer httpRes.Body.Close() assert.Equal(t, http.StatusOK, httpRes.StatusCode) assert.Equal(t, resp, &config_api_client.AgentGroupAssignmentResponse{ Id: "uid", @@ -468,8 +479,9 @@ func TestConfigurationAPI(t *testing.T) { _, httpRes, err := apiClient.ConfigurationAPI. AgentGroupAssignmentDelete(context.Background(), "uid"). Execute() - require.Nil(t, err) + + defer httpRes.Body.Close() assert.Equal(t, http.StatusNoContent, httpRes.StatusCode) }) @@ -496,8 +508,9 @@ func TestConfigurationAPI(t *testing.T) { Limit(10). Next("some-cursor"). Execute() - require.Nil(t, err) + + defer httpRes.Body.Close() assert.Equal(t, http.StatusOK, httpRes.StatusCode) assert.Equal(t, resp, &config_api_client.SensorGroupAssignmentsResponse{ Items: []config_api_client.SensorGroupAssignmentsItem{ @@ -536,8 +549,9 @@ func TestConfigurationAPI(t *testing.T) { SensorGroupAssignmentsPost(context.Background()). SensorGroupAssignmentsPostRequest(*postRequest). Execute() - require.Nil(t, err) + + defer httpRes.Body.Close() assert.Equal(t, http.StatusOK, httpRes.StatusCode) assert.Equal(t, resp, &config_api_client.SensorGroupAssignmentResponse{ Id: "uid", @@ -555,8 +569,9 @@ func TestConfigurationAPI(t *testing.T) { _, httpRes, err := apiClient.ConfigurationAPI. SensorGroupAssignmentsDelete(context.Background(), "uid"). Execute() - require.Nil(t, err) + + defer httpRes.Body.Close() assert.Equal(t, http.StatusNoContent, httpRes.StatusCode) }) @@ -591,12 +606,13 @@ func TestConfigurationAPI(t *testing.T) { Limit(10). Next("some-cursor"). Execute() - security := "security" + dnsLookupDomain := "dns_lookup_domain" var vlanId int32 = 1 - require.Nil(t, err) + + defer httpRes.Body.Close() assert.Equal(t, http.StatusOK, httpRes.StatusCode) assert.Equal(t, resp, &config_api_client.WiredNetworksResponse{ Items: []config_api_client.WiredNetworksItem{ @@ -653,11 +669,12 @@ func TestConfigurationAPI(t *testing.T) { Limit(10). Next("some-cursor"). Execute() - security := "security" - dnsLookupDomain := "dns_lookup_domain" + dnsLookupDomain := "dns_lookup_domain" require.Nil(t, err) + + defer httpRes.Body.Close() assert.Equal(t, http.StatusOK, httpRes.StatusCode) assert.Equal(t, resp, &config_api_client.WirelessNetworksResponse{ Items: []config_api_client.WirelessNetworksItem{ @@ -706,8 +723,9 @@ func TestConfigurationAPI(t *testing.T) { Limit(10). Next("some-cursor"). Execute() - require.Nil(t, err) + + defer httpRes.Body.Close() assert.Equal(t, http.StatusOK, httpRes.StatusCode) assert.Equal(t, resp, &config_api_client.NetworkGroupAssignmentsResponse{ Items: []config_api_client.NetworkGroupAssignmentsItem{ @@ -746,8 +764,9 @@ func TestConfigurationAPI(t *testing.T) { NetworkGroupAssignmentsPost(context.Background()). NetworkGroupAssignmentsPostRequest(*postRequest). Execute() - require.Nil(t, err) + + defer httpRes.Body.Close() assert.Equal(t, http.StatusOK, httpRes.StatusCode) assert.Equal(t, resp, &config_api_client.NetworkGroupAssignmentsPostResponse{ Id: "uid", @@ -765,8 +784,9 @@ func TestConfigurationAPI(t *testing.T) { _, httpRes, err := apiClient.ConfigurationAPI. NetworkGroupAssignmentsDelete(context.Background(), "uid"). Execute() - require.Nil(t, err) + + defer httpRes.Body.Close() assert.Equal(t, http.StatusNoContent, httpRes.StatusCode) }) @@ -793,8 +813,9 @@ func TestConfigurationAPI(t *testing.T) { Limit(10). Next("some-cursor"). Execute() - require.Nil(t, err) + + defer httpRes.Body.Close() assert.Equal(t, http.StatusOK, httpRes.StatusCode) assert.Equal(t, resp, &config_api_client.ServiceTestGroupAssignmentsResponse{ Items: []config_api_client.ServiceTestGroupAssignmentsItem{ @@ -833,8 +854,9 @@ func TestConfigurationAPI(t *testing.T) { ServiceTestGroupAssignmentsPost(context.Background()). ServiceTestGroupAssignmentsPostRequest(*postRequest). Execute() - require.Nil(t, err) + + defer httpRes.Body.Close() assert.Equal(t, http.StatusOK, httpRes.StatusCode) assert.Equal(t, resp, &config_api_client.ServiceTestGroupAssignmentsPostResponse{ Id: "uid", @@ -852,8 +874,9 @@ func TestConfigurationAPI(t *testing.T) { _, httpRes, err := apiClient.ConfigurationAPI. ServiceTestGroupAssignmentsDelete(context.Background(), "uid"). Execute() - require.Nil(t, err) + + defer httpRes.Body.Close() assert.Equal(t, http.StatusNoContent, httpRes.StatusCode) }) } diff --git a/test/live/config/config.go b/test/live/config/config.go index fa54dbe0..318c446a 100644 --- a/test/live/config/config.go +++ b/test/live/config/config.go @@ -10,36 +10,36 @@ package config // customer. // This agent is permanently on the customer -const AgentPermanentId = "abeac07d-3c28-31be-b9e7-30002c753ed4" +const AgentPermanentID = "abeac07d-3c28-31be-b9e7-30002c753ed4" // An agent with this serial will get provisioned const AgentCreateSerial = "56fb38331f19d278" // The customer ID of the acceptance test customer -const CustomerId = "9c16d493-7649-40bc-975b-07422d227c0b" +const CustomerID = "9c16d493-7649-40bc-975b-07422d227c0b" // The root group ID -const GroupIdRoot = "07422d227c0b" +const GroupIDRoot = "07422d227c0b" // This wired network is permanently on the customer const ( - WiredNetworkId = "ethernet-0ee5b46c2ef0" + WiredNetworkID = "ethernet-0ee5b46c2ef0" WiredNetworkName = "tf-provider-acceptance-tests-ethernet-0" ) // This wireless network is permanently on the customer const ( - WirelessNetworkId = "ssid-bf704ff37dc0" + WirelessNetworkID = "ssid-bf704ff37dc0" WirelessNetworkName = "tf-provider-acceptance-tests-ssid-0" ) // This service test is permanently on the customer const ( - ServiceTestId = "6f81e43d-76f1-4a15-aafe-4ce2371d918a" + ServiceTestID = "6f81e43d-76f1-4a15-aafe-4ce2371d918a" ServiceTestName = "tf-provider-acceptance-test-0" ) // This sensor is permanently on the customer -const SensorId = "4b031caf-cea8-411d-8928-79f518163dae" +const SensorID = "4b031caf-cea8-411d-8928-79f518163dae" const DeviceGatewayHost = "https://device-gateway.staging.capedev.io" diff --git a/test/live/datasources/agent_group_assignment_test.go b/test/live/datasources/agent_group_assignment_test.go index 1c824e65..4a60702d 100644 --- a/test/live/datasources/agent_group_assignment_test.go +++ b/test/live/datasources/agent_group_assignment_test.go @@ -30,7 +30,7 @@ func TestAgentGroupAssignmentDataSource(t *testing.T) { data "uxi_agent" "my_agent" { filter = { - id = "` + config.AgentPermanentId + `" + id = "` + config.AgentPermanentID + `" } } @@ -50,6 +50,7 @@ func TestAgentGroupAssignmentDataSource(t *testing.T) { func(s *terraform.State) error { resourceName := "uxi_agent_group_assignment.my_agent_group_assignment" rs := s.RootModule().Resources[resourceName] + return util.CheckStateAgainstAgentGroupAssignment( t, "data.uxi_agent_group_assignment.my_agent_group_assignment", diff --git a/test/live/datasources/agent_test.go b/test/live/datasources/agent_test.go index f4e11685..f6ab3552 100644 --- a/test/live/datasources/agent_test.go +++ b/test/live/datasources/agent_test.go @@ -16,7 +16,7 @@ import ( ) func TestAgentDataSource(t *testing.T) { - agent := util.GetAgent(config.AgentPermanentId) + agent := util.GetAgent(config.AgentPermanentID) resource.Test(t, resource.TestCase{ PreCheck: func() {}, ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -25,7 +25,7 @@ func TestAgentDataSource(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_agent" "my_agent" { filter = { - id = "` + config.AgentPermanentId + `" + id = "` + config.AgentPermanentID + `" } } `, diff --git a/test/live/datasources/group_test.go b/test/live/datasources/group_test.go index e54f2347..d601a5ea 100644 --- a/test/live/datasources/group_test.go +++ b/test/live/datasources/group_test.go @@ -26,7 +26,7 @@ func TestGroupDataSource(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_group" "my_group" { filter = { - id = "` + config.GroupIdRoot + `" + id = "` + config.GroupIDRoot + `" } } `, @@ -51,6 +51,7 @@ func TestGroupDataSource(t *testing.T) { "id", func(value string) error { assert.Equal(t, value, util.GetGroupByName(groupName).Id) + return nil }, ), @@ -60,13 +61,14 @@ func TestGroupDataSource(t *testing.T) { "path", func(value string) error { assert.Equal(t, value, util.GetGroupByName(groupName).Path) + return nil }, ), resource.TestCheckResourceAttr( "data.uxi_group.my_group", "parent_group_id", - config.GroupIdRoot, + config.GroupIDRoot, ), ), }, diff --git a/test/live/datasources/network_group_assignment_test.go b/test/live/datasources/network_group_assignment_test.go index fe00107d..e8706a46 100644 --- a/test/live/datasources/network_group_assignment_test.go +++ b/test/live/datasources/network_group_assignment_test.go @@ -30,7 +30,7 @@ func TestNetworkGroupAssignmentDataSource(t *testing.T) { data "uxi_wired_network" "my_network" { filter = { - id = "` + config.WiredNetworkId + `" + id = "` + config.WiredNetworkID + `" } } @@ -50,6 +50,7 @@ func TestNetworkGroupAssignmentDataSource(t *testing.T) { func(s *terraform.State) error { resourceName := "uxi_network_group_assignment.my_network_group_assignment" rs := s.RootModule().Resources[resourceName] + return util.CheckStateAgainstNetworkGroupAssignment( t, "data.uxi_network_group_assignment.my_network_group_assignment", diff --git a/test/live/datasources/sensor_group_assignment_test.go b/test/live/datasources/sensor_group_assignment_test.go index 9b076107..c0a4d181 100644 --- a/test/live/datasources/sensor_group_assignment_test.go +++ b/test/live/datasources/sensor_group_assignment_test.go @@ -30,7 +30,7 @@ func TestSensorGroupAssignmentDataSource(t *testing.T) { data "uxi_sensor" "my_sensor" { filter = { - id = "` + config.SensorId + `" + id = "` + config.SensorID + `" } } @@ -50,6 +50,7 @@ func TestSensorGroupAssignmentDataSource(t *testing.T) { func(s *terraform.State) error { resourceName := "uxi_sensor_group_assignment.my_sensor_group_assignment" rs := s.RootModule().Resources[resourceName] + return util.CheckStateAgainstSensorGroupAssignment( t, "data.uxi_sensor_group_assignment.my_sensor_group_assignment", diff --git a/test/live/datasources/sensor_test.go b/test/live/datasources/sensor_test.go index e46cbba0..f136c81c 100644 --- a/test/live/datasources/sensor_test.go +++ b/test/live/datasources/sensor_test.go @@ -16,7 +16,7 @@ import ( ) func TestSensorDataSource(t *testing.T) { - sensor := util.GetSensor(config.SensorId) + sensor := util.GetSensor(config.SensorID) resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, Steps: []resource.TestStep{ @@ -24,7 +24,7 @@ func TestSensorDataSource(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_sensor" "my_sensor" { filter = { - id = "` + config.SensorId + `" + id = "` + config.SensorID + `" } } `, diff --git a/test/live/datasources/service_test.go b/test/live/datasources/service_test.go index 1f07bb5e..a9194cc0 100644 --- a/test/live/datasources/service_test.go +++ b/test/live/datasources/service_test.go @@ -16,7 +16,7 @@ import ( ) func TestServiceTestDataSource(t *testing.T) { - serviceTest := util.GetServiceTest(config.ServiceTestId) + serviceTest := util.GetServiceTest(config.ServiceTestID) resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -25,7 +25,7 @@ func TestServiceTestDataSource(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_service_test" "my_service_test" { filter = { - id = "` + config.ServiceTestId + `" + id = "` + config.ServiceTestID + `" } } `, diff --git a/test/live/datasources/service_test_group_assignment_test.go b/test/live/datasources/service_test_group_assignment_test.go index 45a1455d..9169d4a6 100644 --- a/test/live/datasources/service_test_group_assignment_test.go +++ b/test/live/datasources/service_test_group_assignment_test.go @@ -30,7 +30,7 @@ func TestServiceTestGroupAssignmentDataSource(t *testing.T) { data "uxi_service_test" "my_service_test" { filter = { - id = "` + config.ServiceTestId + `" + id = "` + config.ServiceTestID + `" } } @@ -50,6 +50,7 @@ func TestServiceTestGroupAssignmentDataSource(t *testing.T) { func(s *terraform.State) error { resourceName := "uxi_service_test_group_assignment.my_service_test_group_assignment" rs := s.RootModule().Resources[resourceName] + return util.CheckStateAgainstServiceTestGroupAssignment( t, "data.uxi_service_test_group_assignment.my_service_test_group_assignment", diff --git a/test/live/datasources/wired_network_test.go b/test/live/datasources/wired_network_test.go index 7564526d..15da54bf 100644 --- a/test/live/datasources/wired_network_test.go +++ b/test/live/datasources/wired_network_test.go @@ -16,7 +16,7 @@ import ( ) func TestWiredNetworkDataSource(t *testing.T) { - wiredNetwork := util.GetWiredNetwork(config.WiredNetworkId) + wiredNetwork := util.GetWiredNetwork(config.WiredNetworkID) resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -25,7 +25,7 @@ func TestWiredNetworkDataSource(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_wired_network" "my_wired_network" { filter = { - id = "` + config.WiredNetworkId + `" + id = "` + config.WiredNetworkID + `" } } `, diff --git a/test/live/datasources/wireless_network_test.go b/test/live/datasources/wireless_network_test.go index 81784d12..e10cc048 100644 --- a/test/live/datasources/wireless_network_test.go +++ b/test/live/datasources/wireless_network_test.go @@ -16,7 +16,7 @@ import ( ) func TestWirelessNetworkDataSource(t *testing.T) { - wirelessNetwork := util.GetWirelessNetwork(config.WirelessNetworkId) + wirelessNetwork := util.GetWirelessNetwork(config.WirelessNetworkID) resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -25,7 +25,7 @@ func TestWirelessNetworkDataSource(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_wireless_network" "my_wireless_network" { filter = { - id = "` + config.WirelessNetworkId + `" + id = "` + config.WirelessNetworkID + `" } } `, diff --git a/test/live/resources/agent_group_assignment_test.go b/test/live/resources/agent_group_assignment_test.go index 94d12637..3a330ce8 100644 --- a/test/live/resources/agent_group_assignment_test.go +++ b/test/live/resources/agent_group_assignment_test.go @@ -22,8 +22,8 @@ func TestAgentGroupAssignmentResource(t *testing.T) { group2Name = "tf_provider_acceptance_test_agent_group_assignment_resource_two" ) var ( - resourceIdBeforeRecreate string - resourceIdAfterRecreate string + resourceIDBeforeRecreate string + resourceIDAfterRecreate string ) resource.Test(t, resource.TestCase{ @@ -38,7 +38,7 @@ func TestAgentGroupAssignmentResource(t *testing.T) { data "uxi_agent" "my_agent" { filter = { - id = "` + config.AgentPermanentId + `" + id = "` + config.AgentPermanentID + `" } } @@ -51,13 +51,14 @@ func TestAgentGroupAssignmentResource(t *testing.T) { resource.TestCheckResourceAttr( "uxi_agent_group_assignment.my_agent_group_assignment", "agent_id", - config.AgentPermanentId, + config.AgentPermanentID, ), resource.TestCheckResourceAttrWith( "uxi_agent_group_assignment.my_agent_group_assignment", "group_id", func(value string) error { assert.Equal(t, util.GetGroupByName(groupName).Id, value) + return nil }, ), @@ -65,11 +66,12 @@ func TestAgentGroupAssignmentResource(t *testing.T) { func(s *terraform.State) error { resourceName := "uxi_agent_group_assignment.my_agent_group_assignment" rs := s.RootModule().Resources[resourceName] - resourceIdBeforeRecreate = rs.Primary.ID + resourceIDBeforeRecreate = rs.Primary.ID + return util.CheckStateAgainstAgentGroupAssignment( t, "uxi_agent_group_assignment.my_agent_group_assignment", - *util.GetAgentGroupAssignment(resourceIdBeforeRecreate), + *util.GetAgentGroupAssignment(resourceIDBeforeRecreate), )(s) }, ), @@ -90,7 +92,7 @@ func TestAgentGroupAssignmentResource(t *testing.T) { data "uxi_agent" "my_agent" { filter = { - id = "` + config.AgentPermanentId + `" + id = "` + config.AgentPermanentID + `" } } @@ -109,13 +111,14 @@ func TestAgentGroupAssignmentResource(t *testing.T) { resource.TestCheckResourceAttr( "uxi_agent_group_assignment.my_agent_group_assignment", "agent_id", - config.AgentPermanentId, + config.AgentPermanentID, ), resource.TestCheckResourceAttrWith( "uxi_agent_group_assignment.my_agent_group_assignment", "group_id", func(value string) error { assert.Equal(t, util.GetGroupByName(group2Name).Id, value) + return nil }, ), @@ -123,11 +126,12 @@ func TestAgentGroupAssignmentResource(t *testing.T) { func(s *terraform.State) error { resourceName := "uxi_agent_group_assignment.my_agent_group_assignment" rs := s.RootModule().Resources[resourceName] - resourceIdAfterRecreate = rs.Primary.ID + resourceIDAfterRecreate = rs.Primary.ID + return util.CheckStateAgainstAgentGroupAssignment( t, "uxi_agent_group_assignment.my_agent_group_assignment", - *util.GetAgentGroupAssignment(resourceIdAfterRecreate), + *util.GetAgentGroupAssignment(resourceIDAfterRecreate), )(s) }, ), @@ -142,14 +146,15 @@ func TestAgentGroupAssignmentResource(t *testing.T) { assert.Equal(t, util.GetGroupByName(group2Name), nil) assert.Equal( t, - util.GetAgentGroupAssignment(resourceIdBeforeRecreate), + util.GetAgentGroupAssignment(resourceIDBeforeRecreate), nil, ) assert.Equal( t, - util.GetAgentGroupAssignment(resourceIdAfterRecreate), + util.GetAgentGroupAssignment(resourceIDAfterRecreate), nil, ) + return nil }, }) diff --git a/test/live/resources/agent_test.go b/test/live/resources/agent_test.go index e5d156f4..d68e9a84 100644 --- a/test/live/resources/agent_test.go +++ b/test/live/resources/agent_test.go @@ -23,7 +23,7 @@ import ( func TestAgentResource(t *testing.T) { // we provision an agent here so that we have something to delete later on agentID, err := util.ProvisionAgent{ - CustomerID: config.CustomerId, + CustomerID: config.CustomerID, ProvisionToken: os.Getenv("UXI_PROVISION_TOKEN"), DeviceSerial: config.AgentCreateSerial, DeviceGatewayHost: config.DeviceGatewayHost, @@ -33,12 +33,12 @@ func TestAgentResource(t *testing.T) { } agent := util.GetAgent(agentID) - updated_agent := agent - updated_notes := "notes" - updated_pcapMode := "off" - updated_agent.Name = "tf_provider_acceptance_test_agent_resource_updated_name" - updated_agent.Notes = *config_api_client.NewNullableString(&updated_notes) - updated_agent.PcapMode = *config_api_client.NewNullableString(&updated_pcapMode) + updatedAgent := agent + updatedNotes := "notes" + updatedPcapMode := "off" + updatedAgent.Name = "tf_provider_acceptance_test_agent_resource_updated_name" + updatedAgent.Notes = *config_api_client.NewNullableString(&updatedNotes) + updatedAgent.PcapMode = *config_api_client.NewNullableString(&updatedPcapMode) resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -81,7 +81,7 @@ func TestAgentResource(t *testing.T) { notes = "notes" pcap_mode = "off" }`, - Check: shared.CheckStateAgainstAgent(t, "uxi_agent.my_agent", updated_agent), + Check: shared.CheckStateAgainstAgent(t, "uxi_agent.my_agent", updatedAgent), }, // Delete { @@ -90,6 +90,7 @@ func TestAgentResource(t *testing.T) { }, CheckDestroy: func(s *terraform.State) error { assert.Equal(t, util.GetAgent(agentID), nil) + return nil }, }) diff --git a/test/live/resources/group_test.go b/test/live/resources/group_test.go index 8f902c85..3c4ec784 100644 --- a/test/live/resources/group_test.go +++ b/test/live/resources/group_test.go @@ -32,7 +32,7 @@ func TestGroupResource(t *testing.T) { groupNameGrandChildMovedToRoot = groupNameGrandChild + "_moved_to_root" ) - var resourceIdBeforeRecreate string + var resourceIDBeforeRecreate string resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -50,6 +50,7 @@ func TestGroupResource(t *testing.T) { "id", func(value string) error { assert.Equal(t, value, util.GetGroupByName(groupNameParent).Id) + return nil }, ), @@ -77,6 +78,7 @@ func TestGroupResource(t *testing.T) { "id", func(value string) error { assert.Equal(t, value, util.GetGroupByName(groupNameParentUpdated).Id) + return nil }, ), @@ -113,6 +115,7 @@ func TestGroupResource(t *testing.T) { "id", func(value string) error { assert.Equal(t, value, util.GetGroupByName(groupNameChild).Id) + return nil }, ), @@ -132,10 +135,11 @@ func TestGroupResource(t *testing.T) { "uxi_group.grandchild", "id", func(value string) error { - resourceIdBeforeRecreate = util.GetGroupByName( + resourceIDBeforeRecreate = util.GetGroupByName( groupNameGrandChild, ).Id - assert.Equal(t, value, resourceIdBeforeRecreate) + assert.Equal(t, value, resourceIDBeforeRecreate) + return nil }, ), @@ -180,6 +184,7 @@ func TestGroupResource(t *testing.T) { value, util.GetGroupByName(groupNameGrandChildMovedToParent).Id, ) + return nil }, ), @@ -200,7 +205,8 @@ func TestGroupResource(t *testing.T) { "uxi_group.grandchild", "id", func(value string) error { - assert.NotEqual(t, value, resourceIdBeforeRecreate) + assert.NotEqual(t, value, resourceIDBeforeRecreate) + return nil }, ), @@ -246,6 +252,7 @@ func TestGroupResource(t *testing.T) { assert.Equal(t, util.GetGroupByName(groupNameGrandChild), nil) assert.Equal(t, util.GetGroupByName(groupNameGrandChildMovedToParent), nil) assert.Equal(t, util.GetGroupByName(groupNameGrandChildMovedToRoot), nil) + return nil }, }) @@ -264,7 +271,7 @@ func TestRootGroupResource(t *testing.T) { import { to = uxi_group.my_root_group - id = "` + config.GroupIdRoot + `" + id = "` + config.GroupIDRoot + `" }`, ExpectError: regexp.MustCompile(`The root group cannot be used as a resource`), }, @@ -272,14 +279,14 @@ func TestRootGroupResource(t *testing.T) { }) } -func checkGroupIsChildOfNode(actualParentGroupId, expectedParentName string) error { - expectedParentGroupId := util.GetGroupByName(expectedParentName).GetId() +func checkGroupIsChildOfNode(actualParentGroupID, expectedParentName string) error { + expectedParentGroupID := util.GetGroupByName(expectedParentName).GetId() - if expectedParentGroupId != actualParentGroupId { + if expectedParentGroupID != actualParentGroupID { return fmt.Errorf( "expected \"%s\", but got \"%s\"", - expectedParentGroupId, - actualParentGroupId, + expectedParentGroupID, + actualParentGroupID, ) } diff --git a/test/live/resources/network_group_assignment_test.go b/test/live/resources/network_group_assignment_test.go index 64d746cb..dc092f21 100644 --- a/test/live/resources/network_group_assignment_test.go +++ b/test/live/resources/network_group_assignment_test.go @@ -23,8 +23,8 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { ) var ( - resourceIdBeforeRecreate string - resourceIdAfterRecreate string + resourceIDBeforeRecreate string + resourceIDAfterRecreate string ) // Test Wired Network Group Assignment @@ -44,7 +44,7 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { import { to = uxi_wired_network.my_network - id = "` + config.WiredNetworkId + `" + id = "` + config.WiredNetworkID + `" } resource "uxi_network_group_assignment" "my_network_group_assignment" { @@ -56,13 +56,14 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { resource.TestCheckResourceAttr( "uxi_network_group_assignment.my_network_group_assignment", "network_id", - config.WiredNetworkId, + config.WiredNetworkID, ), resource.TestCheckResourceAttrWith( "uxi_network_group_assignment.my_network_group_assignment", "group_id", func(group_id string) error { assert.Equal(t, group_id, util.GetGroupByName(groupName).Id) + return nil }, ), @@ -70,11 +71,12 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { func(s *terraform.State) error { resourceName := "uxi_network_group_assignment.my_network_group_assignment" rs := s.RootModule().Resources[resourceName] - resourceIdBeforeRecreate = rs.Primary.ID + resourceIDBeforeRecreate = rs.Primary.ID + return util.CheckStateAgainstNetworkGroupAssignment( t, "uxi_network_group_assignment.my_network_group_assignment", - util.GetNetworkGroupAssignment(resourceIdBeforeRecreate), + util.GetNetworkGroupAssignment(resourceIDBeforeRecreate), )(s) }, ), @@ -99,7 +101,7 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { import { to = uxi_wired_network.my_network - id = "` + config.WiredNetworkId + `" + id = "` + config.WiredNetworkID + `" } // the new resources we wanna update the assignment to @@ -117,13 +119,14 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { resource.TestCheckResourceAttr( "uxi_network_group_assignment.my_network_group_assignment", "network_id", - config.WiredNetworkId, + config.WiredNetworkID, ), resource.TestCheckResourceAttrWith( "uxi_network_group_assignment.my_network_group_assignment", "group_id", func(group_id string) error { assert.Equal(t, group_id, util.GetGroupByName(group2Name).Id) + return nil }, ), @@ -131,11 +134,12 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { func(s *terraform.State) error { resourceName := "uxi_network_group_assignment.my_network_group_assignment" rs := s.RootModule().Resources[resourceName] - resourceIdAfterRecreate = rs.Primary.ID + resourceIDAfterRecreate = rs.Primary.ID + return util.CheckStateAgainstNetworkGroupAssignment( t, "uxi_network_group_assignment.my_network_group_assignment", - util.GetNetworkGroupAssignment(resourceIdAfterRecreate), + util.GetNetworkGroupAssignment(resourceIDAfterRecreate), )(s) }, // Check that resource has been recreated @@ -143,7 +147,8 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { "uxi_network_group_assignment.my_network_group_assignment", "id", func(value string) error { - assert.NotEqual(t, value, resourceIdBeforeRecreate) + assert.NotEqual(t, value, resourceIDBeforeRecreate) + return nil }, ), @@ -164,8 +169,9 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { CheckDestroy: func(s *terraform.State) error { assert.Equal(t, util.GetGroupByName(groupName), nil) assert.Equal(t, util.GetGroupByName(group2Name), nil) - assert.Equal(t, util.GetAgentGroupAssignment(resourceIdBeforeRecreate), nil) - assert.Equal(t, util.GetAgentGroupAssignment(resourceIdAfterRecreate), nil) + assert.Equal(t, util.GetAgentGroupAssignment(resourceIDBeforeRecreate), nil) + assert.Equal(t, util.GetAgentGroupAssignment(resourceIDAfterRecreate), nil) + return nil }, }) @@ -178,8 +184,8 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { ) var ( - resourceIdBeforeRecreate string - resourceIdAfterRecreate string + resourceIDBeforeRecreate string + resourceIDAfterRecreate string ) // Test Wired Network Group Assignment @@ -199,7 +205,7 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { import { to = uxi_wireless_network.my_network - id = "` + config.WirelessNetworkId + `" + id = "` + config.WirelessNetworkID + `" } resource "uxi_network_group_assignment" "my_network_group_assignment" { @@ -211,13 +217,14 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { resource.TestCheckResourceAttr( "uxi_network_group_assignment.my_network_group_assignment", "network_id", - config.WirelessNetworkId, + config.WirelessNetworkID, ), resource.TestCheckResourceAttrWith( "uxi_network_group_assignment.my_network_group_assignment", "group_id", func(group_id string) error { assert.Equal(t, group_id, util.GetGroupByName(groupName).Id) + return nil }, ), @@ -225,11 +232,12 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { func(s *terraform.State) error { resourceName := "uxi_network_group_assignment.my_network_group_assignment" rs := s.RootModule().Resources[resourceName] - resourceIdBeforeRecreate = rs.Primary.ID + resourceIDBeforeRecreate = rs.Primary.ID + return util.CheckStateAgainstNetworkGroupAssignment( t, "uxi_network_group_assignment.my_network_group_assignment", - util.GetNetworkGroupAssignment(resourceIdBeforeRecreate), + util.GetNetworkGroupAssignment(resourceIDBeforeRecreate), )(s) }, ), @@ -254,7 +262,7 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { import { to = uxi_wireless_network.my_network - id = "` + config.WirelessNetworkId + `" + id = "` + config.WirelessNetworkID + `" } // the new resources we wanna update the assignment to @@ -272,13 +280,14 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { resource.TestCheckResourceAttr( "uxi_network_group_assignment.my_network_group_assignment", "network_id", - config.WirelessNetworkId, + config.WirelessNetworkID, ), resource.TestCheckResourceAttrWith( "uxi_network_group_assignment.my_network_group_assignment", "group_id", func(group_id string) error { assert.Equal(t, group_id, util.GetGroupByName(group2Name).Id) + return nil }, ), @@ -286,11 +295,12 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { func(s *terraform.State) error { resourceName := "uxi_network_group_assignment.my_network_group_assignment" rs := s.RootModule().Resources[resourceName] - resourceIdAfterRecreate = rs.Primary.ID + resourceIDAfterRecreate = rs.Primary.ID + return util.CheckStateAgainstNetworkGroupAssignment( t, "uxi_network_group_assignment.my_network_group_assignment", - util.GetNetworkGroupAssignment(resourceIdAfterRecreate), + util.GetNetworkGroupAssignment(resourceIDAfterRecreate), )(s) }, // Check that resource has been recreated @@ -298,7 +308,8 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { "uxi_network_group_assignment.my_network_group_assignment", "id", func(value string) error { - assert.NotEqual(t, value, resourceIdBeforeRecreate) + assert.NotEqual(t, value, resourceIDBeforeRecreate) + return nil }, ), @@ -319,8 +330,9 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { CheckDestroy: func(s *terraform.State) error { assert.Equal(t, util.GetGroupByName(groupName), nil) assert.Equal(t, util.GetGroupByName(group2Name), nil) - assert.Equal(t, util.GetAgentGroupAssignment(resourceIdBeforeRecreate), nil) - assert.Equal(t, util.GetAgentGroupAssignment(resourceIdAfterRecreate), nil) + assert.Equal(t, util.GetAgentGroupAssignment(resourceIDBeforeRecreate), nil) + assert.Equal(t, util.GetAgentGroupAssignment(resourceIDAfterRecreate), nil) + return nil }, }) diff --git a/test/live/resources/sensor_group_assignment_test.go b/test/live/resources/sensor_group_assignment_test.go index ebc98b15..7db60892 100644 --- a/test/live/resources/sensor_group_assignment_test.go +++ b/test/live/resources/sensor_group_assignment_test.go @@ -23,9 +23,9 @@ func TestSensorGroupAssignmentResource(t *testing.T) { ) var ( - existingSensorProperties = util.GetSensor(config.SensorId) - resourceIdBeforeRecreate string - resourceIdAfterRecreate string + existingSensorProperties = util.GetSensor(config.SensorID) + resourceIDBeforeRecreate string + resourceIDAfterRecreate string ) resource.Test(t, resource.TestCase{ @@ -47,7 +47,7 @@ func TestSensorGroupAssignmentResource(t *testing.T) { import { to = uxi_sensor.my_sensor - id = "` + config.SensorId + `" + id = "` + config.SensorID + `" } resource "uxi_sensor_group_assignment" "my_sensor_group_assignment" { @@ -59,13 +59,14 @@ func TestSensorGroupAssignmentResource(t *testing.T) { resource.TestCheckResourceAttr( "uxi_sensor_group_assignment.my_sensor_group_assignment", "sensor_id", - config.SensorId, + config.SensorID, ), resource.TestCheckResourceAttrWith( "uxi_sensor_group_assignment.my_sensor_group_assignment", "group_id", func(value string) error { assert.Equal(t, value, util.GetGroupByName(groupName).Id) + return nil }, ), @@ -73,11 +74,12 @@ func TestSensorGroupAssignmentResource(t *testing.T) { func(s *terraform.State) error { resourceName := "uxi_sensor_group_assignment.my_sensor_group_assignment" rs := s.RootModule().Resources[resourceName] - resourceIdBeforeRecreate = rs.Primary.ID + resourceIDBeforeRecreate = rs.Primary.ID + return util.CheckStateAgainstSensorGroupAssignment( t, "uxi_sensor_group_assignment.my_sensor_group_assignment", - util.GetSensorGroupAssignment(resourceIdBeforeRecreate), + util.GetSensorGroupAssignment(resourceIDBeforeRecreate), )(s) }, ), @@ -118,13 +120,14 @@ func TestSensorGroupAssignmentResource(t *testing.T) { resource.TestCheckResourceAttr( "uxi_sensor_group_assignment.my_sensor_group_assignment", "sensor_id", - config.SensorId, + config.SensorID, ), resource.TestCheckResourceAttrWith( "uxi_sensor_group_assignment.my_sensor_group_assignment", "group_id", func(value string) error { assert.Equal(t, value, util.GetGroupByName(group2Name).Id) + return nil }, ), @@ -132,11 +135,12 @@ func TestSensorGroupAssignmentResource(t *testing.T) { func(s *terraform.State) error { resourceName := "uxi_sensor_group_assignment.my_sensor_group_assignment" rs := s.RootModule().Resources[resourceName] - resourceIdAfterRecreate = rs.Primary.ID + resourceIDAfterRecreate = rs.Primary.ID + return util.CheckStateAgainstSensorGroupAssignment( t, "uxi_sensor_group_assignment.my_sensor_group_assignment", - util.GetSensorGroupAssignment(resourceIdAfterRecreate), + util.GetSensorGroupAssignment(resourceIDAfterRecreate), )(s) }, ), @@ -156,8 +160,9 @@ func TestSensorGroupAssignmentResource(t *testing.T) { CheckDestroy: func(s *terraform.State) error { assert.Equal(t, util.GetGroupByName(groupName), nil) assert.Equal(t, util.GetGroupByName(group2Name), nil) - assert.Equal(t, util.GetAgentGroupAssignment(resourceIdBeforeRecreate), nil) - assert.Equal(t, util.GetAgentGroupAssignment(resourceIdAfterRecreate), nil) + assert.Equal(t, util.GetAgentGroupAssignment(resourceIDBeforeRecreate), nil) + assert.Equal(t, util.GetAgentGroupAssignment(resourceIDAfterRecreate), nil) + return nil }, }) diff --git a/test/live/resources/sensor_test.go b/test/live/resources/sensor_test.go index 4fea6e67..b6c3a53e 100644 --- a/test/live/resources/sensor_test.go +++ b/test/live/resources/sensor_test.go @@ -19,7 +19,7 @@ import ( ) func TestSensorResource(t *testing.T) { - originalSensor := util.GetSensor(config.SensorId) + originalSensor := util.GetSensor(config.SensorID) updatedSensor := originalSensor updatedSensor.Notes = *config_api_client.NewNullableString(config_api_client.PtrString("tf_provider_acceptance_test_update_notes")) updatedSensor.AddressNote = *config_api_client.NewNullableString(config_api_client.PtrString("tf_provider_acceptance_test_update_address_note")) @@ -52,7 +52,7 @@ func TestSensorResource(t *testing.T) { import { to = uxi_sensor.my_sensor - id = "` + config.SensorId + `" + id = "` + config.SensorID + `" }`, Check: shared.CheckStateAgainstSensor(t, "uxi_sensor.my_sensor", originalSensor), diff --git a/test/live/resources/service_test.go b/test/live/resources/service_test.go index f1332d71..74f34837 100644 --- a/test/live/resources/service_test.go +++ b/test/live/resources/service_test.go @@ -18,7 +18,7 @@ import ( ) func TestServiceTestResource(t *testing.T) { - serviceTest := util.GetServiceTest(config.ServiceTestId) + serviceTest := util.GetServiceTest(config.ServiceTestID) resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -47,7 +47,7 @@ func TestServiceTestResource(t *testing.T) { import { to = uxi_service_test.my_service_test - id = "` + config.ServiceTestId + `" + id = "` + config.ServiceTestID + `" }`, Check: shared.CheckStateAgainstServiceTest( diff --git a/test/live/resources/service_test_group_assignment_test.go b/test/live/resources/service_test_group_assignment_test.go index dc099542..20ce2e16 100644 --- a/test/live/resources/service_test_group_assignment_test.go +++ b/test/live/resources/service_test_group_assignment_test.go @@ -23,8 +23,8 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { ) var ( - resourceIdBeforeRecreate string - resourceIdAfterRecreate string + resourceIDBeforeRecreate string + resourceIDAfterRecreate string ) resource.Test(t, resource.TestCase{ @@ -43,7 +43,7 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { import { to = uxi_service_test.my_service_test - id = "` + config.ServiceTestId + `" + id = "` + config.ServiceTestID + `" } resource "uxi_service_test_group_assignment" "my_service_test_group_assignment" { @@ -55,13 +55,14 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { resource.TestCheckResourceAttr( "uxi_service_test_group_assignment.my_service_test_group_assignment", "service_test_id", - config.ServiceTestId, + config.ServiceTestID, ), resource.TestCheckResourceAttrWith( "uxi_service_test_group_assignment.my_service_test_group_assignment", "group_id", func(value string) error { assert.Equal(t, value, util.GetGroupByName(groupName).Id) + return nil }, ), @@ -69,7 +70,8 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { func(s *terraform.State) error { resourceName := "uxi_service_test_group_assignment.my_service_test_group_assignment" rs := s.RootModule().Resources[resourceName] - resourceIdBeforeRecreate = rs.Primary.ID + resourceIDBeforeRecreate = rs.Primary.ID + return util.CheckStateAgainstServiceTestGroupAssignment( t, "uxi_service_test_group_assignment.my_service_test_group_assignment", @@ -111,13 +113,14 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { resource.TestCheckResourceAttr( "uxi_service_test_group_assignment.my_service_test_group_assignment", "service_test_id", - config.ServiceTestId, + config.ServiceTestID, ), resource.TestCheckResourceAttrWith( "uxi_service_test_group_assignment.my_service_test_group_assignment", "group_id", func(value string) error { assert.Equal(t, value, util.GetGroupByName(group2Name).Id) + return nil }, ), @@ -125,7 +128,8 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { func(s *terraform.State) error { resourceName := "uxi_service_test_group_assignment.my_service_test_group_assignment" rs := s.RootModule().Resources[resourceName] - resourceIdAfterRecreate = rs.Primary.ID + resourceIDAfterRecreate = rs.Primary.ID + return util.CheckStateAgainstServiceTestGroupAssignment( t, "uxi_service_test_group_assignment.my_service_test_group_assignment", @@ -137,7 +141,8 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { "uxi_service_test_group_assignment.my_service_test_group_assignment", "id", func(value string) error { - assert.NotEqual(t, value, resourceIdBeforeRecreate) + assert.NotEqual(t, value, resourceIDBeforeRecreate) + return nil }, ), @@ -158,8 +163,9 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { CheckDestroy: func(s *terraform.State) error { assert.Equal(t, util.GetGroupByName(groupName), nil) assert.Equal(t, util.GetGroupByName(group2Name), nil) - assert.Equal(t, util.GetAgentGroupAssignment(resourceIdBeforeRecreate), nil) - assert.Equal(t, util.GetAgentGroupAssignment(resourceIdAfterRecreate), nil) + assert.Equal(t, util.GetAgentGroupAssignment(resourceIDBeforeRecreate), nil) + assert.Equal(t, util.GetAgentGroupAssignment(resourceIDAfterRecreate), nil) + return nil }, }) diff --git a/test/live/resources/wired_network_test.go b/test/live/resources/wired_network_test.go index 17c91df5..8dcbab81 100644 --- a/test/live/resources/wired_network_test.go +++ b/test/live/resources/wired_network_test.go @@ -18,7 +18,7 @@ import ( ) func TestWiredNetworkResource(t *testing.T) { - wiredNetwork := util.GetWiredNetwork(config.WiredNetworkId) + wiredNetwork := util.GetWiredNetwork(config.WiredNetworkID) resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -47,7 +47,7 @@ func TestWiredNetworkResource(t *testing.T) { import { to = uxi_wired_network.wired_network_0 - id = "` + config.WiredNetworkId + `" + id = "` + config.WiredNetworkID + `" }`, Check: shared.CheckStateAgainstWiredNetwork( @@ -66,7 +66,7 @@ func TestWiredNetworkResource(t *testing.T) { { Config: provider.ProviderConfig + ` resource "uxi_wired_network" "wired_network_0" { - name = "` + config.WiredNetworkId + `-updated-name" + name = "` + config.WiredNetworkID + `-updated-name" }`, ExpectError: regexp.MustCompile( `(?s)updating a wired_network is not supported; wired_networks can only be updated\s*through the dashboard`, diff --git a/test/live/resources/wireless_network_test.go b/test/live/resources/wireless_network_test.go index 3990dce0..0aae2f55 100644 --- a/test/live/resources/wireless_network_test.go +++ b/test/live/resources/wireless_network_test.go @@ -18,7 +18,7 @@ import ( ) func TestWirelessNetworkResource(t *testing.T) { - wirelessNetwork := util.GetWirelessNetwork(config.WirelessNetworkId) + wirelessNetwork := util.GetWirelessNetwork(config.WirelessNetworkID) resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -47,7 +47,7 @@ func TestWirelessNetworkResource(t *testing.T) { import { to = uxi_wireless_network.wireless_network_0 - id = "` + config.WirelessNetworkId + `" + id = "` + config.WirelessNetworkID + `" }`, Check: shared.CheckStateAgainstWirelessNetwork( diff --git a/test/live/util/agent.go b/test/live/util/agent.go index d61a327f..9561edb0 100644 --- a/test/live/util/agent.go +++ b/test/live/util/agent.go @@ -7,7 +7,7 @@ package util import ( "bytes" "context" - "crypto/md5" + "crypto/md5" // #nosec G501 "encoding/json" "fmt" "io" @@ -19,16 +19,18 @@ import ( ) func GetAgent(id string) config_api_client.AgentItem { - result, _, err := Client.ConfigurationAPI. + result, response, err := Client.ConfigurationAPI. AgentsGet(context.Background()). Id(id). Execute() if err != nil { panic(err) } + defer response.Body.Close() if len(result.Items) != 1 { panic("agent with id `" + id + "` could not be found") } + return result.Items[0] } @@ -93,7 +95,7 @@ func (p ProvisionAgent) Provision() (string, error) { func (p ProvisionAgent) generateID() (string, error) { // Create an MD5 hash of the serial string - hasher := md5.New() + hasher := md5.New() // #nosec G401 hasher.Write([]byte(p.DeviceSerial)) digest := hasher.Sum(nil) diff --git a/test/live/util/agent_group_assignment.go b/test/live/util/agent_group_assignment.go index 2256f428..0d35bd6d 100644 --- a/test/live/util/agent_group_assignment.go +++ b/test/live/util/agent_group_assignment.go @@ -14,16 +14,18 @@ import ( ) func GetAgentGroupAssignment(id string) *config_api_client.AgentGroupAssignmentsItem { - result, _, err := Client.ConfigurationAPI. + result, response, err := Client.ConfigurationAPI. AgentGroupAssignmentsGet(context.Background()). Id(id). Execute() if err != nil { panic(err) } + defer response.Body.Close() if len(result.Items) != 1 { return nil } + return &result.Items[0] } diff --git a/test/live/util/group.go b/test/live/util/group.go index e689c4f9..d464a78d 100644 --- a/test/live/util/group.go +++ b/test/live/util/group.go @@ -11,11 +11,16 @@ import ( ) func GetGroupByName(name string) *config_api_client.GroupsGetItem { - groups, _, _ := Client.ConfigurationAPI.GroupsGet(context.Background()).Execute() + groups, response, err := Client.ConfigurationAPI.GroupsGet(context.Background()).Execute() + if err != nil { + panic(err) + } + defer response.Body.Close() for _, group := range groups.Items { if group.Name == name { return &group } } + return nil } diff --git a/test/live/util/network_group_assignment.go b/test/live/util/network_group_assignment.go index 9cce7291..47c7461f 100644 --- a/test/live/util/network_group_assignment.go +++ b/test/live/util/network_group_assignment.go @@ -14,16 +14,18 @@ import ( ) func GetNetworkGroupAssignment(id string) config_api_client.NetworkGroupAssignmentsItem { - result, _, err := Client.ConfigurationAPI. + result, response, err := Client.ConfigurationAPI. NetworkGroupAssignmentsGet(context.Background()). Id(id). Execute() if err != nil { panic(err) } + defer response.Body.Close() if len(result.Items) != 1 { panic("network_group_assignment with id `" + id + "` could not be found") } + return result.Items[0] } diff --git a/test/live/util/sensor.go b/test/live/util/sensor.go index 64844aa0..a5c32c81 100644 --- a/test/live/util/sensor.go +++ b/test/live/util/sensor.go @@ -11,15 +11,17 @@ import ( ) func GetSensor(id string) config_api_client.SensorItem { - result, _, err := Client.ConfigurationAPI. + result, response, err := Client.ConfigurationAPI. SensorsGet(context.Background()). Id(id). Execute() if err != nil { panic(err) } + defer response.Body.Close() if len(result.Items) != 1 { panic("sensor with id `" + id + "` could not be found") } + return result.Items[0] } diff --git a/test/live/util/sensor_group_assignment.go b/test/live/util/sensor_group_assignment.go index b651ff9d..2151eec5 100644 --- a/test/live/util/sensor_group_assignment.go +++ b/test/live/util/sensor_group_assignment.go @@ -14,16 +14,18 @@ import ( ) func GetSensorGroupAssignment(id string) config_api_client.SensorGroupAssignmentsItem { - result, _, err := Client.ConfigurationAPI. + result, response, err := Client.ConfigurationAPI. SensorGroupAssignmentsGet(context.Background()). Id(id). Execute() if err != nil { panic(err) } + defer response.Body.Close() if len(result.Items) != 1 { panic("sensor_group_assignment with id `" + id + "` could not be found") } + return result.Items[0] } diff --git a/test/live/util/service.go b/test/live/util/service.go index d9ab58da..9ccae832 100644 --- a/test/live/util/service.go +++ b/test/live/util/service.go @@ -11,15 +11,17 @@ import ( ) func GetServiceTest(id string) config_api_client.ServiceTestsListItem { - result, _, err := Client.ConfigurationAPI. + result, response, err := Client.ConfigurationAPI. ServiceTestsGet(context.Background()). Id(id). Execute() if err != nil { panic(err) } + defer response.Body.Close() if len(result.Items) != 1 { panic("service_test with id `" + id + "` could not be found") } + return result.Items[0] } diff --git a/test/live/util/service_test_group_assignment.go b/test/live/util/service_test_group_assignment.go index d09ecc24..b7d1cf8a 100644 --- a/test/live/util/service_test_group_assignment.go +++ b/test/live/util/service_test_group_assignment.go @@ -14,16 +14,18 @@ import ( ) func GetServiceTestGroupAssignment(id string) config_api_client.ServiceTestGroupAssignmentsItem { - result, _, err := Client.ConfigurationAPI. + result, response, err := Client.ConfigurationAPI. ServiceTestGroupAssignmentsGet(context.Background()). Id(id). Execute() if err != nil { panic(err) } + defer response.Body.Close() if len(result.Items) != 1 { panic("service_test_group_assignment with id `" + id + "` could not be found") } + return result.Items[0] } diff --git a/test/live/util/util.go b/test/live/util/util.go index 23c5bc23..6a885a6c 100644 --- a/test/live/util/util.go +++ b/test/live/util/util.go @@ -8,5 +8,6 @@ func ConditionalProperty(property string, value *string) string { if value == nil { return "" } + return property + `= "` + *value + `"` } diff --git a/test/live/util/wired_network.go b/test/live/util/wired_network.go index 4faaf804..c77ce635 100644 --- a/test/live/util/wired_network.go +++ b/test/live/util/wired_network.go @@ -11,15 +11,17 @@ import ( ) func GetWiredNetwork(id string) config_api_client.WiredNetworksItem { - result, _, err := Client.ConfigurationAPI. + result, response, err := Client.ConfigurationAPI. WiredNetworksGet(context.Background()). Id(id). Execute() if err != nil { panic(err) } + defer response.Body.Close() if len(result.Items) != 1 { panic("wired_network with id `" + id + "` could not be found") } + return result.Items[0] } diff --git a/test/live/util/wireless_network.go b/test/live/util/wireless_network.go index 28f6d66b..b996dd8d 100644 --- a/test/live/util/wireless_network.go +++ b/test/live/util/wireless_network.go @@ -11,15 +11,17 @@ import ( ) func GetWirelessNetwork(id string) config_api_client.WirelessNetworksItem { - result, _, err := Client.ConfigurationAPI. + result, response, err := Client.ConfigurationAPI. WirelessNetworksGet(context.Background()). Id(id). Execute() if err != nil { panic(err) } + defer response.Body.Close() if len(result.Items) != 1 { panic("wireless_network with id `" + id + "` could not be found") } + return result.Items[0] } diff --git a/test/mocked/datasources/agent_group_assignment_test.go b/test/mocked/datasources/agent_group_assignment_test.go index 33512429..6fdf4c69 100644 --- a/test/mocked/datasources/agent_group_assignment_test.go +++ b/test/mocked/datasources/agent_group_assignment_test.go @@ -102,6 +102,7 @@ func TestAgentGroupAssignmentDataSourceTooManyRequestsHandling(t *testing.T) { ), func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), diff --git a/test/mocked/datasources/agent_test.go b/test/mocked/datasources/agent_test.go index 62b72df1..95db8bca 100644 --- a/test/mocked/datasources/agent_test.go +++ b/test/mocked/datasources/agent_test.go @@ -76,6 +76,7 @@ func TestAgentDataSourceTooManyRequestsHandling(t *testing.T) { shared.CheckStateAgainstAgent(t, "data.uxi_agent.my_agent", agent), func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), diff --git a/test/mocked/datasources/group_test.go b/test/mocked/datasources/group_test.go index fdf14609..806853f2 100644 --- a/test/mocked/datasources/group_test.go +++ b/test/mocked/datasources/group_test.go @@ -43,7 +43,7 @@ func TestGroupDataSource(t *testing.T) { }, { PreConfig: func() { - util.MockGetGroup(util.MockRootGroupId, util.GenerateRootGroupGetResponse(), 1) + util.MockGetGroup(util.MockRootGroupID, util.GenerateRootGroupGetResponse(), 1) }, Config: provider.ProviderConfig + ` data "uxi_group" "my_group" { @@ -88,6 +88,7 @@ func TestGroupDataSourceTooManyRequestsHandling(t *testing.T) { resource.TestCheckResourceAttr("data.uxi_group.my_group", "id", "id"), func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), diff --git a/test/mocked/datasources/network_group_assignment_test.go b/test/mocked/datasources/network_group_assignment_test.go index ba8a5899..9de6ad2f 100644 --- a/test/mocked/datasources/network_group_assignment_test.go +++ b/test/mocked/datasources/network_group_assignment_test.go @@ -102,6 +102,7 @@ func TestNetworkGroupAssignmentDataSourceTooManyRequestsHandling(t *testing.T) { ), func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), diff --git a/test/mocked/datasources/sensor_group_assignment_test.go b/test/mocked/datasources/sensor_group_assignment_test.go index c902463a..f9fb5aba 100644 --- a/test/mocked/datasources/sensor_group_assignment_test.go +++ b/test/mocked/datasources/sensor_group_assignment_test.go @@ -102,6 +102,7 @@ func TestSensorGroupAssignmentDataSourceTooManyRequestsHandling(t *testing.T) { ), func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), diff --git a/test/mocked/datasources/sensor_test.go b/test/mocked/datasources/sensor_test.go index 9dd2ff71..880f61ac 100644 --- a/test/mocked/datasources/sensor_test.go +++ b/test/mocked/datasources/sensor_test.go @@ -76,6 +76,7 @@ func TestSensorDataSourceTooManyRequestsHandling(t *testing.T) { shared.CheckStateAgainstSensor(t, "data.uxi_sensor.my_sensor", sensor), func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), diff --git a/test/mocked/datasources/service_test.go b/test/mocked/datasources/service_test.go index a44eceed..586e8ae1 100644 --- a/test/mocked/datasources/service_test.go +++ b/test/mocked/datasources/service_test.go @@ -84,6 +84,7 @@ func TestServiceTestDataSourceTooManyRequestsHandling(t *testing.T) { ), func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), diff --git a/test/mocked/datasources/service_test_group_assignment_test.go b/test/mocked/datasources/service_test_group_assignment_test.go index a791c2bc..6367c45d 100644 --- a/test/mocked/datasources/service_test_group_assignment_test.go +++ b/test/mocked/datasources/service_test_group_assignment_test.go @@ -102,6 +102,7 @@ func TestServiceTestGroupAssignmentDataSourceTooManyRequestsHandling(t *testing. ), func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), diff --git a/test/mocked/datasources/wired_network_test.go b/test/mocked/datasources/wired_network_test.go index 67e904a1..ebd118ab 100644 --- a/test/mocked/datasources/wired_network_test.go +++ b/test/mocked/datasources/wired_network_test.go @@ -84,6 +84,7 @@ func TestWiredNetworkDataSourceTooManyRequestsHandling(t *testing.T) { ), func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), diff --git a/test/mocked/datasources/wireless_network_test.go b/test/mocked/datasources/wireless_network_test.go index bc3b6e4b..6471b1c5 100644 --- a/test/mocked/datasources/wireless_network_test.go +++ b/test/mocked/datasources/wireless_network_test.go @@ -92,6 +92,7 @@ func TestWirelessNetworkDataSourceTooManyRequestsHandling(t *testing.T) { ), func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), diff --git a/test/mocked/resources/agent_group_assignment_test.go b/test/mocked/resources/agent_group_assignment_test.go index fb72a77e..077374cf 100644 --- a/test/mocked/resources/agent_group_assignment_test.go +++ b/test/mocked/resources/agent_group_assignment_test.go @@ -360,6 +360,7 @@ func TestAgentGroupAssignmentResourceTooManyRequestsHandling(t *testing.T) { ), func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), @@ -382,6 +383,7 @@ func TestAgentGroupAssignmentResourceTooManyRequestsHandling(t *testing.T) { ImportStateVerify: true, Check: func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, }, @@ -410,6 +412,7 @@ func TestAgentGroupAssignmentResourceTooManyRequestsHandling(t *testing.T) { Config: provider.ProviderConfig, Check: func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, }, diff --git a/test/mocked/resources/agent_test.go b/test/mocked/resources/agent_test.go index beb153f0..88e448ab 100644 --- a/test/mocked/resources/agent_test.go +++ b/test/mocked/resources/agent_test.go @@ -145,6 +145,7 @@ func TestAgentResourceTooManyRequestsHandling(t *testing.T) { shared.CheckStateAgainstAgent(t, "uxi_agent.my_agent", agent), func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), @@ -177,6 +178,7 @@ func TestAgentResourceTooManyRequestsHandling(t *testing.T) { shared.CheckStateAgainstAgent(t, "uxi_agent.my_agent", updatedAgent), func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), @@ -195,6 +197,7 @@ func TestAgentResourceTooManyRequestsHandling(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), diff --git a/test/mocked/resources/group_test.go b/test/mocked/resources/group_test.go index 6cbd9dc7..faa6d5fa 100644 --- a/test/mocked/resources/group_test.go +++ b/test/mocked/resources/group_test.go @@ -171,7 +171,7 @@ func TestRootGroupResource(t *testing.T) { // Importing the root group does not work { PreConfig: func() { - util.MockGetGroup(util.MockRootGroupId, util.GenerateRootGroupGetResponse(), 1) + util.MockGetGroup(util.MockRootGroupID, util.GenerateRootGroupGetResponse(), 1) }, Config: provider.ProviderConfig + ` resource "uxi_group" "my_root_group" { @@ -180,7 +180,7 @@ func TestRootGroupResource(t *testing.T) { import { to = uxi_group.my_root_group - id = "` + util.MockRootGroupId + `" + id = "` + util.MockRootGroupID + `" }`, ExpectError: regexp.MustCompile(`The root group cannot be used as a resource`), }, @@ -193,7 +193,7 @@ func TestRootGroupResource(t *testing.T) { 1, ) // to indicate the group has the root group as a parent - util.MockGetGroup(util.MockRootGroupId, util.GenerateRootGroupGetResponse(), 1) + util.MockGetGroup(util.MockRootGroupID, util.GenerateRootGroupGetResponse(), 1) util.MockGetGroup( "id", util.GenerateGroupAttachedToRootGroupGetResponse("id", ""), @@ -266,6 +266,7 @@ func TestGroupResourceTooManyRequestsHandling(t *testing.T) { resource.TestCheckResourceAttr("uxi_group.my_group", "id", "id"), func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), @@ -292,6 +293,7 @@ func TestGroupResourceTooManyRequestsHandling(t *testing.T) { resource.TestCheckResourceAttr("uxi_group.my_group", "id", "id"), func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), @@ -329,6 +331,7 @@ func TestGroupResourceTooManyRequestsHandling(t *testing.T) { resource.TestCheckResourceAttr("uxi_group.my_group", "name", "name_2"), func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), diff --git a/test/mocked/resources/network_group_assignment_test.go b/test/mocked/resources/network_group_assignment_test.go index 99deae2e..fca8b8ad 100644 --- a/test/mocked/resources/network_group_assignment_test.go +++ b/test/mocked/resources/network_group_assignment_test.go @@ -675,6 +675,7 @@ func TestNetworkGroupAssignmentResourceTooManyRequestsHandling(t *testing.T) { ), func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), @@ -701,6 +702,7 @@ func TestNetworkGroupAssignmentResourceTooManyRequestsHandling(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), @@ -745,6 +747,7 @@ func TestNetworkGroupAssignmentResourceTooManyRequestsHandling(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), diff --git a/test/mocked/resources/sensor_group_assignment_test.go b/test/mocked/resources/sensor_group_assignment_test.go index d8c263b2..f4553005 100644 --- a/test/mocked/resources/sensor_group_assignment_test.go +++ b/test/mocked/resources/sensor_group_assignment_test.go @@ -372,6 +372,7 @@ func TestSensorGroupAssignmentResourceTooManyRequestsHandling(t *testing.T) { ), func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), @@ -398,6 +399,7 @@ func TestSensorGroupAssignmentResourceTooManyRequestsHandling(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), @@ -445,6 +447,7 @@ func TestSensorGroupAssignmentResourceTooManyRequestsHandling(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), diff --git a/test/mocked/resources/sensor_test.go b/test/mocked/resources/sensor_test.go index ec9dfd00..a50807b2 100644 --- a/test/mocked/resources/sensor_test.go +++ b/test/mocked/resources/sensor_test.go @@ -166,6 +166,7 @@ func TestSensorResourceTooManyRequestsHandling(t *testing.T) { shared.CheckStateAgainstSensor(t, "uxi_sensor.my_sensor", sensor), func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), @@ -199,6 +200,7 @@ func TestSensorResourceTooManyRequestsHandling(t *testing.T) { shared.CheckStateAgainstSensor(t, "uxi_sensor.my_sensor", updatedSensor), func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), diff --git a/test/mocked/resources/service_test.go b/test/mocked/resources/service_test.go index 33e9e7c0..82111dea 100644 --- a/test/mocked/resources/service_test.go +++ b/test/mocked/resources/service_test.go @@ -153,6 +153,7 @@ func TestServiceTestResourceTooManyRequestsHandling(t *testing.T) { ), func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), diff --git a/test/mocked/resources/service_test_group_assignment_test.go b/test/mocked/resources/service_test_group_assignment_test.go index 8e3a6344..8585da73 100644 --- a/test/mocked/resources/service_test_group_assignment_test.go +++ b/test/mocked/resources/service_test_group_assignment_test.go @@ -360,6 +360,7 @@ func TestServiceTestGroupAssignmentResourceTooManyRequestsHandling(t *testing.T) ), func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), @@ -385,6 +386,7 @@ func TestServiceTestGroupAssignmentResourceTooManyRequestsHandling(t *testing.T) Check: resource.ComposeAggregateTestCheckFunc( func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), diff --git a/test/mocked/resources/wired_network_test.go b/test/mocked/resources/wired_network_test.go index 2a06a72f..63879ec7 100644 --- a/test/mocked/resources/wired_network_test.go +++ b/test/mocked/resources/wired_network_test.go @@ -153,6 +153,7 @@ func TestWiredNetworkResourceTooManyRequestsHandling(t *testing.T) { ), func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), diff --git a/test/mocked/resources/wireless_network_test.go b/test/mocked/resources/wireless_network_test.go index 719402d8..13850d47 100644 --- a/test/mocked/resources/wireless_network_test.go +++ b/test/mocked/resources/wireless_network_test.go @@ -180,6 +180,7 @@ func TestWirelessNetworkResourceTooManyRequestsHandling(t *testing.T) { ), func(s *terraform.State) error { assert.Equal(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil }, ), diff --git a/test/mocked/util/agent.go b/test/mocked/util/agent.go index d4c9ffe9..d1c030a9 100644 --- a/test/mocked/util/agent.go +++ b/test/mocked/util/agent.go @@ -17,6 +17,7 @@ func GenerateAgentPatchRequest(postfix string) config_api_client.AgentsPatchRequ name := "name" + postfix notes := "notes" + postfix pcapMode, _ := config_api_client.NewPcapModeFromValue("light") + return config_api_client.AgentsPatchRequest{ Name: &name, Notes: ¬es, diff --git a/test/mocked/util/group.go b/test/mocked/util/group.go index 6f9e44ca..4ded6f82 100644 --- a/test/mocked/util/group.go +++ b/test/mocked/util/group.go @@ -13,20 +13,20 @@ import ( "github.com/aruba-uxi/terraform-provider-hpeuxi/test/shared" ) -const MockRootGroupId = "root_group_id" +const MockRootGroupID = "root_group_id" func GenerateGroupPostResponse( id string, nameSuffix string, - parentIdSuffix string, + parentIDSuffix string, ) config_api_client.GroupsPostResponse { - parentId := "parent_id" + parentIdSuffix + parentID := "parent_id" + parentIDSuffix return config_api_client.GroupsPostResponse{ Id: id, Name: "name" + nameSuffix, - Parent: *config_api_client.NewParent(parentId), - Path: parentId + "." + id, + Parent: *config_api_client.NewParent(parentID), + Path: parentID + "." + id, Type: shared.GroupType, } } @@ -38,7 +38,7 @@ func GenerateGroupAttachedToRootGroupPostResponse( return config_api_client.GroupsPostResponse{ Id: id, Name: "name" + nameSuffix, - Parent: *config_api_client.NewParent(MockRootGroupId), + Parent: *config_api_client.NewParent(MockRootGroupID), Path: "root_group_id." + id, Type: shared.GroupType, } @@ -47,15 +47,15 @@ func GenerateGroupAttachedToRootGroupPostResponse( func GenerateGroupPatchResponse( id string, nameSuffix string, - parentIdSuffix string, + parentIDSuffix string, ) config_api_client.GroupsPatchResponse { - parentId := "parent_id" + parentIdSuffix + parentID := "parent_id" + parentIDSuffix return config_api_client.GroupsPatchResponse{ Id: id, Name: "name" + nameSuffix, - Parent: *config_api_client.NewParent(parentId), - Path: parentId + "." + id, + Parent: *config_api_client.NewParent(parentID), + Path: parentID + "." + id, Type: shared.GroupType, } } @@ -63,17 +63,17 @@ func GenerateGroupPatchResponse( func GenerateGroupGetResponse( id string, nameSuffix string, - parentIdSuffix string, + parentIDSuffix string, ) config_api_client.GroupsGetResponse { - parentId := "parent_id" + parentIdSuffix + parentID := "parent_id" + parentIDSuffix return config_api_client.GroupsGetResponse{ Items: []config_api_client.GroupsGetItem{ { Id: id, Name: "name" + nameSuffix, - Parent: *config_api_client.NewNullableParent(config_api_client.NewParent(parentId)), - Path: parentId + "." + id, + Parent: *config_api_client.NewNullableParent(config_api_client.NewParent(parentID)), + Path: parentID + "." + id, Type: shared.GroupType, }, }, @@ -91,7 +91,7 @@ func GenerateGroupAttachedToRootGroupGetResponse( { Id: id, Name: "name" + nameSuffix, - Parent: *config_api_client.NewNullableParent(config_api_client.NewParent(MockRootGroupId)), + Parent: *config_api_client.NewNullableParent(config_api_client.NewParent(MockRootGroupID)), Path: "root_group_id." + id, Type: shared.GroupType, }, @@ -105,10 +105,10 @@ func GenerateRootGroupGetResponse() config_api_client.GroupsGetResponse { return config_api_client.GroupsGetResponse{ Items: []config_api_client.GroupsGetItem{ { - Id: MockRootGroupId, + Id: MockRootGroupID, Name: "root", Parent: *config_api_client.NewNullableParent(nil), - Path: MockRootGroupId, + Path: MockRootGroupID, Type: shared.GroupType, }, }, @@ -120,13 +120,13 @@ func GenerateRootGroupGetResponse() config_api_client.GroupsGetResponse { func GenerateNonRootGroupPostRequest( id string, namePostfix string, - parentIdPostfix string, + parentIDPostfix string, ) config_api_client.GroupsPostRequest { - parentId := "parent_id" + parentIdPostfix + parentID := "parent_id" + parentIDPostfix return config_api_client.GroupsPostRequest{ Name: "name" + namePostfix, - ParentId: *config_api_client.NewNullableString(&parentId), + ParentId: *config_api_client.NewNullableString(&parentID), } } @@ -141,6 +141,7 @@ func GenerateGroupAttachedToRootGroupPostRequest( func GenerateGroupPatchRequest(postfix string) config_api_client.GroupsPatchRequest { name := "name" + postfix + return config_api_client.GroupsPatchRequest{ Name: &name, } diff --git a/test/mocked/util/sensor.go b/test/mocked/util/sensor.go index 05b4375b..6c54a0ea 100644 --- a/test/mocked/util/sensor.go +++ b/test/mocked/util/sensor.go @@ -38,6 +38,7 @@ func GenerateSensorResponse(id string, postfix string) config_api_client.Sensors func GenerateSensorPatchRequest(postfix string) config_api_client.SensorsPatchRequest { pcapMode, _ := config_api_client.NewPcapModeFromValue("light") + return config_api_client.SensorsPatchRequest{ Name: config_api_client.PtrString("name" + postfix), AddressNote: config_api_client.PtrString("address_note" + postfix), @@ -48,6 +49,7 @@ func GenerateSensorPatchRequest(postfix string) config_api_client.SensorsPatchRe func GenerateSensorPatchResponse(id string, postfix string) config_api_client.SensorsPatchResponse { pcapMode, _ := config_api_client.NewPcapModeFromValue("light") + return config_api_client.SensorsPatchResponse{ Id: id, Serial: "serial" + postfix, diff --git a/test/mocked/util/wired_network.go b/test/mocked/util/wired_network.go index dafa7795..fb61fbb7 100644 --- a/test/mocked/util/wired_network.go +++ b/test/mocked/util/wired_network.go @@ -20,6 +20,7 @@ func GenerateWiredNetworkResponse( ) config_api_client.WiredNetworksResponse { createdAt, _ := time.Parse(time.RFC3339, "2024-09-11T12:00:00.000Z") updatedAt, _ := time.Parse(time.RFC3339, "2024-09-11T12:00:00.000Z") + return config_api_client.WiredNetworksResponse{ Items: []config_api_client.WiredNetworksItem{ { diff --git a/test/mocked/util/wireless_network.go b/test/mocked/util/wireless_network.go index 79665221..a4a2cd82 100644 --- a/test/mocked/util/wireless_network.go +++ b/test/mocked/util/wireless_network.go @@ -20,6 +20,7 @@ func GenerateWirelessNetworkResponse( ) config_api_client.WirelessNetworksResponse { createdAt, _ := time.Parse(time.RFC3339, "2024-09-11T12:00:00.000Z") updatedAt, _ := time.Parse(time.RFC3339, "2024-09-11T12:00:00.000Z") + return config_api_client.WirelessNetworksResponse{ Items: []config_api_client.WirelessNetworksItem{ { diff --git a/test/shared/agent.go b/test/shared/agent.go index be255506..dcb68167 100644 --- a/test/shared/agent.go +++ b/test/shared/agent.go @@ -27,6 +27,7 @@ func CheckStateAgainstAgent( "name", func(value string) error { assert.Equal(t, value, agent.Name) + return nil }, ), diff --git a/test/shared/sensor.go b/test/shared/sensor.go index 4b877700..9205d8b7 100644 --- a/test/shared/sensor.go +++ b/test/shared/sensor.go @@ -27,6 +27,7 @@ func CheckStateAgainstSensor( "name", func(value string) error { assert.Equal(t, value, sensor.Name) + return nil }, ), diff --git a/test/shared/shared.go b/test/shared/shared.go index debb6e73..1a575417 100644 --- a/test/shared/shared.go +++ b/test/shared/shared.go @@ -71,6 +71,7 @@ func TestOptionalFloatValue( if have != want { return fmt.Errorf("have `%f`; but want `%f`", have, want) } + return nil }, ) @@ -78,6 +79,7 @@ func TestOptionalFloatValue( func stringToFloat64(s string) float64 { val, _ := strconv.ParseFloat(s, 32) + return float64(val) } @@ -86,5 +88,6 @@ func Int32PtrToStringPtr(value *int32) *string { return nil } result := strconv.Itoa(int(*value)) + return &result } diff --git a/test/shared/wired_network.go b/test/shared/wired_network.go index 5d305f33..3422c98b 100644 --- a/test/shared/wired_network.go +++ b/test/shared/wired_network.go @@ -26,6 +26,7 @@ func CheckStateAgainstWiredNetwork( "name", func(value string) error { assert.Equal(t, value, wiredNetwork.Name) + return nil }, ), diff --git a/test/shared/wireless_network.go b/test/shared/wireless_network.go index e9f0fa2e..b58c36a0 100644 --- a/test/shared/wireless_network.go +++ b/test/shared/wireless_network.go @@ -27,6 +27,7 @@ func CheckStateAgainstWirelessNetwork( "name", func(value string) error { assert.Equal(t, value, wirelessNetwork.Name) + return nil }, ),