diff --git a/Justfile b/Justfile index 9ebb59a7..72b57eb6 100644 --- a/Justfile +++ b/Justfile @@ -23,7 +23,7 @@ generate-config-api-client: retrieve-config-api-openapi-spec --output /local/{{ CONFIG_API_CLIENT_DIR }} \ --package-name config_api_client \ --git-user-id aruba-uxi \ - --git-repo-id terraform-provider-configuration-api/{{ CONFIG_API_CLIENT_DIR }} \ + --git-repo-id terraform-provider-hpeuxi/{{ CONFIG_API_CLIENT_DIR }} \ --openapi-normalizer SET_TAGS_FOR_ALL_OPERATIONS=configuration just tidy-client just fmt-client diff --git a/README.md b/README.md index 0aa58393..9fe3d7c3 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ go_path = $(go env GOPATH)/bin ``` dev_overrides { - "registry.terraform.io/arubauxi/configuration" = "" + "registry.terraform.io/arubauxi/hpeuxi" = "" } ``` @@ -17,7 +17,7 @@ Example `~/.terraformrc` file ``` provider_installation { dev_overrides { - "registry.terraform.io/arubauxi/configuration" = "/Users//go/bin" + "registry.terraform.io/arubauxi/hpeuxi" = "/Users//go/bin" } direct {} } diff --git a/docs/data-sources/agent.md b/docs/data-sources/agent.md index 0191f678..1ce0a536 100644 --- a/docs/data-sources/agent.md +++ b/docs/data-sources/agent.md @@ -21,11 +21,8 @@ description: |- ### Read-Only -- `address_note` (String) - `ethernet_mac_address` (String) - `id` (String) The ID of this resource. -- `latitude` (Number) -- `longitude` (Number) - `model_number` (String) - `name` (String) - `notes` (String) diff --git a/docs/data-sources/service_test.md b/docs/data-sources/service_test.md index 70d64f9e..f0153957 100644 --- a/docs/data-sources/service_test.md +++ b/docs/data-sources/service_test.md @@ -23,7 +23,7 @@ description: |- - `category` (String) - `id` (String) The ID of this resource. -- `is_enabled` (String) +- `is_enabled` (Boolean) - `name` (String) - `target` (String) - `template` (String) diff --git a/examples/full-demo/main.tf b/examples/full-demo/main.tf index 565da15c..cb16a366 100644 --- a/examples/full-demo/main.tf +++ b/examples/full-demo/main.tf @@ -1,7 +1,7 @@ terraform { required_providers { uxi = { - source = "registry.terraform.io/arubauxi/configuration" + source = "registry.terraform.io/arubauxi/hpeuxi" } } } diff --git a/go.mod b/go.mod index 56484332..55cfe9ef 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,11 @@ -module github.com/aruba-uxi/terraform-provider-configuration +module github.com/aruba-uxi/terraform-provider-hpeuxi go 1.21 toolchain go1.22.5 require ( - github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client v0.0.0-00010101000000-000000000000 + github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client v0.0.0-00010101000000-000000000000 github.com/h2non/gock v1.2.0 github.com/hashicorp/terraform-plugin-framework v1.10.0 github.com/hashicorp/terraform-plugin-go v0.23.0 @@ -22,6 +22,7 @@ require ( github.com/fatih/color v1.16.0 // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/google/go-cmp v0.6.0 // indirect + github.com/google/uuid v1.6.0 // indirect github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect github.com/hashicorp/errwrap v1.0.0 // indirect github.com/hashicorp/go-checkpoint v0.5.0 // indirect @@ -68,4 +69,4 @@ require ( google.golang.org/protobuf v1.34.0 // indirect ) -replace github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client => ./pkg/config-api-client +replace github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client => ./pkg/config-api-client diff --git a/go.sum b/go.sum index a81f86dd..4d0d3d02 100644 --- a/go.sum +++ b/go.sum @@ -42,6 +42,8 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/h2non/gock v1.2.0 h1:K6ol8rfrRkUOefooBC8elXoaNGYkpp7y2qcxGG6BzUE= github.com/h2non/gock v1.2.0/go.mod h1:tNhoxHYW2W42cYkYb1WqzdbYIieALC99kpYr7rH/BQk= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw= diff --git a/internal/provider/config/config.go b/internal/provider/config/config.go index e2f140c9..23c843d0 100644 --- a/internal/provider/config/config.go +++ b/internal/provider/config/config.go @@ -1,5 +1,5 @@ package config const ( - MaxRetriesFor429 = 10 + MaxRetriesForTooManyRequests = 10 ) diff --git a/internal/provider/datasources/agent.go b/internal/provider/datasources/agent.go index 04784ba0..b925e0e1 100644 --- a/internal/provider/datasources/agent.go +++ b/internal/provider/datasources/agent.go @@ -3,8 +3,8 @@ package datasources import ( "context" - config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/util" + config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" @@ -24,17 +24,14 @@ type agentDataSource struct { } type agentDataSourceModel struct { - Id types.String `tfsdk:"id"` - Serial types.String `tfsdk:"serial"` - Name types.String `tfsdk:"name"` - ModelNumber types.String `tfsdk:"model_number"` - WifiMacAddress types.String `tfsdk:"wifi_mac_address"` - EthernetMacAddress types.String `tfsdk:"ethernet_mac_address"` - AddressNote types.String `tfsdk:"address_note"` - Longitude types.Float32 `tfsdk:"longitude"` - Latitude types.Float32 `tfsdk:"latitude"` - Notes types.String `tfsdk:"notes"` - PcapMode types.String `tfsdk:"pcap_mode"` + Id types.String `tfsdk:"id"` + Serial types.String `tfsdk:"serial"` + Name types.String `tfsdk:"name"` + ModelNumber types.String `tfsdk:"model_number"` + WifiMacAddress types.String `tfsdk:"wifi_mac_address"` + EthernetMacAddress types.String `tfsdk:"ethernet_mac_address"` + Notes types.String `tfsdk:"notes"` + PcapMode types.String `tfsdk:"pcap_mode"` Filter struct { AgentID types.String `tfsdk:"agent_id"` } `tfsdk:"filter"` @@ -73,15 +70,6 @@ func (d *agentDataSource) Schema( "ethernet_mac_address": schema.StringAttribute{ Computed: true, }, - "address_note": schema.StringAttribute{ - Computed: true, - }, - "longitude": schema.Float32Attribute{ - Computed: true, - }, - "latitude": schema.Float32Attribute{ - Computed: true, - }, "notes": schema.StringAttribute{ Computed: true, }, @@ -118,7 +106,7 @@ func (d *agentDataSource) Read( AgentsGet(ctx). Id(state.Filter.AgentID.ValueString()) - agentResponse, response, err := util.RetryFor429(request.Execute) + agentResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) errorSummary := util.GenerateErrorSummary("read", "uxi_agent") @@ -137,6 +125,7 @@ func (d *agentDataSource) Read( state.Id = types.StringValue(agent.Id) state.Name = types.StringValue(agent.Name) + state.Serial = types.StringValue(agent.Serial) state.ModelNumber = types.StringPointerValue(agent.ModelNumber.Get()) state.WifiMacAddress = types.StringPointerValue(agent.WifiMacAddress.Get()) state.EthernetMacAddress = types.StringPointerValue(agent.EthernetMacAddress.Get()) diff --git a/internal/provider/datasources/agent_group_assignment.go b/internal/provider/datasources/agent_group_assignment.go index 32f7de49..7c457763 100644 --- a/internal/provider/datasources/agent_group_assignment.go +++ b/internal/provider/datasources/agent_group_assignment.go @@ -3,8 +3,8 @@ package datasources import ( "context" - config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/util" + config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" @@ -84,7 +84,7 @@ func (d *agentGroupAssignmentDataSource) Read( request := d.client.ConfigurationAPI. AgentGroupAssignmentsGet(ctx). Id(state.Filter.AgentGroupAssignmentID) - agentGroupAssignmentResponse, response, err := util.RetryFor429(request.Execute) + agentGroupAssignmentResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) errorSummary := util.GenerateErrorSummary("read", "uxi_agent_group_assignment") diff --git a/internal/provider/datasources/group.go b/internal/provider/datasources/group.go index 5030d44f..3e0f3763 100644 --- a/internal/provider/datasources/group.go +++ b/internal/provider/datasources/group.go @@ -3,8 +3,8 @@ package datasources import ( "context" - config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/util" + config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" @@ -90,7 +90,7 @@ func (d *groupDataSource) Read( GroupsGet(ctx). Id(*state.Filter.GroupID) - groupResponse, response, err := util.RetryFor429(request.Execute) + groupResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) errorSummary := util.GenerateErrorSummary("read", "uxi_group") diff --git a/internal/provider/datasources/network_group_assignment.go b/internal/provider/datasources/network_group_assignment.go index 3ed0fdf3..3793a544 100644 --- a/internal/provider/datasources/network_group_assignment.go +++ b/internal/provider/datasources/network_group_assignment.go @@ -3,8 +3,8 @@ package datasources import ( "context" - config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/util" + config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" @@ -84,7 +84,7 @@ func (d *networkGroupAssignmentDataSource) Read( request := d.client.ConfigurationAPI. NetworkGroupAssignmentsGet(ctx). Id(state.Filter.NetworkGroupAssignmentID) - networkGroupAssignmentResponse, response, err := util.RetryFor429(request.Execute) + networkGroupAssignmentResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) errorSummary := util.GenerateErrorSummary("read", "uxi_network_group_assignment") diff --git a/internal/provider/datasources/sensor.go b/internal/provider/datasources/sensor.go index b1437fa4..0448e901 100644 --- a/internal/provider/datasources/sensor.go +++ b/internal/provider/datasources/sensor.go @@ -3,8 +3,8 @@ package datasources import ( "context" - config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/util" + config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" @@ -118,7 +118,7 @@ func (d *sensorDataSource) Read( SensorsGet(ctx). Id(state.Filter.SensorID.ValueString()) - sensorResponse, response, err := util.RetryFor429(request.Execute) + sensorResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) errorSummary := util.GenerateErrorSummary("read", "uxi_sensor") @@ -137,12 +137,13 @@ func (d *sensorDataSource) Read( state.Id = types.StringValue(sensor.Id) state.Name = types.StringValue(sensor.Name) + state.Serial = types.StringValue(sensor.Serial) state.ModelNumber = types.StringValue(sensor.ModelNumber) state.WifiMacAddress = types.StringPointerValue(sensor.WifiMacAddress.Get()) state.EthernetMacAddress = types.StringPointerValue(sensor.EthernetMacAddress.Get()) state.AddressNote = types.StringPointerValue(sensor.AddressNote.Get()) - state.Longitude = types.Float32PointerValue(sensor.Longitude.Get()) state.Latitude = types.Float32PointerValue(sensor.Latitude.Get()) + state.Longitude = types.Float32PointerValue(sensor.Longitude.Get()) state.Notes = types.StringPointerValue(sensor.Notes.Get()) state.PcapMode = types.StringPointerValue(sensor.PcapMode.Get()) diff --git a/internal/provider/datasources/sensor_group_assignment.go b/internal/provider/datasources/sensor_group_assignment.go index 493f3acd..5361cfca 100644 --- a/internal/provider/datasources/sensor_group_assignment.go +++ b/internal/provider/datasources/sensor_group_assignment.go @@ -3,8 +3,8 @@ package datasources import ( "context" - config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/util" + config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" @@ -86,7 +86,7 @@ func (d *sensorGroupAssignmentDataSource) Read( request := d.client.ConfigurationAPI. SensorGroupAssignmentsGet(ctx). Id(state.Filter.SensorGroupAssignmentID) - sensorGroupAssignmentResponse, response, err := util.RetryFor429(request.Execute) + sensorGroupAssignmentResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) errorSummary := util.GenerateErrorSummary("create", "uxi_sensor_group_assignment") diff --git a/internal/provider/datasources/service.go b/internal/provider/datasources/service.go index 14a9afa8..4fce7d56 100644 --- a/internal/provider/datasources/service.go +++ b/internal/provider/datasources/service.go @@ -3,8 +3,8 @@ package datasources import ( "context" - config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/util" + config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" @@ -29,7 +29,7 @@ type serviceTestDataSourceModel struct { Name types.String `tfsdk:"name"` Target types.String `tfsdk:"target"` Template types.String `tfsdk:"template"` - IsEnabled types.String `tfsdk:"is_enabled"` + IsEnabled types.Bool `tfsdk:"is_enabled"` Filter struct { ServiceTestID types.String `tfsdk:"service_test_id"` } `tfsdk:"filter"` @@ -65,7 +65,7 @@ func (d *serviceTestDataSource) Schema( "template": schema.StringAttribute{ Computed: true, }, - "is_enabled": schema.StringAttribute{ + "is_enabled": schema.BoolAttribute{ Computed: true, }, "filter": schema.SingleNestedAttribute{ @@ -98,7 +98,7 @@ func (d *serviceTestDataSource) Read( ServiceTestsGet(ctx). Id(state.Filter.ServiceTestID.ValueString()) - serviceTestResponse, response, err := util.RetryFor429(request.Execute) + serviceTestResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) errorSummary := util.GenerateErrorSummary("read", "uxi_service_test") @@ -116,7 +116,11 @@ func (d *serviceTestDataSource) Read( serviceTest := serviceTestResponse.Items[0] state.Id = types.StringValue(serviceTest.Id) + state.Category = types.StringValue(serviceTest.Category) state.Name = types.StringValue(serviceTest.Name) + state.Target = types.StringPointerValue(serviceTest.Target.Get()) + state.Template = types.StringValue(serviceTest.Template) + state.IsEnabled = types.BoolValue(serviceTest.IsEnabled) // Set state diags = resp.State.Set(ctx, &state) diff --git a/internal/provider/datasources/service_test_group_assignment.go b/internal/provider/datasources/service_test_group_assignment.go index 098596f4..42906656 100644 --- a/internal/provider/datasources/service_test_group_assignment.go +++ b/internal/provider/datasources/service_test_group_assignment.go @@ -3,8 +3,8 @@ package datasources import ( "context" - config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/util" + config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" @@ -84,7 +84,9 @@ func (d *serviceTestGroupAssignmentDataSource) Read( request := d.client.ConfigurationAPI. ServiceTestGroupAssignmentsGet(ctx). Id(state.Filter.ServiceTestGroupAssignmentID) - serviceTestGroupAssignmentResponse, response, err := util.RetryFor429(request.Execute) + serviceTestGroupAssignmentResponse, response, err := util.RetryForTooManyRequests( + request.Execute, + ) errorPresent, errorDetail := util.RaiseForStatus(response, err) errorSummary := util.GenerateErrorSummary("read", "uxi_service_test_group_assignment") diff --git a/internal/provider/datasources/wired_network.go b/internal/provider/datasources/wired_network.go index 94dd3a1a..b9b5b994 100644 --- a/internal/provider/datasources/wired_network.go +++ b/internal/provider/datasources/wired_network.go @@ -3,8 +3,8 @@ package datasources import ( "context" - config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/util" + config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" @@ -33,7 +33,7 @@ type wiredNetworkDataSourceModel struct { DisableEdns types.Bool `tfsdk:"disable_edns"` UseDns64 types.Bool `tfsdk:"use_dns64"` ExternalConnectivity types.Bool `tfsdk:"external_connectivity"` - VlanId types.Int64 `tfsdk:"vlan_id"` + VlanId types.Int32 `tfsdk:"vlan_id"` Filter struct { WiredNetworkID string `tfsdk:"wired_network_id"` @@ -79,7 +79,7 @@ func (d *wiredNetworkDataSource) Schema( "external_connectivity": schema.BoolAttribute{ Computed: true, }, - "vlan_id": schema.Int64Attribute{ + "vlan_id": schema.Int32Attribute{ Computed: true, }, "filter": schema.SingleNestedAttribute{ @@ -111,7 +111,7 @@ func (d *wiredNetworkDataSource) Read( request := d.client.ConfigurationAPI. WiredNetworksGet(ctx). Id(state.Filter.WiredNetworkID) - networkResponse, response, err := util.RetryFor429(request.Execute) + networkResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) errorSummary := util.GenerateErrorSummary("read", "uxi_wired_network") @@ -130,12 +130,12 @@ func (d *wiredNetworkDataSource) Read( state.ID = types.StringValue(network.Id) state.Name = types.StringValue(network.Name) state.IpVersion = types.StringValue(network.IpVersion) - state.Security = types.StringValue(*network.Security.Get()) - state.DnsLookupDomain = types.StringValue(*network.DnsLookupDomain.Get()) + state.Security = types.StringPointerValue(network.Security.Get()) + state.DnsLookupDomain = types.StringPointerValue(network.DnsLookupDomain.Get()) state.DisableEdns = types.BoolValue(network.DisableEdns) state.UseDns64 = types.BoolValue(network.UseDns64) state.ExternalConnectivity = types.BoolValue(network.ExternalConnectivity) - state.VlanId = types.Int64Value(int64(*network.VLanId.Get())) + state.VlanId = types.Int32PointerValue(network.VLanId.Get()) // Set state diags = resp.State.Set(ctx, &state) diff --git a/internal/provider/datasources/wireless_network.go b/internal/provider/datasources/wireless_network.go index d8f03c32..f8c8a203 100644 --- a/internal/provider/datasources/wireless_network.go +++ b/internal/provider/datasources/wireless_network.go @@ -3,8 +3,8 @@ package datasources import ( "context" - config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/util" + config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" @@ -119,7 +119,7 @@ func (d *wirelessNetworkDataSource) Read( request := d.client.ConfigurationAPI. WirelessNetworksGet(ctx). Id(state.Filter.WirelessNetworkID) - networkResponse, response, err := util.RetryFor429(request.Execute) + networkResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) errorSummary := util.GenerateErrorSummary("read", "uxi_wireless_network") @@ -139,10 +139,10 @@ func (d *wirelessNetworkDataSource) Read( state.Ssid = types.StringValue(network.Ssid) state.Name = types.StringValue(network.Name) state.IpVersion = types.StringValue(network.IpVersion) - state.Security = types.StringValue(*network.Security.Get()) + state.Security = types.StringPointerValue(network.Security.Get()) state.Hidden = types.BoolValue(network.Hidden) state.BandLocking = types.StringValue(network.BandLocking) - state.DnsLookupDomain = types.StringValue(*network.DnsLookupDomain.Get()) + state.DnsLookupDomain = types.StringPointerValue(network.DnsLookupDomain.Get()) state.DisableEdns = types.BoolValue(network.DisableEdns) state.UseDns64 = types.BoolValue(network.UseDns64) state.ExternalConnectivity = types.BoolValue(network.ExternalConnectivity) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index e7043150..0e3419aa 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -4,15 +4,15 @@ import ( "context" "os" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/datasources" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/resources" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/datasources" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/resources" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/provider/schema" "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" "github.com/hashicorp/terraform-plugin-framework/types" "net/http" diff --git a/internal/provider/resources/agent.go b/internal/provider/resources/agent.go index fb7284fd..0a345c16 100644 --- a/internal/provider/resources/agent.go +++ b/internal/provider/resources/agent.go @@ -3,8 +3,8 @@ package resources import ( "context" - "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -27,25 +27,6 @@ type agentResourceModel struct { PCapMode types.String `tfsdk:"pcap_mode"` } -// TODO: Switch this to use the Client Model when that becomes available -type AgentResponseModel struct { - UID string - Serial string - Name string - ModelNumber string - WifiMacAddress string - EthernetMacAddress string - Notes string - PCapMode string -} - -// TODO: Switch this to use the Client Model when that becomes available -type AgentUpdateRequestModel struct { - Name string - Notes string - PCapMode string -} - func NewAgentResource() resource.Resource { return &agentResource{} } @@ -80,9 +61,11 @@ func (r *agentResource) Schema( }, "notes": schema.StringAttribute{ Optional: true, + Computed: true, }, "pcap_mode": schema.StringAttribute{ Optional: true, + Computed: true, }, }, } @@ -142,7 +125,7 @@ func (r *agentResource) Read( request := r.client.ConfigurationAPI. AgentsGet(ctx). Id(state.ID.ValueString()) - sensorResponse, response, err := util.RetryFor429(request.Execute) + agentResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) errorSummary := util.GenerateErrorSummary("read", "uxi_agent") @@ -152,16 +135,16 @@ func (r *agentResource) Read( return } - if len(sensorResponse.Items) != 1 { + if len(agentResponse.Items) != 1 { resp.State.RemoveResource(ctx) return } - sensor := sensorResponse.Items[0] + agent := agentResponse.Items[0] - state.ID = types.StringValue(sensor.Id) - state.Name = types.StringValue(sensor.Name) - state.Notes = types.StringPointerValue(sensor.Notes.Get()) - state.PCapMode = types.StringPointerValue(sensor.PcapMode.Get()) + state.ID = types.StringValue(agent.Id) + state.Name = types.StringValue(agent.Name) + state.Notes = types.StringPointerValue(agent.Notes.Get()) + state.PCapMode = types.StringPointerValue(agent.PcapMode.Get()) diags = resp.State.Set(ctx, &state) resp.Diagnostics.Append(diags...) @@ -183,18 +166,35 @@ func (r *agentResource) Update( return } - // Update existing item - response := UpdateAgent(AgentUpdateRequestModel{ - Name: plan.Name.ValueString(), - Notes: plan.Notes.ValueString(), - PCapMode: plan.PCapMode.ValueString(), - }) + patchRequest := config_api_client.NewAgentsPatchRequest() + patchRequest.Name = plan.Name.ValueStringPointer() + if !plan.Notes.IsUnknown() { + patchRequest.Notes = plan.Notes.ValueStringPointer() + } + if !plan.PCapMode.IsUnknown() { + patchRequest.PcapMode = plan.PCapMode.ValueStringPointer() + } + request := r.client.ConfigurationAPI. + AgentsPatch(ctx, plan.ID.ValueString()). + AgentsPatchRequest(*patchRequest) + agent, response, err := util.RetryForTooManyRequests(request.Execute) - // Update resource state with updated items - plan.ID = types.StringValue(response.UID) - plan.Name = types.StringValue(response.Name) - plan.Notes = types.StringValue(response.Notes) - plan.PCapMode = types.StringValue(response.PCapMode) + errorPresent, errorDetail := util.RaiseForStatus(response, err) + + if errorPresent { + resp.Diagnostics.AddError(util.GenerateErrorSummary("update", "uxi_agent"), errorDetail) + return + } + + // Update the state to match the plan (replace with response from client) + plan.ID = types.StringValue(agent.Id) + plan.Name = types.StringValue(agent.Name) + if agent.Notes.Get() != nil { + plan.Notes = types.StringValue(*agent.Notes.Get()) + } + if agent.PcapMode.Get() != nil { + plan.PCapMode = types.StringValue(*agent.PcapMode.Get()) + } // Set state to fully populated data diags = resp.State.Set(ctx, plan) @@ -219,7 +219,7 @@ func (r *agentResource) Delete( request := r.client.ConfigurationAPI.AgentsDelete(ctx, state.ID.ValueString()) - _, response, err := util.RetryFor429(request.Execute) + _, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) if errorPresent { @@ -235,19 +235,3 @@ func (r *agentResource) ImportState( ) { resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) } - -// Update the agent using the configuration-api client -var UpdateAgent = func(request AgentUpdateRequestModel) AgentResponseModel { - // TODO: Query the agent using the client - - return AgentResponseModel{ - UID: "mock_uid", - Serial: "mock_serial", - Name: request.Name, - ModelNumber: "mock_model_number", - WifiMacAddress: "mock_wifi_mac_address", - EthernetMacAddress: "mock_ethernet_mac_address", - Notes: request.Notes, - PCapMode: request.PCapMode, - } -} diff --git a/internal/provider/resources/agent_group_assignment.go b/internal/provider/resources/agent_group_assignment.go index 18357c69..c2f125af 100644 --- a/internal/provider/resources/agent_group_assignment.go +++ b/internal/provider/resources/agent_group_assignment.go @@ -2,8 +2,8 @@ package resources import ( "context" - "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -13,7 +13,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" ) -// Ensure the implementation satisfies the expected interfaces. var ( _ resource.Resource = &agentGroupAssignmentResource{} _ resource.ResourceWithConfigure = &agentGroupAssignmentResource{} @@ -25,12 +24,6 @@ type agentGroupAssignmentResourceModel struct { GroupID types.String `tfsdk:"group_id"` } -type AgentGroupAssignmentResponseModel struct { - UID string // - GroupUID string // , - AgentUID string // -} - func NewAgentGroupAssignmentResource() resource.Resource { return &agentGroupAssignmentResource{} } @@ -103,7 +96,6 @@ func (r *agentGroupAssignmentResource) Create( req resource.CreateRequest, resp *resource.CreateResponse, ) { - // Retrieve values from plan var plan agentGroupAssignmentResourceModel diags := req.Plan.Get(ctx, &plan) resp.Diagnostics.Append(diags...) @@ -118,7 +110,7 @@ func (r *agentGroupAssignmentResource) Create( request := r.client.ConfigurationAPI. AgentGroupAssignmentsPost(ctx). AgentGroupAssignmentsPostRequest(*postRequest) - agentGroupAssignment, response, err := util.RetryFor429(request.Execute) + agentGroupAssignment, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) if errorPresent { @@ -129,12 +121,10 @@ func (r *agentGroupAssignmentResource) Create( return } - // Update the state to match the plan plan.ID = types.StringValue(agentGroupAssignment.Id) plan.GroupID = types.StringValue(agentGroupAssignment.Group.Id) plan.AgentID = types.StringValue(agentGroupAssignment.Agent.Id) - // Set state to fully populated data diags = resp.State.Set(ctx, plan) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -147,7 +137,6 @@ func (r *agentGroupAssignmentResource) Read( req resource.ReadRequest, resp *resource.ReadResponse, ) { - // Get current state var state agentGroupAssignmentResourceModel diags := req.State.Get(ctx, &state) resp.Diagnostics.Append(diags...) @@ -158,7 +147,7 @@ func (r *agentGroupAssignmentResource) Read( request := r.client.ConfigurationAPI. AgentGroupAssignmentsGet(ctx). Id(state.ID.ValueString()) - agentGroupAssignmentResponse, response, err := util.RetryFor429(request.Execute) + agentGroupAssignmentResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) errorSummary := util.GenerateErrorSummary("read", "uxi_agent_group_assignment") @@ -174,12 +163,10 @@ func (r *agentGroupAssignmentResource) Read( } agentGroupAssignment := agentGroupAssignmentResponse.Items[0] - // Update state from client response state.ID = types.StringValue(agentGroupAssignment.Id) state.GroupID = types.StringValue(agentGroupAssignment.Group.Id) state.AgentID = types.StringValue(agentGroupAssignment.Agent.Id) - // Set refreshed state diags = resp.State.Set(ctx, &state) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -192,7 +179,6 @@ func (r *agentGroupAssignmentResource) Update( req resource.UpdateRequest, resp *resource.UpdateResponse, ) { - // Retrieve values from plan var plan agentGroupAssignmentResourceModel diags := req.Plan.Get(ctx, &plan) diags.AddError("operation not supported", "updating an agent group assignment is not supported") @@ -207,7 +193,6 @@ func (r *agentGroupAssignmentResource) Delete( req resource.DeleteRequest, resp *resource.DeleteResponse, ) { - // Retrieve values from state var state agentGroupAssignmentResourceModel diags := req.State.Get(ctx, &state) resp.Diagnostics.Append(diags...) @@ -215,7 +200,18 @@ func (r *agentGroupAssignmentResource) Delete( return } - // Delete existing agentGroupAssignment using the plan_id + request := r.client.ConfigurationAPI. + AgentGroupAssignmentDelete(ctx, state.ID.ValueString()) + _, response, err := util.RetryForTooManyRequests(request.Execute) + errorPresent, errorDetail := util.RaiseForStatus(response, err) + + if errorPresent { + resp.Diagnostics.AddError( + util.GenerateErrorSummary("delete", "uxi_agent_group_assignment"), + errorDetail, + ) + return + } } func (r *agentGroupAssignmentResource) ImportState( diff --git a/internal/provider/resources/group.go b/internal/provider/resources/group.go index 2f931992..0f955aec 100644 --- a/internal/provider/resources/group.go +++ b/internal/provider/resources/group.go @@ -3,8 +3,8 @@ package resources import ( "context" - "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -115,7 +115,7 @@ func (r *groupResource) Create( request := r.client.ConfigurationAPI. GroupsPost(ctx). GroupsPostRequest(*groups_post_request) - group, response, err := util.RetryFor429(request.Execute) + group, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) if errorPresent { @@ -207,7 +207,7 @@ func (r *groupResource) Update( request := r.client.ConfigurationAPI. GroupsPatch(ctx, plan.ID.ValueString()). GroupsPatchRequest(*patchRequest) - group, response, err := util.RetryFor429(request.Execute) + group, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) @@ -249,7 +249,7 @@ func (r *groupResource) Delete( // Delete existing group using the plan_id request := r.client.ConfigurationAPI.GroupsDelete(ctx, state.ID.ValueString()) - _, response, err := util.RetryFor429(request.Execute) + _, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) if errorPresent { @@ -271,7 +271,7 @@ func (r *groupResource) getGroup( id string, ) (*config_api_client.GroupsGetItem, *string) { request := r.client.ConfigurationAPI.GroupsGet(ctx).Id(id) - groupResponse, response, err := util.RetryFor429(request.Execute) + groupResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) if errorPresent { diff --git a/internal/provider/resources/network_group_assignment.go b/internal/provider/resources/network_group_assignment.go index 5b35c0cb..096a544c 100644 --- a/internal/provider/resources/network_group_assignment.go +++ b/internal/provider/resources/network_group_assignment.go @@ -2,8 +2,8 @@ package resources import ( "context" - "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -112,7 +112,7 @@ func (r *networkGroupAssignmentResource) Create( request := r.client.ConfigurationAPI. NetworkGroupAssignmentsPost(ctx). NetworkGroupAssignmentsPostRequest(*postRequest) - networkGroupAssignment, response, err := util.RetryFor429(request.Execute) + networkGroupAssignment, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) if errorPresent { @@ -152,7 +152,7 @@ func (r *networkGroupAssignmentResource) Read( request := r.client.ConfigurationAPI. NetworkGroupAssignmentsGet(ctx). Id(state.ID.ValueString()) - networkGroupAssignmentResponse, response, err := util.RetryFor429(request.Execute) + networkGroupAssignmentResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) errorSummary := util.GenerateErrorSummary("read", "uxi_network_group_assignment") @@ -214,7 +214,7 @@ func (r *networkGroupAssignmentResource) Delete( request := r.client.ConfigurationAPI. NetworkGroupAssignmentsDelete(ctx, state.ID.ValueString()) - _, response, err := util.RetryFor429(request.Execute) + _, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) if errorPresent { diff --git a/internal/provider/resources/sensor.go b/internal/provider/resources/sensor.go index bc0a2a80..95077a86 100644 --- a/internal/provider/resources/sensor.go +++ b/internal/provider/resources/sensor.go @@ -2,8 +2,8 @@ package resources import ( "context" - "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -13,7 +13,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" ) -// Ensure the implementation satisfies the expected interfaces. var ( _ resource.Resource = &sensorResource{} _ resource.ResourceWithConfigure = &sensorResource{} @@ -27,29 +26,6 @@ type sensorResourceModel struct { PCapMode types.String `tfsdk:"pcap_mode"` } -// TODO: Switch this to use the Client Model when that becomes available -type SensorResponseModel struct { - UID string - Serial string - Name string - ModelNumber string - WifiMacAddress string - EthernetMacAddress string - AddressNote string - Longitude float32 - Latitude float32 - Notes string - PCapMode string -} - -// TODO: Switch this to use the Client Model when that becomes available -type SensorUpdateRequestModel struct { - Name string - AddressNote string - Notes string - PCapMode string -} - func NewSensorResource() resource.Resource { return &sensorResource{} } @@ -84,12 +60,18 @@ func (r *sensorResource) Schema( }, "address_note": schema.StringAttribute{ Optional: true, + // computed because goes from nil -> "" when sensor becomes configured + Computed: true, }, "notes": schema.StringAttribute{ Optional: true, + // computed because goes from from nil -> "" when sensor becomes configured + Computed: true, }, "pcap_mode": schema.StringAttribute{ Optional: true, + // computed because goes from from nil -> "light" when sensor becomes configured + Computed: true, }, }, } @@ -100,8 +82,6 @@ func (r *sensorResource) Configure( req resource.ConfigureRequest, resp *resource.ConfigureResponse, ) { - // Add a nil check when handling ProviderData because Terraform - // sets that data after it calls the ConfigureProvider RPC. if req.ProviderData == nil { return } @@ -124,7 +104,6 @@ func (r *sensorResource) Create( req resource.CreateRequest, resp *resource.CreateResponse, ) { - // Retrieve values from plan var plan sensorResourceModel diags := req.Plan.Get(ctx, &plan) diags.AddError( @@ -139,7 +118,6 @@ func (r *sensorResource) Read( req resource.ReadRequest, resp *resource.ReadResponse, ) { - // Get current state var state sensorResourceModel diags := req.State.Get(ctx, &state) resp.Diagnostics.Append(diags...) @@ -150,7 +128,7 @@ func (r *sensorResource) Read( request := r.client.ConfigurationAPI. SensorsGet(ctx). Id(state.ID.ValueString()) - sensorResponse, response, err := util.RetryFor429(request.Execute) + sensorResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) errorSummary := util.GenerateErrorSummary("read", "uxi_sensor") @@ -166,14 +144,12 @@ func (r *sensorResource) Read( } sensor := sensorResponse.Items[0] - // Update state from client response state.ID = types.StringValue(sensor.Id) state.Name = types.StringValue(sensor.Name) state.AddressNote = types.StringPointerValue(sensor.AddressNote.Get()) state.Notes = types.StringPointerValue(sensor.Notes.Get()) state.PCapMode = types.StringPointerValue(sensor.PcapMode.Get()) - // Set refreshed state diags = resp.State.Set(ctx, &state) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -186,7 +162,6 @@ func (r *sensorResource) Update( req resource.UpdateRequest, resp *resource.UpdateResponse, ) { - // Retrieve values from plan var plan sensorResourceModel diags := req.Plan.Get(ctx, &plan) resp.Diagnostics.Append(diags...) @@ -194,22 +169,30 @@ func (r *sensorResource) Update( return } - // Update existing item - response := UpdateSensor(SensorUpdateRequestModel{ - Name: plan.Name.ValueString(), - AddressNote: plan.AddressNote.ValueString(), - Notes: plan.Notes.ValueString(), - PCapMode: plan.PCapMode.ValueString(), - }) + patchRequest := config_api_client.NewSensorsPatchRequest() + patchRequest.Name = plan.Name.ValueStringPointer() + patchRequest.AddressNote = plan.AddressNote.ValueStringPointer() + patchRequest.Notes = plan.Notes.ValueStringPointer() + patchRequest.PcapMode = plan.PCapMode.ValueStringPointer() - // Update resource state with updated items - plan.ID = types.StringValue(response.UID) - plan.Name = types.StringValue(response.Name) - plan.AddressNote = types.StringValue(response.AddressNote) - plan.Notes = types.StringValue(response.Notes) - plan.PCapMode = types.StringValue(response.PCapMode) + request := r.client.ConfigurationAPI. + 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(util.GenerateErrorSummary("update", "uxi_sensor"), errorDetail) + return + } + + plan.ID = types.StringValue(sensor.Id) + plan.Name = types.StringValue(sensor.Name) + plan.AddressNote = types.StringPointerValue(sensor.AddressNote.Get()) + plan.Notes = types.StringPointerValue(sensor.Notes.Get()) + plan.PCapMode = types.StringPointerValue(sensor.PcapMode.Get()) - // Set state to fully populated data diags = resp.State.Set(ctx, plan) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -222,7 +205,6 @@ func (r *sensorResource) Delete( req resource.DeleteRequest, resp *resource.DeleteResponse, ) { - // Retrieve values from state var state sensorResourceModel diags := req.State.Get(ctx, &state) diags.AddError( @@ -239,22 +221,3 @@ func (r *sensorResource) ImportState( ) { resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) } - -// Update the sensor using the configuration-api client -var UpdateSensor = func(request SensorUpdateRequestModel) SensorResponseModel { - // TODO: Query the sensor using the client - - return SensorResponseModel{ - UID: "mock_uid", - Serial: "mock_serial", - Name: request.Name, - ModelNumber: "mock_model_number", - WifiMacAddress: "mock_wifi_mac_address", - EthernetMacAddress: "mock_ethernet_mac_address", - AddressNote: request.AddressNote, - Longitude: 0.0, - Latitude: 0.0, - Notes: request.Notes, - PCapMode: request.PCapMode, - } -} diff --git a/internal/provider/resources/sensor_group_assignment.go b/internal/provider/resources/sensor_group_assignment.go index 3db69c71..6b9db512 100644 --- a/internal/provider/resources/sensor_group_assignment.go +++ b/internal/provider/resources/sensor_group_assignment.go @@ -3,8 +3,8 @@ package resources import ( "context" - config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/util" + config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" @@ -25,11 +25,6 @@ type sensorGroupAssignmentResourceModel struct { GroupID types.String `tfsdk:"group_id"` } -type SensorGroupAssignmentRequestModel struct { - GroupUID string // , - SensorUID string // -} - func NewSensorGroupAssignmentResource() resource.Resource { return &sensorGroupAssignmentResource{} } @@ -120,7 +115,7 @@ func (r *sensorGroupAssignmentResource) Create( request := r.client.ConfigurationAPI. SensorGroupAssignmentsPost(ctx). SensorGroupAssignmentsPostRequest(*postRequest) - sensorGroupAssignment, response, err := util.RetryFor429(request.Execute) + sensorGroupAssignment, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) if errorPresent { @@ -158,7 +153,7 @@ func (r *sensorGroupAssignmentResource) Read( request := r.client.ConfigurationAPI. SensorGroupAssignmentsGet(ctx). Id(state.ID.ValueString()) - sensorGroupAssignmentResponse, response, err := util.RetryFor429(request.Execute) + sensorGroupAssignmentResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) errorSummary := util.GenerateErrorSummary("create", "uxi_sensor_group_assignment") @@ -219,7 +214,7 @@ func (r *sensorGroupAssignmentResource) Delete( // Delete existing sensorGroupAssignment using the plan_id request := r.client.ConfigurationAPI. SensorGroupAssignmentsDelete(ctx, state.ID.ValueString()) - _, response, err := util.RetryFor429(request.Execute) + _, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) if errorPresent { diff --git a/internal/provider/resources/service.go b/internal/provider/resources/service.go index 7da01377..de0f98f6 100644 --- a/internal/provider/resources/service.go +++ b/internal/provider/resources/service.go @@ -2,9 +2,9 @@ package resources import ( "context" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/util" - "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" @@ -115,7 +115,7 @@ func (r *serviceTestResource) Read( request := r.client.ConfigurationAPI. ServiceTestsGet(ctx). Id(state.ID.ValueString()) - sensorResponse, response, err := util.RetryFor429(request.Execute) + sensorResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) errorSummary := util.GenerateErrorSummary("read", "uxi_service_test") diff --git a/internal/provider/resources/service_group_assignment.go b/internal/provider/resources/service_group_assignment.go index 986ab27b..40c9354e 100644 --- a/internal/provider/resources/service_group_assignment.go +++ b/internal/provider/resources/service_group_assignment.go @@ -2,8 +2,8 @@ package resources import ( "context" - "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -112,7 +112,7 @@ func (r *serviceTestGroupAssignmentResource) Create( request := r.client.ConfigurationAPI. ServiceTestGroupAssignmentsPost(ctx). ServiceTestGroupAssignmentsPostRequest(*postRequest) - serviceTestGroupAssignment, response, err := util.RetryFor429(request.Execute) + serviceTestGroupAssignment, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) if errorPresent { @@ -152,7 +152,9 @@ func (r *serviceTestGroupAssignmentResource) Read( request := r.client.ConfigurationAPI. ServiceTestGroupAssignmentsGet(ctx). Id(state.ID.ValueString()) - serviceTestGroupAssignmentResponse, response, err := util.RetryFor429(request.Execute) + serviceTestGroupAssignmentResponse, response, err := util.RetryForTooManyRequests( + request.Execute, + ) errorPresent, errorDetail := util.RaiseForStatus(response, err) errorSummary := util.GenerateErrorSummary("read", "uxi_service_test_group_assignment") @@ -215,7 +217,7 @@ func (r *serviceTestGroupAssignmentResource) Delete( request := r.client.ConfigurationAPI. ServiceTestGroupAssignmentsDelete(ctx, state.ID.ValueString()) - _, response, err := util.RetryFor429(request.Execute) + _, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) if errorPresent { diff --git a/internal/provider/resources/wired_network.go b/internal/provider/resources/wired_network.go index ab43df3b..202b9cda 100644 --- a/internal/provider/resources/wired_network.go +++ b/internal/provider/resources/wired_network.go @@ -3,8 +3,8 @@ package resources import ( "context" - "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" @@ -115,7 +115,7 @@ func (r *wiredNetworkResource) Read( request := r.client.ConfigurationAPI. WiredNetworksGet(ctx). Id(state.ID.ValueString()) - networkResponse, response, err := util.RetryFor429(request.Execute) + networkResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) errorSummary := util.GenerateErrorSummary("read", "uxi_wired_network") diff --git a/internal/provider/resources/wireless_network.go b/internal/provider/resources/wireless_network.go index 572c0b49..e0ee8b8b 100644 --- a/internal/provider/resources/wireless_network.go +++ b/internal/provider/resources/wireless_network.go @@ -3,8 +3,8 @@ package resources import ( "context" - "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" @@ -115,7 +115,7 @@ func (r *wirelessNetworkResource) Read( request := r.client.ConfigurationAPI. WirelessNetworksGet(ctx). Id(state.ID.ValueString()) - networkResponse, response, err := util.RetryFor429(request.Execute) + networkResponse, response, err := util.RetryForTooManyRequests(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) errorSummary := util.GenerateErrorSummary("read", "uxi_wireless_network") diff --git a/internal/provider/util/error_handling.go b/internal/provider/util/error_handling.go index 543e8af0..85d84986 100644 --- a/internal/provider/util/error_handling.go +++ b/internal/provider/util/error_handling.go @@ -6,7 +6,7 @@ import ( "net/http" "net/url" - config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ) func GenerateErrorSummary(actionName string, entityName string) string { diff --git a/internal/provider/util/group.go b/internal/provider/util/group.go index ecb38e58..2d0a43f3 100644 --- a/internal/provider/util/group.go +++ b/internal/provider/util/group.go @@ -1,7 +1,7 @@ package util import ( - "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ) func IsRoot(group config_api_client.GroupsGetItem) bool { diff --git a/internal/provider/util/retry.go b/internal/provider/util/retry.go index 215a105f..b54a7fee 100644 --- a/internal/provider/util/retry.go +++ b/internal/provider/util/retry.go @@ -6,18 +6,20 @@ import ( "strconv" "time" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/config" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/config" ) -func RetryFor429[T any](f func() (T, *http.Response, error)) (T, *http.Response, error) { +func RetryForTooManyRequests[T any]( + f func() (T, *http.Response, error), +) (T, *http.Response, error) { var result T var err error var httpResponse *http.Response - for i := 0; i < config.MaxRetriesFor429; i++ { + for i := 0; i < config.MaxRetriesForTooManyRequests; i++ { result, httpResponse, err = f() - if httpResponse == nil || httpResponse.StatusCode != 429 { + if httpResponse == nil || httpResponse.StatusCode != http.StatusTooManyRequests { return result, httpResponse, err } diff --git a/main.go b/main.go index 31678c28..88369bf1 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,7 @@ import ( "flag" "log" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider" "github.com/hashicorp/terraform-plugin-framework/providerserver" ) @@ -28,7 +28,7 @@ func main() { flag.Parse() opts := providerserver.ServeOpts{ - Address: "registry.terraform.io/arubauxi/configuration", + Address: "registry.terraform.io/arubauxi/hpeuxi", Debug: debug, } diff --git a/pkg/config-api-client/.openapi-generator/FILES b/pkg/config-api-client/.openapi-generator/FILES index 53edefd3..7cb7dd7c 100644 --- a/pkg/config-api-client/.openapi-generator/FILES +++ b/pkg/config-api-client/.openapi-generator/FILES @@ -9,6 +9,8 @@ docs/AgentGroupAssignmentsItem.md docs/AgentGroupAssignmentsPostRequest.md docs/AgentGroupAssignmentsResponse.md docs/AgentItem.md +docs/AgentsPatchRequest.md +docs/AgentsPatchResponse.md docs/AgentsResponse.md docs/ConfigurationAPI.md docs/ErrorDetail.md @@ -56,6 +58,8 @@ model_agent_group_assignments_item.go model_agent_group_assignments_post_request.go model_agent_group_assignments_response.go model_agent_item.go +model_agents_patch_request.go +model_agents_patch_response.go model_agents_response.go model_error_detail.go model_error_response.go diff --git a/pkg/config-api-client/README.md b/pkg/config-api-client/README.md index a5f70cc6..448bcc59 100644 --- a/pkg/config-api-client/README.md +++ b/pkg/config-api-client/README.md @@ -5,7 +5,7 @@ Nice description goes here ## Overview This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI-spec](https://www.openapis.org/) from a remote server, you can easily generate an API client. -- API version: 5.6.0 +- API version: 5.10.0 - Package version: 1.0.0 - Generator version: 7.9.0-SNAPSHOT - Build package: org.openapitools.codegen.languages.GoClientCodegen @@ -23,7 +23,7 @@ go get golang.org/x/net/context Put the package under your project folder and add the following in import: ```go -import config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" +import config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ``` To use a proxy, set the environment variable `HTTP_PROXY`: @@ -79,10 +79,12 @@ All URIs are relative to *https://api.capenetworks.com* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- +*ConfigurationAPI* | [**AgentGroupAssignmentDelete**](docs/ConfigurationAPI.md#agentgroupassignmentdelete) | **Delete** /networking-uxi/v1alpha1/agent-group-assignments/{uid} | Agent Group Assignment Delete *ConfigurationAPI* | [**AgentGroupAssignmentsGet**](docs/ConfigurationAPI.md#agentgroupassignmentsget) | **Get** /networking-uxi/v1alpha1/agent-group-assignments | Agent Group Assignments Get *ConfigurationAPI* | [**AgentGroupAssignmentsPost**](docs/ConfigurationAPI.md#agentgroupassignmentspost) | **Post** /networking-uxi/v1alpha1/agent-group-assignments | Agent Group Assignments Post *ConfigurationAPI* | [**AgentsDelete**](docs/ConfigurationAPI.md#agentsdelete) | **Delete** /networking-uxi/v1alpha1/agents/{agent_uid} | Agents Delete *ConfigurationAPI* | [**AgentsGet**](docs/ConfigurationAPI.md#agentsget) | **Get** /networking-uxi/v1alpha1/agents | Agents Get +*ConfigurationAPI* | [**AgentsPatch**](docs/ConfigurationAPI.md#agentspatch) | **Patch** /networking-uxi/v1alpha1/agents/{agent_uid} | Agents Patch *ConfigurationAPI* | [**GroupsDelete**](docs/ConfigurationAPI.md#groupsdelete) | **Delete** /networking-uxi/v1alpha1/groups/{group_uid} | Groups Delete *ConfigurationAPI* | [**GroupsGet**](docs/ConfigurationAPI.md#groupsget) | **Get** /networking-uxi/v1alpha1/groups | Groups Get *ConfigurationAPI* | [**GroupsPatch**](docs/ConfigurationAPI.md#groupspatch) | **Patch** /networking-uxi/v1alpha1/groups/{group_uid} | Groups Patch @@ -111,6 +113,8 @@ Class | Method | HTTP request | Description - [AgentGroupAssignmentsPostRequest](docs/AgentGroupAssignmentsPostRequest.md) - [AgentGroupAssignmentsResponse](docs/AgentGroupAssignmentsResponse.md) - [AgentItem](docs/AgentItem.md) + - [AgentsPatchRequest](docs/AgentsPatchRequest.md) + - [AgentsPatchResponse](docs/AgentsPatchResponse.md) - [AgentsResponse](docs/AgentsResponse.md) - [ErrorDetail](docs/ErrorDetail.md) - [ErrorResponse](docs/ErrorResponse.md) diff --git a/pkg/config-api-client/api/.openapi.source.yaml b/pkg/config-api-client/api/.openapi.source.yaml index 0bd9391b..a87530b1 100644 --- a/pkg/config-api-client/api/.openapi.source.yaml +++ b/pkg/config-api-client/api/.openapi.source.yaml @@ -9,7 +9,7 @@ info: email: support@capenetworks.com license: name: No idea, but we need something - version: 5.6.0 + version: 5.10.0 servers: - url: https://api.capenetworks.com - url: https://api.staging.capedev.io @@ -109,6 +109,46 @@ paths: - v1alpha1 - agent-group-assignments x-stability-level: alpha + /networking-uxi/v1alpha1/agent-group-assignments/{uid}: + delete: + operationId: agent_group_assignment_delete + summary: Agent Group Assignment Delete + description: Delete an agent group assignment. + parameters: + - name: uid + in: path + required: true + schema: + type: string + title: Uid + responses: + '200': + description: Successful Response + content: + application/json: + schema: {} + '204': + description: No Content + 4XX: + description: Client Error + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + 5XX: + description: Server Error + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + security: + - HTTPBearer: [] + tags: + - api + - configuration + - v1alpha1 + - agent-group-assignments + x-stability-level: alpha /networking-uxi/v1alpha1/agents/{agent_uid}: delete: operationId: agents_delete @@ -146,8 +186,52 @@ paths: tags: - api - configuration - - v1 + - v1alpha1 - agents + patch: + operationId: agents_patch + summary: Agents Patch + description: Update an existing agent. + parameters: + - name: agent_uid + in: path + required: true + schema: + type: string + title: Agent Uid + requestBody: + required: true + content: + application/merge-patch+json: + schema: + $ref: '#/components/schemas/AgentsPatchRequest' + responses: + '200': + description: Successful Response + content: + application/json: + schema: + $ref: '#/components/schemas/AgentsPatchResponse' + 4XX: + description: Client Error + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + 5XX: + description: Server Error + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + security: + - HTTPBearer: [] + tags: + - api + - configuration + - v1alpha1 + - agents + x-stability-level: alpha /networking-uxi/v1alpha1/agents: get: operationId: agents_get @@ -243,8 +327,9 @@ paths: tags: - api - configuration - - v1 + - v1alpha1 - groups + x-stability-level: alpha patch: operationId: groups_patch summary: Groups Patch @@ -292,8 +377,9 @@ paths: tags: - api - configuration - - v1 + - v1alpha1 - groups + x-stability-level: alpha /networking-uxi/v1alpha1/groups: get: operationId: groups_get @@ -728,7 +814,7 @@ paths: requestBody: required: true content: - application/json: + application/merge-patch+json: schema: $ref: '#/components/schemas/SensorsPatchRequest' responses: @@ -757,6 +843,7 @@ paths: - configuration - v1 - sensors + x-stability-level: alpha /networking-uxi/v1alpha1/service-test-group-assignments/{id}: delete: operationId: service_test_group_assignments_delete @@ -1202,6 +1289,79 @@ components: - pcapMode - type title: AgentItem + AgentsPatchRequest: + description: |- + Request body for patching an agent. + + Fields: + name: Optional string + notes: Optional string + pcap_mode: Optional string + type: object + properties: + name: + type: string + title: Name + notes: + type: string + title: Notes + pcapMode: + type: string + title: Pcapmode + title: AgentsPatchRequest + AgentsPatchResponse: + type: object + properties: + id: + type: string + title: Id + serial: + type: string + title: Serial + name: + type: string + title: Name + modelNumber: + anyOf: + - type: string + nullable: true + title: Modelnumber + wifiMacAddress: + anyOf: + - type: string + nullable: true + title: Wifimacaddress + ethernetMacAddress: + anyOf: + - type: string + nullable: true + title: Ethernetmacaddress + notes: + anyOf: + - type: string + nullable: true + title: Notes + pcapMode: + anyOf: + - type: string + nullable: true + title: Pcapmode + type: + type: string + enum: + - networking-uxi/agent + title: Type + required: + - id + - serial + - name + - modelNumber + - wifiMacAddress + - ethernetMacAddress + - notes + - pcapMode + - type + title: AgentsPatchResponse AgentsResponse: type: object properties: @@ -1665,24 +1825,28 @@ components: - type title: SensorItem SensorsPatchRequest: + description: |- + Request body for patching a sensor. + + Fields: + name: Optional string + address_note: Optional string + notes: Optional string + pcap_mode: Optional string type: object properties: name: type: string title: Name - address_note: - anyOf: - - type: string - nullable: true - title: Address Note + addressNote: + type: string + title: Addressnote notes: - anyOf: - - type: string - nullable: true + type: string title: Notes - pcap_mode: + pcapMode: type: string - title: Pcap Mode + title: Pcapmode title: SensorsPatchRequest SensorsPatchResponse: type: object diff --git a/pkg/config-api-client/api/openapi.yaml b/pkg/config-api-client/api/openapi.yaml index 5d30059a..df14a1e1 100644 --- a/pkg/config-api-client/api/openapi.yaml +++ b/pkg/config-api-client/api/openapi.yaml @@ -9,7 +9,7 @@ info: name: "No idea, but we need something" termsOfService: http://we.dont.care.yet.com/term-of-service title: Configuration Api - version: 5.6.0 + version: 5.10.0 servers: - url: https://api.capenetworks.com - url: https://api.staging.capedev.io @@ -121,6 +121,45 @@ paths: tags: - configuration x-stability-level: alpha + /networking-uxi/v1alpha1/agent-group-assignments/{uid}: + delete: + description: Delete an agent group assignment. + operationId: agent_group_assignment_delete + parameters: + - explode: false + in: path + name: uid + required: true + schema: + title: Uid + type: string + style: simple + responses: + "200": + content: + application/json: + schema: {} + description: Successful Response + "204": + description: No Content + "4XX": + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + description: Client Error + "5XX": + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + description: Server Error + security: + - HTTPBearer: [] + summary: Agent Group Assignment Delete + tags: + - configuration + x-stability-level: alpha /networking-uxi/v1alpha1/agents/{agent_uid}: delete: description: Delete an existing agent. @@ -159,6 +198,49 @@ paths: summary: Agents Delete tags: - configuration + patch: + description: Update an existing agent. + operationId: agents_patch + parameters: + - explode: false + in: path + name: agent_uid + required: true + schema: + title: Agent Uid + type: string + style: simple + requestBody: + content: + application/merge-patch+json: + schema: + $ref: '#/components/schemas/AgentsPatchRequest' + required: true + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/AgentsPatchResponse' + description: Successful Response + "4XX": + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + description: Client Error + "5XX": + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + description: Server Error + security: + - HTTPBearer: [] + summary: Agents Patch + tags: + - configuration + x-stability-level: alpha /networking-uxi/v1alpha1/agents: get: description: Get a list of agents @@ -254,6 +336,7 @@ paths: summary: Groups Delete tags: - configuration + x-stability-level: alpha patch: description: Update an existing group. operationId: groups_patch @@ -295,6 +378,7 @@ paths: summary: Groups Patch tags: - configuration + x-stability-level: alpha /networking-uxi/v1alpha1/groups: get: description: Lists groups matching provided criteria @@ -715,7 +799,7 @@ paths: style: simple requestBody: content: - application/json: + application/merge-patch+json: schema: $ref: '#/components/schemas/SensorsPatchRequest' required: true @@ -743,6 +827,7 @@ paths: summary: Sensors Patch tags: - configuration + x-stability-level: alpha /networking-uxi/v1alpha1/service-test-group-assignments/{id}: delete: description: Delete a service test group assignment @@ -1213,6 +1298,79 @@ components: - wifiMacAddress title: AgentItem type: object + AgentsPatchRequest: + description: |- + Request body for patching an agent. + + Fields: + name: Optional string + notes: Optional string + pcap_mode: Optional string + properties: + name: + title: Name + type: string + notes: + title: Notes + type: string + pcapMode: + title: Pcapmode + type: string + title: AgentsPatchRequest + type: object + AgentsPatchResponse: + example: + notes: notes + pcapMode: pcapMode + serial: serial + ethernetMacAddress: ethernetMacAddress + name: name + modelNumber: modelNumber + id: id + type: networking-uxi/agent + wifiMacAddress: wifiMacAddress + properties: + id: + title: Id + type: string + serial: + title: Serial + type: string + name: + title: Name + type: string + modelNumber: + nullable: true + type: string + wifiMacAddress: + nullable: true + type: string + ethernetMacAddress: + nullable: true + type: string + notes: + nullable: true + type: string + pcapMode: + nullable: true + type: string + type: + enum: + - networking-uxi/agent + title: Type + type: string + required: + - ethernetMacAddress + - id + - modelNumber + - name + - notes + - pcapMode + - serial + - type + - wifiMacAddress + title: AgentsPatchResponse + type: object AgentsResponse: example: next: next @@ -1832,23 +1990,26 @@ components: title: SensorItem type: object SensorsPatchRequest: - example: - address_note: address_note - notes: notes - name: name - pcap_mode: pcap_mode + description: |- + Request body for patching a sensor. + + Fields: + name: Optional string + address_note: Optional string + notes: Optional string + pcap_mode: Optional string properties: name: title: Name type: string - address_note: - nullable: true + addressNote: + title: Addressnote type: string notes: - nullable: true + title: Notes type: string - pcap_mode: - title: Pcap Mode + pcapMode: + title: Pcapmode type: string title: SensorsPatchRequest type: object diff --git a/pkg/config-api-client/api_configuration.go b/pkg/config-api-client/api_configuration.go index 1d50dfa1..7ec5630f 100644 --- a/pkg/config-api-client/api_configuration.go +++ b/pkg/config-api-client/api_configuration.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ @@ -23,6 +23,157 @@ import ( // ConfigurationAPIService ConfigurationAPI service type ConfigurationAPIService service +type ApiAgentGroupAssignmentDeleteRequest struct { + ctx context.Context + ApiService *ConfigurationAPIService + uid string +} + +func (r ApiAgentGroupAssignmentDeleteRequest) Execute() (interface{}, *http.Response, error) { + return r.ApiService.AgentGroupAssignmentDeleteExecute(r) +} + +/* +AgentGroupAssignmentDelete Agent Group Assignment Delete + +Delete an agent group assignment. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param uid + @return ApiAgentGroupAssignmentDeleteRequest +*/ +func (a *ConfigurationAPIService) AgentGroupAssignmentDelete( + ctx context.Context, + uid string, +) ApiAgentGroupAssignmentDeleteRequest { + return ApiAgentGroupAssignmentDeleteRequest{ + ApiService: a, + ctx: ctx, + uid: uid, + } +} + +// Execute executes the request +// +// @return interface{} +func (a *ConfigurationAPIService) AgentGroupAssignmentDeleteExecute( + r ApiAgentGroupAssignmentDeleteRequest, +) (interface{}, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodDelete + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue interface{} + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext( + r.ctx, + "ConfigurationAPIService.AgentGroupAssignmentDelete", + ) + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/networking-uxi/v1alpha1/agent-group-assignments/{uid}" + localVarPath = strings.Replace( + localVarPath, + "{"+"uid"+"}", + url.PathEscape(parameterValueToString(r.uid, "uid")), + -1, + ) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + req, err := a.client.prepareRequest( + r.ctx, + localVarPath, + localVarHTTPMethod, + localVarPostBody, + localVarHeaderParams, + localVarQueryParams, + localVarFormParams, + formFiles, + ) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode >= 400 && localVarHTTPResponse.StatusCode < 500 { + var v ErrorResponse + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode >= 500 { + var v ErrorResponse + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode( + &localVarReturnValue, + localVarBody, + localVarHTTPResponse.Header.Get("Content-Type"), + ) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + type ApiAgentGroupAssignmentsGetRequest struct { ctx context.Context ApiService *ConfigurationAPIService @@ -670,6 +821,172 @@ func (a *ConfigurationAPIService) AgentsGetExecute( return localVarReturnValue, localVarHTTPResponse, nil } +type ApiAgentsPatchRequest struct { + ctx context.Context + ApiService *ConfigurationAPIService + agentUid string + agentsPatchRequest *AgentsPatchRequest +} + +func (r ApiAgentsPatchRequest) AgentsPatchRequest( + agentsPatchRequest AgentsPatchRequest, +) ApiAgentsPatchRequest { + r.agentsPatchRequest = &agentsPatchRequest + return r +} + +func (r ApiAgentsPatchRequest) Execute() (*AgentsPatchResponse, *http.Response, error) { + return r.ApiService.AgentsPatchExecute(r) +} + +/* +AgentsPatch Agents Patch + +Update an existing agent. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param agentUid + @return ApiAgentsPatchRequest +*/ +func (a *ConfigurationAPIService) AgentsPatch( + ctx context.Context, + agentUid string, +) ApiAgentsPatchRequest { + return ApiAgentsPatchRequest{ + ApiService: a, + ctx: ctx, + agentUid: agentUid, + } +} + +// Execute executes the request +// +// @return AgentsPatchResponse +func (a *ConfigurationAPIService) AgentsPatchExecute( + r ApiAgentsPatchRequest, +) (*AgentsPatchResponse, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPatch + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *AgentsPatchResponse + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext( + r.ctx, + "ConfigurationAPIService.AgentsPatch", + ) + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/networking-uxi/v1alpha1/agents/{agent_uid}" + localVarPath = strings.Replace( + localVarPath, + "{"+"agent_uid"+"}", + url.PathEscape(parameterValueToString(r.agentUid, "agentUid")), + -1, + ) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.agentsPatchRequest == nil { + return localVarReturnValue, nil, reportError( + "agentsPatchRequest is required and must be specified", + ) + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/merge-patch+json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.agentsPatchRequest + req, err := a.client.prepareRequest( + r.ctx, + localVarPath, + localVarHTTPMethod, + localVarPostBody, + localVarHeaderParams, + localVarQueryParams, + localVarFormParams, + formFiles, + ) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode >= 400 && localVarHTTPResponse.StatusCode < 500 { + var v ErrorResponse + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode >= 500 { + var v ErrorResponse + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode( + &localVarReturnValue, + localVarBody, + localVarHTTPResponse.Header.Get("Content-Type"), + ) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + type ApiGroupsDeleteRequest struct { ctx context.Context ApiService *ConfigurationAPIService @@ -2513,7 +2830,7 @@ func (a *ConfigurationAPIService) SensorsPatchExecute( } // to determine the Content-Type header - localVarHTTPContentTypes := []string{"application/json"} + localVarHTTPContentTypes := []string{"application/merge-patch+json"} // set Content-Type header localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) diff --git a/pkg/config-api-client/client.go b/pkg/config-api-client/client.go index debdc55f..dd1a33eb 100644 --- a/pkg/config-api-client/client.go +++ b/pkg/config-api-client/client.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ @@ -41,7 +41,7 @@ var ( queryDescape = strings.NewReplacer("%5B", "[", "%5D", "]") ) -// APIClient manages communication with the Configuration Api API v5.6.0 +// APIClient manages communication with the Configuration Api API v5.10.0 // In most cases there should be only one, shared, APIClient. type APIClient struct { cfg *Configuration diff --git a/pkg/config-api-client/configuration.go b/pkg/config-api-client/configuration.go index 1738e669..2217c2e4 100644 --- a/pkg/config-api-client/configuration.go +++ b/pkg/config-api-client/configuration.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/docs/AgentsPatchRequest.md b/pkg/config-api-client/docs/AgentsPatchRequest.md new file mode 100644 index 00000000..e8482958 --- /dev/null +++ b/pkg/config-api-client/docs/AgentsPatchRequest.md @@ -0,0 +1,108 @@ +# AgentsPatchRequest + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Name** | Pointer to **string** | | [optional] +**Notes** | Pointer to **string** | | [optional] +**PcapMode** | Pointer to **string** | | [optional] + +## Methods + +### NewAgentsPatchRequest + +`func NewAgentsPatchRequest() *AgentsPatchRequest` + +NewAgentsPatchRequest instantiates a new AgentsPatchRequest object +This constructor will assign default values to properties that have it defined, +and makes sure properties required by API are set, but the set of arguments +will change when the set of required properties is changed + +### NewAgentsPatchRequestWithDefaults + +`func NewAgentsPatchRequestWithDefaults() *AgentsPatchRequest` + +NewAgentsPatchRequestWithDefaults instantiates a new AgentsPatchRequest object +This constructor will only assign default values to properties that have it defined, +but it doesn't guarantee that properties required by API are set + +### GetName + +`func (o *AgentsPatchRequest) GetName() string` + +GetName returns the Name field if non-nil, zero value otherwise. + +### GetNameOk + +`func (o *AgentsPatchRequest) GetNameOk() (*string, bool)` + +GetNameOk returns a tuple with the Name field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetName + +`func (o *AgentsPatchRequest) SetName(v string)` + +SetName sets Name field to given value. + +### HasName + +`func (o *AgentsPatchRequest) HasName() bool` + +HasName returns a boolean if a field has been set. + +### GetNotes + +`func (o *AgentsPatchRequest) GetNotes() string` + +GetNotes returns the Notes field if non-nil, zero value otherwise. + +### GetNotesOk + +`func (o *AgentsPatchRequest) GetNotesOk() (*string, bool)` + +GetNotesOk returns a tuple with the Notes field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetNotes + +`func (o *AgentsPatchRequest) SetNotes(v string)` + +SetNotes sets Notes field to given value. + +### HasNotes + +`func (o *AgentsPatchRequest) HasNotes() bool` + +HasNotes returns a boolean if a field has been set. + +### GetPcapMode + +`func (o *AgentsPatchRequest) GetPcapMode() string` + +GetPcapMode returns the PcapMode field if non-nil, zero value otherwise. + +### GetPcapModeOk + +`func (o *AgentsPatchRequest) GetPcapModeOk() (*string, bool)` + +GetPcapModeOk returns a tuple with the PcapMode field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetPcapMode + +`func (o *AgentsPatchRequest) SetPcapMode(v string)` + +SetPcapMode sets PcapMode field to given value. + +### HasPcapMode + +`func (o *AgentsPatchRequest) HasPcapMode() bool` + +HasPcapMode returns a boolean if a field has been set. + + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/pkg/config-api-client/docs/AgentsPatchResponse.md b/pkg/config-api-client/docs/AgentsPatchResponse.md new file mode 100644 index 00000000..b7653579 --- /dev/null +++ b/pkg/config-api-client/docs/AgentsPatchResponse.md @@ -0,0 +1,269 @@ +# AgentsPatchResponse + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Id** | **string** | | +**Serial** | **string** | | +**Name** | **string** | | +**ModelNumber** | **NullableString** | | +**WifiMacAddress** | **NullableString** | | +**EthernetMacAddress** | **NullableString** | | +**Notes** | **NullableString** | | +**PcapMode** | **NullableString** | | +**Type** | **string** | | + +## Methods + +### NewAgentsPatchResponse + +`func NewAgentsPatchResponse(id string, serial string, name string, modelNumber NullableString, wifiMacAddress NullableString, ethernetMacAddress NullableString, notes NullableString, pcapMode NullableString, type_ string, ) *AgentsPatchResponse` + +NewAgentsPatchResponse instantiates a new AgentsPatchResponse object +This constructor will assign default values to properties that have it defined, +and makes sure properties required by API are set, but the set of arguments +will change when the set of required properties is changed + +### NewAgentsPatchResponseWithDefaults + +`func NewAgentsPatchResponseWithDefaults() *AgentsPatchResponse` + +NewAgentsPatchResponseWithDefaults instantiates a new AgentsPatchResponse object +This constructor will only assign default values to properties that have it defined, +but it doesn't guarantee that properties required by API are set + +### GetId + +`func (o *AgentsPatchResponse) GetId() string` + +GetId returns the Id field if non-nil, zero value otherwise. + +### GetIdOk + +`func (o *AgentsPatchResponse) GetIdOk() (*string, bool)` + +GetIdOk returns a tuple with the Id field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetId + +`func (o *AgentsPatchResponse) SetId(v string)` + +SetId sets Id field to given value. + + +### GetSerial + +`func (o *AgentsPatchResponse) GetSerial() string` + +GetSerial returns the Serial field if non-nil, zero value otherwise. + +### GetSerialOk + +`func (o *AgentsPatchResponse) GetSerialOk() (*string, bool)` + +GetSerialOk returns a tuple with the Serial field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetSerial + +`func (o *AgentsPatchResponse) SetSerial(v string)` + +SetSerial sets Serial field to given value. + + +### GetName + +`func (o *AgentsPatchResponse) GetName() string` + +GetName returns the Name field if non-nil, zero value otherwise. + +### GetNameOk + +`func (o *AgentsPatchResponse) GetNameOk() (*string, bool)` + +GetNameOk returns a tuple with the Name field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetName + +`func (o *AgentsPatchResponse) SetName(v string)` + +SetName sets Name field to given value. + + +### GetModelNumber + +`func (o *AgentsPatchResponse) GetModelNumber() string` + +GetModelNumber returns the ModelNumber field if non-nil, zero value otherwise. + +### GetModelNumberOk + +`func (o *AgentsPatchResponse) GetModelNumberOk() (*string, bool)` + +GetModelNumberOk returns a tuple with the ModelNumber field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetModelNumber + +`func (o *AgentsPatchResponse) SetModelNumber(v string)` + +SetModelNumber sets ModelNumber field to given value. + + +### SetModelNumberNil + +`func (o *AgentsPatchResponse) SetModelNumberNil(b bool)` + + SetModelNumberNil sets the value for ModelNumber to be an explicit nil + +### UnsetModelNumber +`func (o *AgentsPatchResponse) UnsetModelNumber()` + +UnsetModelNumber ensures that no value is present for ModelNumber, not even an explicit nil +### GetWifiMacAddress + +`func (o *AgentsPatchResponse) GetWifiMacAddress() string` + +GetWifiMacAddress returns the WifiMacAddress field if non-nil, zero value otherwise. + +### GetWifiMacAddressOk + +`func (o *AgentsPatchResponse) GetWifiMacAddressOk() (*string, bool)` + +GetWifiMacAddressOk returns a tuple with the WifiMacAddress field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetWifiMacAddress + +`func (o *AgentsPatchResponse) SetWifiMacAddress(v string)` + +SetWifiMacAddress sets WifiMacAddress field to given value. + + +### SetWifiMacAddressNil + +`func (o *AgentsPatchResponse) SetWifiMacAddressNil(b bool)` + + SetWifiMacAddressNil sets the value for WifiMacAddress to be an explicit nil + +### UnsetWifiMacAddress +`func (o *AgentsPatchResponse) UnsetWifiMacAddress()` + +UnsetWifiMacAddress ensures that no value is present for WifiMacAddress, not even an explicit nil +### GetEthernetMacAddress + +`func (o *AgentsPatchResponse) GetEthernetMacAddress() string` + +GetEthernetMacAddress returns the EthernetMacAddress field if non-nil, zero value otherwise. + +### GetEthernetMacAddressOk + +`func (o *AgentsPatchResponse) GetEthernetMacAddressOk() (*string, bool)` + +GetEthernetMacAddressOk returns a tuple with the EthernetMacAddress field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetEthernetMacAddress + +`func (o *AgentsPatchResponse) SetEthernetMacAddress(v string)` + +SetEthernetMacAddress sets EthernetMacAddress field to given value. + + +### SetEthernetMacAddressNil + +`func (o *AgentsPatchResponse) SetEthernetMacAddressNil(b bool)` + + SetEthernetMacAddressNil sets the value for EthernetMacAddress to be an explicit nil + +### UnsetEthernetMacAddress +`func (o *AgentsPatchResponse) UnsetEthernetMacAddress()` + +UnsetEthernetMacAddress ensures that no value is present for EthernetMacAddress, not even an explicit nil +### GetNotes + +`func (o *AgentsPatchResponse) GetNotes() string` + +GetNotes returns the Notes field if non-nil, zero value otherwise. + +### GetNotesOk + +`func (o *AgentsPatchResponse) GetNotesOk() (*string, bool)` + +GetNotesOk returns a tuple with the Notes field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetNotes + +`func (o *AgentsPatchResponse) SetNotes(v string)` + +SetNotes sets Notes field to given value. + + +### SetNotesNil + +`func (o *AgentsPatchResponse) SetNotesNil(b bool)` + + SetNotesNil sets the value for Notes to be an explicit nil + +### UnsetNotes +`func (o *AgentsPatchResponse) UnsetNotes()` + +UnsetNotes ensures that no value is present for Notes, not even an explicit nil +### GetPcapMode + +`func (o *AgentsPatchResponse) GetPcapMode() string` + +GetPcapMode returns the PcapMode field if non-nil, zero value otherwise. + +### GetPcapModeOk + +`func (o *AgentsPatchResponse) GetPcapModeOk() (*string, bool)` + +GetPcapModeOk returns a tuple with the PcapMode field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetPcapMode + +`func (o *AgentsPatchResponse) SetPcapMode(v string)` + +SetPcapMode sets PcapMode field to given value. + + +### SetPcapModeNil + +`func (o *AgentsPatchResponse) SetPcapModeNil(b bool)` + + SetPcapModeNil sets the value for PcapMode to be an explicit nil + +### UnsetPcapMode +`func (o *AgentsPatchResponse) UnsetPcapMode()` + +UnsetPcapMode ensures that no value is present for PcapMode, not even an explicit nil +### GetType + +`func (o *AgentsPatchResponse) GetType() string` + +GetType returns the Type field if non-nil, zero value otherwise. + +### GetTypeOk + +`func (o *AgentsPatchResponse) GetTypeOk() (*string, bool)` + +GetTypeOk returns a tuple with the Type field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetType + +`func (o *AgentsPatchResponse) SetType(v string)` + +SetType sets Type field to given value. + + + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/pkg/config-api-client/docs/ConfigurationAPI.md b/pkg/config-api-client/docs/ConfigurationAPI.md index a264f186..fb7deba8 100644 --- a/pkg/config-api-client/docs/ConfigurationAPI.md +++ b/pkg/config-api-client/docs/ConfigurationAPI.md @@ -4,10 +4,12 @@ All URIs are relative to *https://api.capenetworks.com* Method | HTTP request | Description ------------- | ------------- | ------------- +[**AgentGroupAssignmentDelete**](ConfigurationAPI.md#AgentGroupAssignmentDelete) | **Delete** /networking-uxi/v1alpha1/agent-group-assignments/{uid} | Agent Group Assignment Delete [**AgentGroupAssignmentsGet**](ConfigurationAPI.md#AgentGroupAssignmentsGet) | **Get** /networking-uxi/v1alpha1/agent-group-assignments | Agent Group Assignments Get [**AgentGroupAssignmentsPost**](ConfigurationAPI.md#AgentGroupAssignmentsPost) | **Post** /networking-uxi/v1alpha1/agent-group-assignments | Agent Group Assignments Post [**AgentsDelete**](ConfigurationAPI.md#AgentsDelete) | **Delete** /networking-uxi/v1alpha1/agents/{agent_uid} | Agents Delete [**AgentsGet**](ConfigurationAPI.md#AgentsGet) | **Get** /networking-uxi/v1alpha1/agents | Agents Get +[**AgentsPatch**](ConfigurationAPI.md#AgentsPatch) | **Patch** /networking-uxi/v1alpha1/agents/{agent_uid} | Agents Patch [**GroupsDelete**](ConfigurationAPI.md#GroupsDelete) | **Delete** /networking-uxi/v1alpha1/groups/{group_uid} | Groups Delete [**GroupsGet**](ConfigurationAPI.md#GroupsGet) | **Get** /networking-uxi/v1alpha1/groups | Groups Get [**GroupsPatch**](ConfigurationAPI.md#GroupsPatch) | **Patch** /networking-uxi/v1alpha1/groups/{group_uid} | Groups Patch @@ -29,6 +31,76 @@ Method | HTTP request | Description +## AgentGroupAssignmentDelete + +> interface{} AgentGroupAssignmentDelete(ctx, uid).Execute() + +Agent Group Assignment Delete + + + +### Example + +```go +package main + +import ( + "context" + "fmt" + "os" + openapiclient "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" +) + +func main() { + uid := "uid_example" // string | + + configuration := openapiclient.NewConfiguration() + apiClient := openapiclient.NewAPIClient(configuration) + resp, r, err := apiClient.ConfigurationAPI.AgentGroupAssignmentDelete(context.Background(), uid).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `ConfigurationAPI.AgentGroupAssignmentDelete``: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + // response from `AgentGroupAssignmentDelete`: interface{} + fmt.Fprintf(os.Stdout, "Response from `ConfigurationAPI.AgentGroupAssignmentDelete`: %v\n", resp) +} +``` + +### Path Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +**ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. +**uid** | **string** | | + +### Other Parameters + +Other parameters are passed through a pointer to a apiAgentGroupAssignmentDeleteRequest struct via the builder pattern + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + + +### Return type + +**interface{}** + +### Authorization + +[HTTPBearer](../README.md#HTTPBearer) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) +[[Back to Model list]](../README.md#documentation-for-models) +[[Back to README]](../README.md) + + ## AgentGroupAssignmentsGet > AgentGroupAssignmentsResponse AgentGroupAssignmentsGet(ctx).Id(id).Next(next).Limit(limit).Execute() @@ -46,7 +118,7 @@ import ( "context" "fmt" "os" - openapiclient "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + openapiclient "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ) func main() { @@ -116,7 +188,7 @@ import ( "context" "fmt" "os" - openapiclient "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + openapiclient "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ) func main() { @@ -182,7 +254,7 @@ import ( "context" "fmt" "os" - openapiclient "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + openapiclient "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ) func main() { @@ -252,7 +324,7 @@ import ( "context" "fmt" "os" - openapiclient "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + openapiclient "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ) func main() { @@ -305,6 +377,78 @@ Name | Type | Description | Notes [[Back to README]](../README.md) +## AgentsPatch + +> AgentsPatchResponse AgentsPatch(ctx, agentUid).AgentsPatchRequest(agentsPatchRequest).Execute() + +Agents Patch + + + +### Example + +```go +package main + +import ( + "context" + "fmt" + "os" + openapiclient "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" +) + +func main() { + agentUid := "agentUid_example" // string | + agentsPatchRequest := *openapiclient.NewAgentsPatchRequest() // AgentsPatchRequest | + + configuration := openapiclient.NewConfiguration() + apiClient := openapiclient.NewAPIClient(configuration) + resp, r, err := apiClient.ConfigurationAPI.AgentsPatch(context.Background(), agentUid).AgentsPatchRequest(agentsPatchRequest).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `ConfigurationAPI.AgentsPatch``: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + // response from `AgentsPatch`: AgentsPatchResponse + fmt.Fprintf(os.Stdout, "Response from `ConfigurationAPI.AgentsPatch`: %v\n", resp) +} +``` + +### Path Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +**ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. +**agentUid** | **string** | | + +### Other Parameters + +Other parameters are passed through a pointer to a apiAgentsPatchRequest struct via the builder pattern + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + + **agentsPatchRequest** | [**AgentsPatchRequest**](AgentsPatchRequest.md) | | + +### Return type + +[**AgentsPatchResponse**](AgentsPatchResponse.md) + +### Authorization + +[HTTPBearer](../README.md#HTTPBearer) + +### HTTP request headers + +- **Content-Type**: application/merge-patch+json +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) +[[Back to Model list]](../README.md#documentation-for-models) +[[Back to README]](../README.md) + + ## GroupsDelete > interface{} GroupsDelete(ctx, groupUid).Execute() @@ -322,7 +466,7 @@ import ( "context" "fmt" "os" - openapiclient "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + openapiclient "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ) func main() { @@ -392,7 +536,7 @@ import ( "context" "fmt" "os" - openapiclient "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + openapiclient "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ) func main() { @@ -462,7 +606,7 @@ import ( "context" "fmt" "os" - openapiclient "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + openapiclient "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ) func main() { @@ -534,7 +678,7 @@ import ( "context" "fmt" "os" - openapiclient "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + openapiclient "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ) func main() { @@ -600,7 +744,7 @@ import ( "context" "fmt" "os" - openapiclient "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + openapiclient "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ) func main() { @@ -670,7 +814,7 @@ import ( "context" "fmt" "os" - openapiclient "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + openapiclient "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ) func main() { @@ -740,7 +884,7 @@ import ( "context" "fmt" "os" - openapiclient "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + openapiclient "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ) func main() { @@ -806,7 +950,7 @@ import ( "context" "fmt" "os" - openapiclient "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + openapiclient "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ) func main() { @@ -876,7 +1020,7 @@ import ( "context" "fmt" "os" - openapiclient "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + openapiclient "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ) func main() { @@ -946,7 +1090,7 @@ import ( "context" "fmt" "os" - openapiclient "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + openapiclient "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ) func main() { @@ -1012,7 +1156,7 @@ import ( "context" "fmt" "os" - openapiclient "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + openapiclient "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ) func main() { @@ -1082,7 +1226,7 @@ import ( "context" "fmt" "os" - openapiclient "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + openapiclient "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ) func main() { @@ -1129,7 +1273,7 @@ Name | Type | Description | Notes ### HTTP request headers -- **Content-Type**: application/json +- **Content-Type**: application/merge-patch+json - **Accept**: application/json [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) @@ -1154,7 +1298,7 @@ import ( "context" "fmt" "os" - openapiclient "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + openapiclient "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ) func main() { @@ -1224,7 +1368,7 @@ import ( "context" "fmt" "os" - openapiclient "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + openapiclient "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ) func main() { @@ -1294,7 +1438,7 @@ import ( "context" "fmt" "os" - openapiclient "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + openapiclient "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ) func main() { @@ -1360,7 +1504,7 @@ import ( "context" "fmt" "os" - openapiclient "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + openapiclient "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ) func main() { @@ -1430,7 +1574,7 @@ import ( "context" "fmt" "os" - openapiclient "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + openapiclient "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ) func main() { @@ -1500,7 +1644,7 @@ import ( "context" "fmt" "os" - openapiclient "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + openapiclient "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" ) func main() { diff --git a/pkg/config-api-client/docs/SensorsPatchRequest.md b/pkg/config-api-client/docs/SensorsPatchRequest.md index 394fdcb5..90c6220a 100644 --- a/pkg/config-api-client/docs/SensorsPatchRequest.md +++ b/pkg/config-api-client/docs/SensorsPatchRequest.md @@ -5,8 +5,8 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **Name** | Pointer to **string** | | [optional] -**AddressNote** | Pointer to **NullableString** | | [optional] -**Notes** | Pointer to **NullableString** | | [optional] +**AddressNote** | Pointer to **string** | | [optional] +**Notes** | Pointer to **string** | | [optional] **PcapMode** | Pointer to **string** | | [optional] ## Methods @@ -78,16 +78,6 @@ SetAddressNote sets AddressNote field to given value. HasAddressNote returns a boolean if a field has been set. -### SetAddressNoteNil - -`func (o *SensorsPatchRequest) SetAddressNoteNil(b bool)` - - SetAddressNoteNil sets the value for AddressNote to be an explicit nil - -### UnsetAddressNote -`func (o *SensorsPatchRequest) UnsetAddressNote()` - -UnsetAddressNote ensures that no value is present for AddressNote, not even an explicit nil ### GetNotes `func (o *SensorsPatchRequest) GetNotes() string` @@ -113,16 +103,6 @@ SetNotes sets Notes field to given value. HasNotes returns a boolean if a field has been set. -### SetNotesNil - -`func (o *SensorsPatchRequest) SetNotesNil(b bool)` - - SetNotesNil sets the value for Notes to be an explicit nil - -### UnsetNotes -`func (o *SensorsPatchRequest) UnsetNotes()` - -UnsetNotes ensures that no value is present for Notes, not even an explicit nil ### GetPcapMode `func (o *SensorsPatchRequest) GetPcapMode() string` diff --git a/pkg/config-api-client/go.mod b/pkg/config-api-client/go.mod index 6c5bcb61..c4418b8d 100644 --- a/pkg/config-api-client/go.mod +++ b/pkg/config-api-client/go.mod @@ -1,4 +1,4 @@ -module github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client +module github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client go 1.18 diff --git a/pkg/config-api-client/model_agent.go b/pkg/config-api-client/model_agent.go index 090015f4..095f8736 100644 --- a/pkg/config-api-client/model_agent.go +++ b/pkg/config-api-client/model_agent.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_agent_group_assignment_response.go b/pkg/config-api-client/model_agent_group_assignment_response.go index 4ade33cf..7fc7850b 100644 --- a/pkg/config-api-client/model_agent_group_assignment_response.go +++ b/pkg/config-api-client/model_agent_group_assignment_response.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_agent_group_assignments_item.go b/pkg/config-api-client/model_agent_group_assignments_item.go index ae898888..5b67360b 100644 --- a/pkg/config-api-client/model_agent_group_assignments_item.go +++ b/pkg/config-api-client/model_agent_group_assignments_item.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_agent_group_assignments_post_request.go b/pkg/config-api-client/model_agent_group_assignments_post_request.go index d214f689..27bc83c1 100644 --- a/pkg/config-api-client/model_agent_group_assignments_post_request.go +++ b/pkg/config-api-client/model_agent_group_assignments_post_request.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_agent_group_assignments_response.go b/pkg/config-api-client/model_agent_group_assignments_response.go index 667579c2..e726c89c 100644 --- a/pkg/config-api-client/model_agent_group_assignments_response.go +++ b/pkg/config-api-client/model_agent_group_assignments_response.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_agent_item.go b/pkg/config-api-client/model_agent_item.go index 9760a724..3677cd4e 100644 --- a/pkg/config-api-client/model_agent_item.go +++ b/pkg/config-api-client/model_agent_item.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_agents_patch_request.go b/pkg/config-api-client/model_agents_patch_request.go new file mode 100644 index 00000000..44d16bad --- /dev/null +++ b/pkg/config-api-client/model_agents_patch_request.go @@ -0,0 +1,197 @@ +/* +Configuration Api + +Nice description goes here + +API version: 5.10.0 +Contact: support@capenetworks.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package config_api_client + +import ( + "encoding/json" +) + +// checks if the AgentsPatchRequest type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &AgentsPatchRequest{} + +// AgentsPatchRequest Request body for patching an agent. Fields: name: Optional string notes: Optional string pcap_mode: Optional string +type AgentsPatchRequest struct { + Name *string `json:"name,omitempty"` + Notes *string `json:"notes,omitempty"` + PcapMode *string `json:"pcapMode,omitempty"` +} + +// NewAgentsPatchRequest instantiates a new AgentsPatchRequest object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewAgentsPatchRequest() *AgentsPatchRequest { + this := AgentsPatchRequest{} + return &this +} + +// NewAgentsPatchRequestWithDefaults instantiates a new AgentsPatchRequest object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewAgentsPatchRequestWithDefaults() *AgentsPatchRequest { + this := AgentsPatchRequest{} + return &this +} + +// GetName returns the Name field value if set, zero value otherwise. +func (o *AgentsPatchRequest) GetName() string { + if o == nil || IsNil(o.Name) { + var ret string + return ret + } + return *o.Name +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *AgentsPatchRequest) GetNameOk() (*string, bool) { + if o == nil || IsNil(o.Name) { + return nil, false + } + return o.Name, true +} + +// HasName returns a boolean if a field has been set. +func (o *AgentsPatchRequest) HasName() bool { + if o != nil && !IsNil(o.Name) { + return true + } + + return false +} + +// SetName gets a reference to the given string and assigns it to the Name field. +func (o *AgentsPatchRequest) SetName(v string) { + o.Name = &v +} + +// GetNotes returns the Notes field value if set, zero value otherwise. +func (o *AgentsPatchRequest) GetNotes() string { + if o == nil || IsNil(o.Notes) { + var ret string + return ret + } + return *o.Notes +} + +// GetNotesOk returns a tuple with the Notes field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *AgentsPatchRequest) GetNotesOk() (*string, bool) { + if o == nil || IsNil(o.Notes) { + return nil, false + } + return o.Notes, true +} + +// HasNotes returns a boolean if a field has been set. +func (o *AgentsPatchRequest) HasNotes() bool { + if o != nil && !IsNil(o.Notes) { + return true + } + + return false +} + +// SetNotes gets a reference to the given string and assigns it to the Notes field. +func (o *AgentsPatchRequest) SetNotes(v string) { + o.Notes = &v +} + +// GetPcapMode returns the PcapMode field value if set, zero value otherwise. +func (o *AgentsPatchRequest) GetPcapMode() string { + if o == nil || IsNil(o.PcapMode) { + var ret string + return ret + } + return *o.PcapMode +} + +// GetPcapModeOk returns a tuple with the PcapMode field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *AgentsPatchRequest) GetPcapModeOk() (*string, bool) { + if o == nil || IsNil(o.PcapMode) { + return nil, false + } + return o.PcapMode, true +} + +// HasPcapMode returns a boolean if a field has been set. +func (o *AgentsPatchRequest) HasPcapMode() bool { + if o != nil && !IsNil(o.PcapMode) { + return true + } + + return false +} + +// SetPcapMode gets a reference to the given string and assigns it to the PcapMode field. +func (o *AgentsPatchRequest) SetPcapMode(v string) { + o.PcapMode = &v +} + +func (o AgentsPatchRequest) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o AgentsPatchRequest) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Name) { + toSerialize["name"] = o.Name + } + if !IsNil(o.Notes) { + toSerialize["notes"] = o.Notes + } + if !IsNil(o.PcapMode) { + toSerialize["pcapMode"] = o.PcapMode + } + return toSerialize, nil +} + +type NullableAgentsPatchRequest struct { + value *AgentsPatchRequest + isSet bool +} + +func (v NullableAgentsPatchRequest) Get() *AgentsPatchRequest { + return v.value +} + +func (v *NullableAgentsPatchRequest) Set(val *AgentsPatchRequest) { + v.value = val + v.isSet = true +} + +func (v NullableAgentsPatchRequest) IsSet() bool { + return v.isSet +} + +func (v *NullableAgentsPatchRequest) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableAgentsPatchRequest(val *AgentsPatchRequest) *NullableAgentsPatchRequest { + return &NullableAgentsPatchRequest{value: val, isSet: true} +} + +func (v NullableAgentsPatchRequest) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableAgentsPatchRequest) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/pkg/config-api-client/model_agents_patch_response.go b/pkg/config-api-client/model_agents_patch_response.go new file mode 100644 index 00000000..dab8c5c5 --- /dev/null +++ b/pkg/config-api-client/model_agents_patch_response.go @@ -0,0 +1,401 @@ +/* +Configuration Api + +Nice description goes here + +API version: 5.10.0 +Contact: support@capenetworks.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package config_api_client + +import ( + "bytes" + "encoding/json" + "fmt" +) + +// checks if the AgentsPatchResponse type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &AgentsPatchResponse{} + +// AgentsPatchResponse struct for AgentsPatchResponse +type AgentsPatchResponse struct { + Id string `json:"id"` + Serial string `json:"serial"` + Name string `json:"name"` + ModelNumber NullableString `json:"modelNumber"` + WifiMacAddress NullableString `json:"wifiMacAddress"` + EthernetMacAddress NullableString `json:"ethernetMacAddress"` + Notes NullableString `json:"notes"` + PcapMode NullableString `json:"pcapMode"` + Type string `json:"type"` +} + +type _AgentsPatchResponse AgentsPatchResponse + +// NewAgentsPatchResponse instantiates a new AgentsPatchResponse object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewAgentsPatchResponse( + id string, + serial string, + name string, + modelNumber NullableString, + wifiMacAddress NullableString, + ethernetMacAddress NullableString, + notes NullableString, + pcapMode NullableString, + type_ string, +) *AgentsPatchResponse { + this := AgentsPatchResponse{} + this.Id = id + this.Serial = serial + this.Name = name + this.ModelNumber = modelNumber + this.WifiMacAddress = wifiMacAddress + this.EthernetMacAddress = ethernetMacAddress + this.Notes = notes + this.PcapMode = pcapMode + this.Type = type_ + return &this +} + +// NewAgentsPatchResponseWithDefaults instantiates a new AgentsPatchResponse object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewAgentsPatchResponseWithDefaults() *AgentsPatchResponse { + this := AgentsPatchResponse{} + return &this +} + +// GetId returns the Id field value +func (o *AgentsPatchResponse) GetId() string { + if o == nil { + var ret string + return ret + } + + return o.Id +} + +// GetIdOk returns a tuple with the Id field value +// and a boolean to check if the value has been set. +func (o *AgentsPatchResponse) GetIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Id, true +} + +// SetId sets field value +func (o *AgentsPatchResponse) SetId(v string) { + o.Id = v +} + +// GetSerial returns the Serial field value +func (o *AgentsPatchResponse) GetSerial() string { + if o == nil { + var ret string + return ret + } + + return o.Serial +} + +// GetSerialOk returns a tuple with the Serial field value +// and a boolean to check if the value has been set. +func (o *AgentsPatchResponse) GetSerialOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Serial, true +} + +// SetSerial sets field value +func (o *AgentsPatchResponse) SetSerial(v string) { + o.Serial = v +} + +// GetName returns the Name field value +func (o *AgentsPatchResponse) GetName() string { + if o == nil { + var ret string + return ret + } + + return o.Name +} + +// GetNameOk returns a tuple with the Name field value +// and a boolean to check if the value has been set. +func (o *AgentsPatchResponse) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Name, true +} + +// SetName sets field value +func (o *AgentsPatchResponse) SetName(v string) { + o.Name = v +} + +// GetModelNumber returns the ModelNumber field value +// If the value is explicit nil, the zero value for string will be returned +func (o *AgentsPatchResponse) GetModelNumber() string { + if o == nil || o.ModelNumber.Get() == nil { + var ret string + return ret + } + + return *o.ModelNumber.Get() +} + +// GetModelNumberOk returns a tuple with the ModelNumber field value +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *AgentsPatchResponse) GetModelNumberOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.ModelNumber.Get(), o.ModelNumber.IsSet() +} + +// SetModelNumber sets field value +func (o *AgentsPatchResponse) SetModelNumber(v string) { + o.ModelNumber.Set(&v) +} + +// GetWifiMacAddress returns the WifiMacAddress field value +// If the value is explicit nil, the zero value for string will be returned +func (o *AgentsPatchResponse) GetWifiMacAddress() string { + if o == nil || o.WifiMacAddress.Get() == nil { + var ret string + return ret + } + + return *o.WifiMacAddress.Get() +} + +// GetWifiMacAddressOk returns a tuple with the WifiMacAddress field value +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *AgentsPatchResponse) GetWifiMacAddressOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.WifiMacAddress.Get(), o.WifiMacAddress.IsSet() +} + +// SetWifiMacAddress sets field value +func (o *AgentsPatchResponse) SetWifiMacAddress(v string) { + o.WifiMacAddress.Set(&v) +} + +// GetEthernetMacAddress returns the EthernetMacAddress field value +// If the value is explicit nil, the zero value for string will be returned +func (o *AgentsPatchResponse) GetEthernetMacAddress() string { + if o == nil || o.EthernetMacAddress.Get() == nil { + var ret string + return ret + } + + return *o.EthernetMacAddress.Get() +} + +// GetEthernetMacAddressOk returns a tuple with the EthernetMacAddress field value +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *AgentsPatchResponse) GetEthernetMacAddressOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.EthernetMacAddress.Get(), o.EthernetMacAddress.IsSet() +} + +// SetEthernetMacAddress sets field value +func (o *AgentsPatchResponse) SetEthernetMacAddress(v string) { + o.EthernetMacAddress.Set(&v) +} + +// GetNotes returns the Notes field value +// If the value is explicit nil, the zero value for string will be returned +func (o *AgentsPatchResponse) GetNotes() string { + if o == nil || o.Notes.Get() == nil { + var ret string + return ret + } + + return *o.Notes.Get() +} + +// GetNotesOk returns a tuple with the Notes field value +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *AgentsPatchResponse) GetNotesOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.Notes.Get(), o.Notes.IsSet() +} + +// SetNotes sets field value +func (o *AgentsPatchResponse) SetNotes(v string) { + o.Notes.Set(&v) +} + +// GetPcapMode returns the PcapMode field value +// If the value is explicit nil, the zero value for string will be returned +func (o *AgentsPatchResponse) GetPcapMode() string { + if o == nil || o.PcapMode.Get() == nil { + var ret string + return ret + } + + return *o.PcapMode.Get() +} + +// GetPcapModeOk returns a tuple with the PcapMode field value +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *AgentsPatchResponse) GetPcapModeOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.PcapMode.Get(), o.PcapMode.IsSet() +} + +// SetPcapMode sets field value +func (o *AgentsPatchResponse) SetPcapMode(v string) { + o.PcapMode.Set(&v) +} + +// GetType returns the Type field value +func (o *AgentsPatchResponse) GetType() string { + if o == nil { + var ret string + return ret + } + + return o.Type +} + +// GetTypeOk returns a tuple with the Type field value +// and a boolean to check if the value has been set. +func (o *AgentsPatchResponse) GetTypeOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value +func (o *AgentsPatchResponse) SetType(v string) { + o.Type = v +} + +func (o AgentsPatchResponse) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o AgentsPatchResponse) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["id"] = o.Id + toSerialize["serial"] = o.Serial + toSerialize["name"] = o.Name + toSerialize["modelNumber"] = o.ModelNumber.Get() + toSerialize["wifiMacAddress"] = o.WifiMacAddress.Get() + toSerialize["ethernetMacAddress"] = o.EthernetMacAddress.Get() + toSerialize["notes"] = o.Notes.Get() + toSerialize["pcapMode"] = o.PcapMode.Get() + toSerialize["type"] = o.Type + return toSerialize, nil +} + +func (o *AgentsPatchResponse) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "id", + "serial", + "name", + "modelNumber", + "wifiMacAddress", + "ethernetMacAddress", + "notes", + "pcapMode", + "type", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err + } + + for _, requiredProperty := range requiredProperties { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varAgentsPatchResponse := _AgentsPatchResponse{} + + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + err = decoder.Decode(&varAgentsPatchResponse) + + if err != nil { + return err + } + + *o = AgentsPatchResponse(varAgentsPatchResponse) + + return err +} + +type NullableAgentsPatchResponse struct { + value *AgentsPatchResponse + isSet bool +} + +func (v NullableAgentsPatchResponse) Get() *AgentsPatchResponse { + return v.value +} + +func (v *NullableAgentsPatchResponse) Set(val *AgentsPatchResponse) { + v.value = val + v.isSet = true +} + +func (v NullableAgentsPatchResponse) IsSet() bool { + return v.isSet +} + +func (v *NullableAgentsPatchResponse) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableAgentsPatchResponse(val *AgentsPatchResponse) *NullableAgentsPatchResponse { + return &NullableAgentsPatchResponse{value: val, isSet: true} +} + +func (v NullableAgentsPatchResponse) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableAgentsPatchResponse) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/pkg/config-api-client/model_agents_response.go b/pkg/config-api-client/model_agents_response.go index 93083659..daa5bc9c 100644 --- a/pkg/config-api-client/model_agents_response.go +++ b/pkg/config-api-client/model_agents_response.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_error_detail.go b/pkg/config-api-client/model_error_detail.go index 3f8140ae..51ee835e 100644 --- a/pkg/config-api-client/model_error_detail.go +++ b/pkg/config-api-client/model_error_detail.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_error_response.go b/pkg/config-api-client/model_error_response.go index 1eccd445..448deb4c 100644 --- a/pkg/config-api-client/model_error_response.go +++ b/pkg/config-api-client/model_error_response.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_group.go b/pkg/config-api-client/model_group.go index 54f3e204..7c291c9a 100644 --- a/pkg/config-api-client/model_group.go +++ b/pkg/config-api-client/model_group.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_groups_get_item.go b/pkg/config-api-client/model_groups_get_item.go index ad6832cd..9db3ce95 100644 --- a/pkg/config-api-client/model_groups_get_item.go +++ b/pkg/config-api-client/model_groups_get_item.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_groups_get_response.go b/pkg/config-api-client/model_groups_get_response.go index 81671ea7..bb1fd03e 100644 --- a/pkg/config-api-client/model_groups_get_response.go +++ b/pkg/config-api-client/model_groups_get_response.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_groups_patch_request.go b/pkg/config-api-client/model_groups_patch_request.go index 40fd1116..c22206af 100644 --- a/pkg/config-api-client/model_groups_patch_request.go +++ b/pkg/config-api-client/model_groups_patch_request.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_groups_patch_response.go b/pkg/config-api-client/model_groups_patch_response.go index bd96a50b..cb572f4b 100644 --- a/pkg/config-api-client/model_groups_patch_response.go +++ b/pkg/config-api-client/model_groups_patch_response.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_groups_post_request.go b/pkg/config-api-client/model_groups_post_request.go index 3af1abf8..298a52ff 100644 --- a/pkg/config-api-client/model_groups_post_request.go +++ b/pkg/config-api-client/model_groups_post_request.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_groups_post_response.go b/pkg/config-api-client/model_groups_post_response.go index 588e5f3c..2ddcc319 100644 --- a/pkg/config-api-client/model_groups_post_response.go +++ b/pkg/config-api-client/model_groups_post_response.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_issue.go b/pkg/config-api-client/model_issue.go index 4f888270..1d53863a 100644 --- a/pkg/config-api-client/model_issue.go +++ b/pkg/config-api-client/model_issue.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_issue_subject.go b/pkg/config-api-client/model_issue_subject.go index 433cede2..6ed7ed7a 100644 --- a/pkg/config-api-client/model_issue_subject.go +++ b/pkg/config-api-client/model_issue_subject.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_network.go b/pkg/config-api-client/model_network.go index 0c547c05..68498dfb 100644 --- a/pkg/config-api-client/model_network.go +++ b/pkg/config-api-client/model_network.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_network_group_assignments_item.go b/pkg/config-api-client/model_network_group_assignments_item.go index 4896b913..016e4813 100644 --- a/pkg/config-api-client/model_network_group_assignments_item.go +++ b/pkg/config-api-client/model_network_group_assignments_item.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_network_group_assignments_post_request.go b/pkg/config-api-client/model_network_group_assignments_post_request.go index 9ac4e8be..a366d142 100644 --- a/pkg/config-api-client/model_network_group_assignments_post_request.go +++ b/pkg/config-api-client/model_network_group_assignments_post_request.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_network_group_assignments_post_response.go b/pkg/config-api-client/model_network_group_assignments_post_response.go index e0e538a1..48b96639 100644 --- a/pkg/config-api-client/model_network_group_assignments_post_response.go +++ b/pkg/config-api-client/model_network_group_assignments_post_response.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_network_group_assignments_response.go b/pkg/config-api-client/model_network_group_assignments_response.go index 770560a4..cbd49033 100644 --- a/pkg/config-api-client/model_network_group_assignments_response.go +++ b/pkg/config-api-client/model_network_group_assignments_response.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_parent.go b/pkg/config-api-client/model_parent.go index 10c204f0..f7e3072f 100644 --- a/pkg/config-api-client/model_parent.go +++ b/pkg/config-api-client/model_parent.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_sensor.go b/pkg/config-api-client/model_sensor.go index 7ff54384..028b1352 100644 --- a/pkg/config-api-client/model_sensor.go +++ b/pkg/config-api-client/model_sensor.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_sensor_group_assignment_response.go b/pkg/config-api-client/model_sensor_group_assignment_response.go index 92db9fff..b7df55a3 100644 --- a/pkg/config-api-client/model_sensor_group_assignment_response.go +++ b/pkg/config-api-client/model_sensor_group_assignment_response.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_sensor_group_assignments_item.go b/pkg/config-api-client/model_sensor_group_assignments_item.go index f21eb164..6f4f278f 100644 --- a/pkg/config-api-client/model_sensor_group_assignments_item.go +++ b/pkg/config-api-client/model_sensor_group_assignments_item.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_sensor_group_assignments_post_request.go b/pkg/config-api-client/model_sensor_group_assignments_post_request.go index ea9ee527..83ddd32b 100644 --- a/pkg/config-api-client/model_sensor_group_assignments_post_request.go +++ b/pkg/config-api-client/model_sensor_group_assignments_post_request.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_sensor_group_assignments_response.go b/pkg/config-api-client/model_sensor_group_assignments_response.go index 5fc9276a..86c55e4f 100644 --- a/pkg/config-api-client/model_sensor_group_assignments_response.go +++ b/pkg/config-api-client/model_sensor_group_assignments_response.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_sensor_item.go b/pkg/config-api-client/model_sensor_item.go index 8b34ebf9..838cade2 100644 --- a/pkg/config-api-client/model_sensor_item.go +++ b/pkg/config-api-client/model_sensor_item.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_sensors_patch_request.go b/pkg/config-api-client/model_sensors_patch_request.go index 4449ce6e..15512305 100644 --- a/pkg/config-api-client/model_sensors_patch_request.go +++ b/pkg/config-api-client/model_sensors_patch_request.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ @@ -18,12 +18,12 @@ import ( // checks if the SensorsPatchRequest type satisfies the MappedNullable interface at compile time var _ MappedNullable = &SensorsPatchRequest{} -// SensorsPatchRequest struct for SensorsPatchRequest +// SensorsPatchRequest Request body for patching a sensor. Fields: name: Optional string address_note: Optional string notes: Optional string pcap_mode: Optional string type SensorsPatchRequest struct { - Name *string `json:"name,omitempty"` - AddressNote NullableString `json:"address_note,omitempty"` - Notes NullableString `json:"notes,omitempty"` - PcapMode *string `json:"pcap_mode,omitempty"` + Name *string `json:"name,omitempty"` + AddressNote *string `json:"addressNote,omitempty"` + Notes *string `json:"notes,omitempty"` + PcapMode *string `json:"pcapMode,omitempty"` } // NewSensorsPatchRequest instantiates a new SensorsPatchRequest object @@ -75,90 +75,68 @@ func (o *SensorsPatchRequest) SetName(v string) { o.Name = &v } -// GetAddressNote returns the AddressNote field value if set, zero value otherwise (both if not set or set to explicit null). +// GetAddressNote returns the AddressNote field value if set, zero value otherwise. func (o *SensorsPatchRequest) GetAddressNote() string { - if o == nil || IsNil(o.AddressNote.Get()) { + if o == nil || IsNil(o.AddressNote) { var ret string return ret } - return *o.AddressNote.Get() + return *o.AddressNote } // GetAddressNoteOk returns a tuple with the AddressNote field value if set, nil otherwise // and a boolean to check if the value has been set. -// NOTE: If the value is an explicit nil, `nil, true` will be returned func (o *SensorsPatchRequest) GetAddressNoteOk() (*string, bool) { - if o == nil { + if o == nil || IsNil(o.AddressNote) { return nil, false } - return o.AddressNote.Get(), o.AddressNote.IsSet() + return o.AddressNote, true } // HasAddressNote returns a boolean if a field has been set. func (o *SensorsPatchRequest) HasAddressNote() bool { - if o != nil && o.AddressNote.IsSet() { + if o != nil && !IsNil(o.AddressNote) { return true } return false } -// SetAddressNote gets a reference to the given NullableString and assigns it to the AddressNote field. +// SetAddressNote gets a reference to the given string and assigns it to the AddressNote field. func (o *SensorsPatchRequest) SetAddressNote(v string) { - o.AddressNote.Set(&v) + o.AddressNote = &v } -// SetAddressNoteNil sets the value for AddressNote to be an explicit nil -func (o *SensorsPatchRequest) SetAddressNoteNil() { - o.AddressNote.Set(nil) -} - -// UnsetAddressNote ensures that no value is present for AddressNote, not even an explicit nil -func (o *SensorsPatchRequest) UnsetAddressNote() { - o.AddressNote.Unset() -} - -// GetNotes returns the Notes field value if set, zero value otherwise (both if not set or set to explicit null). +// GetNotes returns the Notes field value if set, zero value otherwise. func (o *SensorsPatchRequest) GetNotes() string { - if o == nil || IsNil(o.Notes.Get()) { + if o == nil || IsNil(o.Notes) { var ret string return ret } - return *o.Notes.Get() + return *o.Notes } // GetNotesOk returns a tuple with the Notes field value if set, nil otherwise // and a boolean to check if the value has been set. -// NOTE: If the value is an explicit nil, `nil, true` will be returned func (o *SensorsPatchRequest) GetNotesOk() (*string, bool) { - if o == nil { + if o == nil || IsNil(o.Notes) { return nil, false } - return o.Notes.Get(), o.Notes.IsSet() + return o.Notes, true } // HasNotes returns a boolean if a field has been set. func (o *SensorsPatchRequest) HasNotes() bool { - if o != nil && o.Notes.IsSet() { + if o != nil && !IsNil(o.Notes) { return true } return false } -// SetNotes gets a reference to the given NullableString and assigns it to the Notes field. +// SetNotes gets a reference to the given string and assigns it to the Notes field. func (o *SensorsPatchRequest) SetNotes(v string) { - o.Notes.Set(&v) -} - -// SetNotesNil sets the value for Notes to be an explicit nil -func (o *SensorsPatchRequest) SetNotesNil() { - o.Notes.Set(nil) -} - -// UnsetNotes ensures that no value is present for Notes, not even an explicit nil -func (o *SensorsPatchRequest) UnsetNotes() { - o.Notes.Unset() + o.Notes = &v } // GetPcapMode returns the PcapMode field value if set, zero value otherwise. @@ -206,14 +184,14 @@ func (o SensorsPatchRequest) ToMap() (map[string]interface{}, error) { if !IsNil(o.Name) { toSerialize["name"] = o.Name } - if o.AddressNote.IsSet() { - toSerialize["address_note"] = o.AddressNote.Get() + if !IsNil(o.AddressNote) { + toSerialize["addressNote"] = o.AddressNote } - if o.Notes.IsSet() { - toSerialize["notes"] = o.Notes.Get() + if !IsNil(o.Notes) { + toSerialize["notes"] = o.Notes } if !IsNil(o.PcapMode) { - toSerialize["pcap_mode"] = o.PcapMode + toSerialize["pcapMode"] = o.PcapMode } return toSerialize, nil } diff --git a/pkg/config-api-client/model_sensors_patch_response.go b/pkg/config-api-client/model_sensors_patch_response.go index a8f9c518..27d0b853 100644 --- a/pkg/config-api-client/model_sensors_patch_response.go +++ b/pkg/config-api-client/model_sensors_patch_response.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_sensors_response.go b/pkg/config-api-client/model_sensors_response.go index d51e51bc..2b626e61 100644 --- a/pkg/config-api-client/model_sensors_response.go +++ b/pkg/config-api-client/model_sensors_response.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_service_test_.go b/pkg/config-api-client/model_service_test_.go index 2db7a91a..44f0572f 100644 --- a/pkg/config-api-client/model_service_test_.go +++ b/pkg/config-api-client/model_service_test_.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_service_test_group_assignments_item.go b/pkg/config-api-client/model_service_test_group_assignments_item.go index 8f51b348..9cf0fef2 100644 --- a/pkg/config-api-client/model_service_test_group_assignments_item.go +++ b/pkg/config-api-client/model_service_test_group_assignments_item.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_service_test_group_assignments_post_request.go b/pkg/config-api-client/model_service_test_group_assignments_post_request.go index 7028a49c..462e66a9 100644 --- a/pkg/config-api-client/model_service_test_group_assignments_post_request.go +++ b/pkg/config-api-client/model_service_test_group_assignments_post_request.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_service_test_group_assignments_post_response.go b/pkg/config-api-client/model_service_test_group_assignments_post_response.go index 15841622..a8f2c406 100644 --- a/pkg/config-api-client/model_service_test_group_assignments_post_response.go +++ b/pkg/config-api-client/model_service_test_group_assignments_post_response.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_service_test_group_assignments_response.go b/pkg/config-api-client/model_service_test_group_assignments_response.go index ed55669f..03f0b6d9 100644 --- a/pkg/config-api-client/model_service_test_group_assignments_response.go +++ b/pkg/config-api-client/model_service_test_group_assignments_response.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_service_tests_list_item.go b/pkg/config-api-client/model_service_tests_list_item.go index 29e0c943..62375918 100644 --- a/pkg/config-api-client/model_service_tests_list_item.go +++ b/pkg/config-api-client/model_service_tests_list_item.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_service_tests_list_response.go b/pkg/config-api-client/model_service_tests_list_response.go index a00afb11..213e2b0c 100644 --- a/pkg/config-api-client/model_service_tests_list_response.go +++ b/pkg/config-api-client/model_service_tests_list_response.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_wired_networks_item.go b/pkg/config-api-client/model_wired_networks_item.go index 6832b942..73a219a8 100644 --- a/pkg/config-api-client/model_wired_networks_item.go +++ b/pkg/config-api-client/model_wired_networks_item.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_wired_networks_response.go b/pkg/config-api-client/model_wired_networks_response.go index e1f26bd9..8f4e171b 100644 --- a/pkg/config-api-client/model_wired_networks_response.go +++ b/pkg/config-api-client/model_wired_networks_response.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_wireless_networks_item.go b/pkg/config-api-client/model_wireless_networks_item.go index 3b581929..c05f2e4d 100644 --- a/pkg/config-api-client/model_wireless_networks_item.go +++ b/pkg/config-api-client/model_wireless_networks_item.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/model_wireless_networks_response.go b/pkg/config-api-client/model_wireless_networks_response.go index 194f210b..0edde116 100644 --- a/pkg/config-api-client/model_wireless_networks_response.go +++ b/pkg/config-api-client/model_wireless_networks_response.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/response.go b/pkg/config-api-client/response.go index 3239c83b..2c309448 100644 --- a/pkg/config-api-client/response.go +++ b/pkg/config-api-client/response.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/pkg/config-api-client/test/api_configuration_test.go b/pkg/config-api-client/test/api_configuration_test.go index 86abec6e..0d9bd3fd 100644 --- a/pkg/config-api-client/test/api_configuration_test.go +++ b/pkg/config-api-client/test/api_configuration_test.go @@ -2,10 +2,11 @@ package config_api_client import ( "context" + "net/http" "testing" "time" - openapiclient "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" "github.com/h2non/gock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -13,10 +14,10 @@ import ( func TestConfigurationAPI(t *testing.T) { - configuration := openapiclient.NewConfiguration() + configuration := config_api_client.NewConfiguration() configuration.Host = "localhost:80" configuration.Scheme = "http" - apiClient := openapiclient.NewAPIClient(configuration) + apiClient := config_api_client.NewAPIClient(configuration) defer gock.Off() @@ -24,7 +25,7 @@ func TestConfigurationAPI(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Get("/networking-uxi/v1alpha1/agents"). MatchParams(map[string]string{"id": "uid", "limit": "10", "next": "some-cursor"}). - Reply(200). + Reply(http.StatusOK). JSON(map[string]interface{}{ "items": []map[string]interface{}{ { @@ -56,37 +57,87 @@ func TestConfigurationAPI(t *testing.T) { pcapMode := "pcap_mode" require.Nil(t, err) - assert.Equal(t, 200, httpRes.StatusCode) - assert.Equal(t, resp, &openapiclient.AgentsResponse{ - Items: []openapiclient.AgentItem{ + assert.Equal(t, http.StatusOK, httpRes.StatusCode) + assert.Equal(t, resp, &config_api_client.AgentsResponse{ + Items: []config_api_client.AgentItem{ { Id: "uid", Serial: "serial", Name: "name", - ModelNumber: *openapiclient.NewNullableString(&modelNumber), - WifiMacAddress: *openapiclient.NewNullableString(&wifiMacAddress), - EthernetMacAddress: *openapiclient.NewNullableString(ðernetMacAddress), - Notes: *openapiclient.NewNullableString(¬es), - PcapMode: *openapiclient.NewNullableString(&pcapMode), + ModelNumber: *config_api_client.NewNullableString(&modelNumber), + WifiMacAddress: *config_api_client.NewNullableString(&wifiMacAddress), + EthernetMacAddress: *config_api_client.NewNullableString(ðernetMacAddress), + Notes: *config_api_client.NewNullableString(¬es), + PcapMode: *config_api_client.NewNullableString(&pcapMode), Type: "networking-uxi/sensor", }, }, - Next: *openapiclient.NewNullableString(nil), + Next: *config_api_client.NewNullableString(nil), Count: 1, }) }) + t.Run("Test ConfigurationAPI AgentsPatchRequest", func(t *testing.T) { + gock.New(configuration.Scheme+"://"+configuration.Host). + Patch("/networking-uxi/v1alpha1/agents/uid"). + MatchHeader("Content-Type", "application/merge-patch+json"). + JSON(map[string]interface{}{"name": "new_name", "notes": "new_notes", "pcapMode": "off"}). + Reply(http.StatusOK). + JSON(map[string]interface{}{ + "id": "uid", + "serial": "serial", + "name": "new_name", + "modelNumber": "model_number", + "wifiMacAddress": "wifi_mac_address", + "ethernetMacAddress": "ethernet_mac_address", + "notes": "new_notes", + "pcapMode": "off", + "type": "networking-uxi/agent", + }, + ) + name := "new_name" + notes := "new_notes" + pcapMode := "off" + agentsPatchRequest := config_api_client.AgentsPatchRequest{ + Name: &name, + Notes: ¬es, + PcapMode: &pcapMode, + } + resp, httpRes, err := apiClient.ConfigurationAPI. + AgentsPatch(context.Background(), "uid"). + AgentsPatchRequest(agentsPatchRequest). + Execute() + + wifiMacAddress := "wifi_mac_address" + ethernetMacAddress := "ethernet_mac_address" + modelNumber := "model_number" + + require.Nil(t, err) + assert.Equal(t, http.StatusOK, httpRes.StatusCode) + assert.Equal(t, resp, &config_api_client.AgentsPatchResponse{ + Id: "uid", + Serial: "serial", + Name: "new_name", + ModelNumber: *config_api_client.NewNullableString(&modelNumber), + WifiMacAddress: *config_api_client.NewNullableString(&wifiMacAddress), + EthernetMacAddress: *config_api_client.NewNullableString(ðernetMacAddress), + Notes: *config_api_client.NewNullableString(¬es), + PcapMode: *config_api_client.NewNullableString(&pcapMode), + Type: "networking-uxi/agent", + }) + }) + t.Run("Test ConfigurationAPI AgentsDelete", func(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Delete("/networking-uxi/v1alpha1/agents/uid"). - Reply(204) + Reply(http.StatusNoContent) _, httpRes, err := apiClient.ConfigurationAPI. AgentsDelete(context.Background(), "uid"). Execute() require.Nil(t, err) - assert.Equal(t, 204, httpRes.StatusCode) + assert.Equal(t, http.StatusNoContent, httpRes.StatusCode) }) t.Run("Test ConfigurationAPI GroupsGet", func(t *testing.T) { @@ -94,7 +145,7 @@ func TestConfigurationAPI(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Get("/networking-uxi/v1alpha1/groups"). MatchParams(map[string]string{"id": "uid", "limit": "10", "next": "some-cursor"}). - Reply(200). + Reply(http.StatusOK). JSON(map[string]interface{}{ "items": []map[string]interface{}{ { @@ -116,18 +167,18 @@ func TestConfigurationAPI(t *testing.T) { Execute() require.Nil(t, err) - assert.Equal(t, 200, httpRes.StatusCode) - assert.Equal(t, resp, &openapiclient.GroupsGetResponse{ - Items: []openapiclient.GroupsGetItem{ + assert.Equal(t, http.StatusOK, httpRes.StatusCode) + assert.Equal(t, resp, &config_api_client.GroupsGetResponse{ + Items: []config_api_client.GroupsGetItem{ { Id: "uid", Name: "name", - Parent: *openapiclient.NewNullableParent(openapiclient.NewParent("parent_uid")), + Parent: *config_api_client.NewNullableParent(config_api_client.NewParent("parent_uid")), Path: "root_uid.parent_uid.uid", Type: "networking-uxi/group", }, }, - Next: *openapiclient.NewNullableString(nil), + Next: *config_api_client.NewNullableString(nil), Count: 1, }) }) @@ -140,7 +191,7 @@ func TestConfigurationAPI(t *testing.T) { "name": "name", "parentId": "parent.uid", }). - Reply(200). + Reply(http.StatusOK). JSON(map[string]interface{}{ "id": "node", "name": "name", @@ -148,18 +199,18 @@ func TestConfigurationAPI(t *testing.T) { "path": "parent.uid.node", "type": "networking-uxi/group", }) - groupsPostRequest := openapiclient.NewGroupsPostRequest("name") + groupsPostRequest := config_api_client.NewGroupsPostRequest("name") groupsPostRequest.SetParentId("parent.uid") resp, httpRes, err := apiClient.ConfigurationAPI. GroupsPost(context.Background()). GroupsPostRequest(*groupsPostRequest).Execute() require.Nil(t, err) - assert.Equal(t, 200, httpRes.StatusCode) - assert.Equal(t, resp, &openapiclient.GroupsPostResponse{ + assert.Equal(t, http.StatusOK, httpRes.StatusCode) + assert.Equal(t, resp, &config_api_client.GroupsPostResponse{ Id: "node", Name: "name", - Parent: *openapiclient.NewParent("parent.uid"), + Parent: *config_api_client.NewParent("parent.uid"), Path: "parent.uid.node", Type: "networking-uxi/group", }) @@ -169,7 +220,7 @@ func TestConfigurationAPI(t *testing.T) { gock.New(configuration.Scheme+"://"+configuration.Host). Patch("/networking-uxi/v1alpha1/groups/node"). MatchHeader("Content-Type", "application/merge-patch+json"). - Reply(200). + Reply(http.StatusOK). JSON(map[string]interface{}{ "id": "node", "name": "new_name", @@ -177,17 +228,17 @@ func TestConfigurationAPI(t *testing.T) { "path": "parent.uid.node", "type": "networking-uxi/group", }) - groupsPatchRequest := openapiclient.NewGroupsPatchRequest("new_name") + groupsPatchRequest := config_api_client.NewGroupsPatchRequest("new_name") resp, httpRes, err := apiClient.ConfigurationAPI. GroupsPatch(context.Background(), "node"). GroupsPatchRequest(*groupsPatchRequest).Execute() require.Nil(t, err) - assert.Equal(t, 200, httpRes.StatusCode) - assert.Equal(t, resp, &openapiclient.GroupsPatchResponse{ + assert.Equal(t, http.StatusOK, httpRes.StatusCode) + assert.Equal(t, resp, &config_api_client.GroupsPatchResponse{ Id: "node", Name: "new_name", - Parent: *openapiclient.NewParent("parent.uid"), + Parent: *config_api_client.NewParent("parent.uid"), Path: "parent.uid.node", Type: "networking-uxi/group", }) @@ -196,21 +247,21 @@ func TestConfigurationAPI(t *testing.T) { t.Run("Test ConfigurationAPI GroupsDelete", func(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Delete("/networking-uxi/v1alpha1/groups/uid"). - Reply(204) + Reply(http.StatusNoContent) _, httpRes, err := apiClient.ConfigurationAPI. GroupsDelete(context.Background(), "uid"). Execute() require.Nil(t, err) - assert.Equal(t, 204, httpRes.StatusCode) + assert.Equal(t, http.StatusNoContent, httpRes.StatusCode) }) t.Run("Test ConfigurationAPI SensorsGet", func(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Get("/networking-uxi/v1alpha1/sensors"). MatchParams(map[string]string{"id": "uid", "limit": "10", "next": "some-cursor"}). - Reply(200). + Reply(http.StatusOK). JSON(map[string]interface{}{ "items": []map[string]interface{}{ { @@ -248,37 +299,35 @@ func TestConfigurationAPI(t *testing.T) { PcapMode := "pcap_mode" require.Nil(t, err) - assert.Equal(t, 200, httpRes.StatusCode) - assert.Equal(t, resp, &openapiclient.SensorsResponse{ - Items: []openapiclient.SensorItem{ + assert.Equal(t, http.StatusOK, httpRes.StatusCode) + assert.Equal(t, resp, &config_api_client.SensorsResponse{ + Items: []config_api_client.SensorItem{ { Id: "uid", Serial: "serial", Name: "name", ModelNumber: "model_number", - WifiMacAddress: *openapiclient.NewNullableString(&WifiMacAddress), - EthernetMacAddress: *openapiclient.NewNullableString(&EthernetMacAddress), - AddressNote: *openapiclient.NewNullableString(&AddressNote), - Longitude: *openapiclient.NewNullableFloat32(&Longitude), - Latitude: *openapiclient.NewNullableFloat32(&Latitude), - Notes: *openapiclient.NewNullableString(&Notes), - PcapMode: *openapiclient.NewNullableString(&PcapMode), + WifiMacAddress: *config_api_client.NewNullableString(&WifiMacAddress), + EthernetMacAddress: *config_api_client.NewNullableString(&EthernetMacAddress), + AddressNote: *config_api_client.NewNullableString(&AddressNote), + Longitude: *config_api_client.NewNullableFloat32(&Longitude), + Latitude: *config_api_client.NewNullableFloat32(&Latitude), + Notes: *config_api_client.NewNullableString(&Notes), + PcapMode: *config_api_client.NewNullableString(&PcapMode), Type: "networking-uxi/sensor", }, }, - Next: *openapiclient.NewNullableString(nil), + Next: *config_api_client.NewNullableString(nil), Count: 1, }) }) - t.Run("Test ConfigurationAPI GroupsPatch", func(t *testing.T) { - gock.New(configuration.Scheme + "://" + configuration.Host). + t.Run("Test ConfigurationAPI SensorsPatchRequest", func(t *testing.T) { + gock.New(configuration.Scheme+"://"+configuration.Host). Patch("/networking-uxi/v1alpha1/sensors/uid"). - // TODO: uncomment this once spec has been updated to merge-patch+json - // MatchHeader("Content-Type", "application/merge-patch+json"). - // TODO: Change these fields to camelCase once the spec has been updated - BodyString(`{"name":"new_name","address_note":"new_address_note","notes":"new_notes","pcap_mode":"off"}`). - Reply(200). + MatchHeader("Content-Type", "application/merge-patch+json"). + JSON(map[string]interface{}{"name": "new_name", "addressNote": "new_address_note", "notes": "new_notes", "pcapMode": "off"}). + Reply(http.StatusOK). JSON(map[string]interface{}{ "id": "uid", "serial": "serial", @@ -298,10 +347,10 @@ func TestConfigurationAPI(t *testing.T) { addressNote := "new_address_note" notes := "new_notes" pcapMode := "off" - sensorsPatchRequest := openapiclient.SensorsPatchRequest{ + sensorsPatchRequest := config_api_client.SensorsPatchRequest{ Name: &name, - AddressNote: *openapiclient.NewNullableString(&addressNote), - Notes: *openapiclient.NewNullableString(¬es), + AddressNote: &addressNote, + Notes: ¬es, PcapMode: &pcapMode, } resp, httpRes, err := apiClient.ConfigurationAPI. @@ -315,19 +364,19 @@ func TestConfigurationAPI(t *testing.T) { var latitude float32 = 0.0 require.Nil(t, err) - assert.Equal(t, 200, httpRes.StatusCode) - assert.Equal(t, resp, &openapiclient.SensorsPatchResponse{ + assert.Equal(t, http.StatusOK, httpRes.StatusCode) + assert.Equal(t, resp, &config_api_client.SensorsPatchResponse{ Id: "uid", Serial: "serial", Name: "new_name", ModelNumber: "model_number", - WifiMacAddress: *openapiclient.NewNullableString(&wifiMacAddress), - EthernetMacAddress: *openapiclient.NewNullableString(ðernetMacAddress), - AddressNote: *openapiclient.NewNullableString(&addressNote), - Longitude: *openapiclient.NewNullableFloat32(&longitude), - Latitude: *openapiclient.NewNullableFloat32(&latitude), - Notes: *openapiclient.NewNullableString(¬es), - PcapMode: *openapiclient.NewNullableString(&pcapMode), + WifiMacAddress: *config_api_client.NewNullableString(&wifiMacAddress), + EthernetMacAddress: *config_api_client.NewNullableString(ðernetMacAddress), + AddressNote: *config_api_client.NewNullableString(&addressNote), + Longitude: *config_api_client.NewNullableFloat32(&longitude), + Latitude: *config_api_client.NewNullableFloat32(&latitude), + Notes: *config_api_client.NewNullableString(¬es), + PcapMode: *config_api_client.NewNullableString(&pcapMode), Type: "networking-uxi/sensor", }) }) @@ -337,7 +386,7 @@ func TestConfigurationAPI(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Get("/networking-uxi/v1alpha1/agent-group-assignments"). MatchParams(map[string]string{"id": "uid", "limit": "10", "next": "some-cursor"}). - Reply(200). + Reply(http.StatusOK). JSON(map[string]interface{}{ "items": []map[string]interface{}{ { @@ -358,18 +407,18 @@ func TestConfigurationAPI(t *testing.T) { Execute() require.Nil(t, err) - assert.Equal(t, 200, httpRes.StatusCode) - assert.Equal(t, resp, &openapiclient.AgentGroupAssignmentsResponse{ - Items: []openapiclient.AgentGroupAssignmentsItem{ + assert.Equal(t, http.StatusOK, httpRes.StatusCode) + assert.Equal(t, resp, &config_api_client.AgentGroupAssignmentsResponse{ + Items: []config_api_client.AgentGroupAssignmentsItem{ { Id: "uid", - Group: *openapiclient.NewGroup("group_uid"), - Agent: *openapiclient.NewAgent("agent_uid"), + Group: *config_api_client.NewGroup("group_uid"), + Agent: *config_api_client.NewAgent("agent_uid"), Type: "networking-uxi/agent-group-assignment", }, }, Count: 1, - Next: *openapiclient.NewNullableString(nil), + Next: *config_api_client.NewNullableString(nil), }) }) @@ -381,7 +430,7 @@ func TestConfigurationAPI(t *testing.T) { "groupId": "group_uid", "agentId": "agent_uid", }). - Reply(200). + Reply(http.StatusOK). JSON(map[string]interface{}{ "id": "uid", "group": map[string]string{"id": "group_uid"}, @@ -389,28 +438,44 @@ func TestConfigurationAPI(t *testing.T) { "type": "networking-uxi/agent-group-assignment", }) - postRequest := openapiclient.NewAgentGroupAssignmentsPostRequest("group_uid", "agent_uid") + postRequest := config_api_client.NewAgentGroupAssignmentsPostRequest( + "group_uid", + "agent_uid", + ) resp, httpRes, err := apiClient.ConfigurationAPI. AgentGroupAssignmentsPost(context.Background()). AgentGroupAssignmentsPostRequest(*postRequest). Execute() require.Nil(t, err) - assert.Equal(t, 200, httpRes.StatusCode) - assert.Equal(t, resp, &openapiclient.AgentGroupAssignmentResponse{ + assert.Equal(t, http.StatusOK, httpRes.StatusCode) + assert.Equal(t, resp, &config_api_client.AgentGroupAssignmentResponse{ Id: "uid", - Group: *openapiclient.NewGroup("group_uid"), - Agent: *openapiclient.NewAgent("agent_uid"), + Group: *config_api_client.NewGroup("group_uid"), + Agent: *config_api_client.NewAgent("agent_uid"), Type: "networking-uxi/agent-group-assignment", }) }) + t.Run("Test ConfigurationAPI AgentGroupAssignmentDelete", func(t *testing.T) { + gock.New(configuration.Scheme + "://" + configuration.Host). + Delete("/networking-uxi/v1alpha1/agent-group-assignments/uid"). + Reply(http.StatusNoContent) + + _, httpRes, err := apiClient.ConfigurationAPI. + AgentGroupAssignmentDelete(context.Background(), "uid"). + Execute() + + require.Nil(t, err) + assert.Equal(t, http.StatusNoContent, httpRes.StatusCode) + }) + t.Run("Test ConfigurationAPI SensorGroupAssignmentsGet", func(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Get("/networking-uxi/v1alpha1/sensor-group-assignments"). MatchParams(map[string]string{"id": "uid", "limit": "10", "next": "some-cursor"}). - Reply(200). + Reply(http.StatusOK). JSON(map[string]interface{}{ "items": []map[string]interface{}{ { @@ -431,18 +496,18 @@ func TestConfigurationAPI(t *testing.T) { Execute() require.Nil(t, err) - assert.Equal(t, 200, httpRes.StatusCode) - assert.Equal(t, resp, &openapiclient.SensorGroupAssignmentsResponse{ - Items: []openapiclient.SensorGroupAssignmentsItem{ + assert.Equal(t, http.StatusOK, httpRes.StatusCode) + assert.Equal(t, resp, &config_api_client.SensorGroupAssignmentsResponse{ + Items: []config_api_client.SensorGroupAssignmentsItem{ { Id: "uid", - Group: *openapiclient.NewGroup("group_uid"), - Sensor: *openapiclient.NewSensor("sensor_uid"), + Group: *config_api_client.NewGroup("group_uid"), + Sensor: *config_api_client.NewSensor("sensor_uid"), Type: "networking-uxi/sensor-group-assignment", }, }, Count: 1, - Next: *openapiclient.NewNullableString(nil), + Next: *config_api_client.NewNullableString(nil), }) }) @@ -454,7 +519,7 @@ func TestConfigurationAPI(t *testing.T) { "groupId": "group_uid", "sensorId": "sensor_uid", }). - Reply(200). + Reply(http.StatusOK). JSON(map[string]interface{}{ "id": "uid", "group": map[string]string{"id": "group_uid"}, @@ -462,18 +527,21 @@ func TestConfigurationAPI(t *testing.T) { "type": "networking-uxi/sensor-group-assignment", }) - postRequest := openapiclient.NewSensorGroupAssignmentsPostRequest("group_uid", "sensor_uid") + postRequest := config_api_client.NewSensorGroupAssignmentsPostRequest( + "group_uid", + "sensor_uid", + ) resp, httpRes, err := apiClient.ConfigurationAPI. SensorGroupAssignmentsPost(context.Background()). SensorGroupAssignmentsPostRequest(*postRequest). Execute() require.Nil(t, err) - assert.Equal(t, 200, httpRes.StatusCode) - assert.Equal(t, resp, &openapiclient.SensorGroupAssignmentResponse{ + assert.Equal(t, http.StatusOK, httpRes.StatusCode) + assert.Equal(t, resp, &config_api_client.SensorGroupAssignmentResponse{ Id: "uid", - Group: *openapiclient.NewGroup("group_uid"), - Sensor: *openapiclient.NewSensor("sensor_uid"), + Group: *config_api_client.NewGroup("group_uid"), + Sensor: *config_api_client.NewSensor("sensor_uid"), Type: "networking-uxi/sensor-group-assignment", }) }) @@ -481,14 +549,14 @@ func TestConfigurationAPI(t *testing.T) { t.Run("Test ConfigurationAPI SensorGroupAssignmentsDelete", func(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Delete("/networking-uxi/v1alpha1/sensor-group-assignments/uid"). - Reply(204) + Reply(http.StatusNoContent) _, httpRes, err := apiClient.ConfigurationAPI. SensorGroupAssignmentsDelete(context.Background(), "uid"). Execute() require.Nil(t, err) - assert.Equal(t, 204, httpRes.StatusCode) + assert.Equal(t, http.StatusNoContent, httpRes.StatusCode) }) t.Run("Test ConfigurationAPI WiredNetworksGet", func(t *testing.T) { @@ -496,7 +564,7 @@ func TestConfigurationAPI(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Get("/networking-uxi/v1alpha1/wired-networks"). MatchParams(map[string]string{"id": "uid", "limit": "10", "next": "some-cursor"}). - Reply(200). + Reply(http.StatusOK). JSON(map[string]interface{}{ "items": []map[string]interface{}{ { @@ -529,26 +597,26 @@ func TestConfigurationAPI(t *testing.T) { var vlanId int32 = 1 require.Nil(t, err) - assert.Equal(t, 200, httpRes.StatusCode) - assert.Equal(t, resp, &openapiclient.WiredNetworksResponse{ - Items: []openapiclient.WiredNetworksItem{ + assert.Equal(t, http.StatusOK, httpRes.StatusCode) + assert.Equal(t, resp, &config_api_client.WiredNetworksResponse{ + Items: []config_api_client.WiredNetworksItem{ { Id: "uid", Name: "alias", IpVersion: "ip_version", UpdatedAt: time.Date(2024, 9, 11, 12, 0, 0, 0, time.UTC), CreatedAt: time.Date(2024, 9, 11, 12, 0, 0, 0, time.UTC), - Security: *openapiclient.NewNullableString(&security), - DnsLookupDomain: *openapiclient.NewNullableString(&dnsLookupDomain), + Security: *config_api_client.NewNullableString(&security), + DnsLookupDomain: *config_api_client.NewNullableString(&dnsLookupDomain), DisableEdns: true, UseDns64: false, ExternalConnectivity: true, - VLanId: *openapiclient.NewNullableInt32(&vlanId), + VLanId: *config_api_client.NewNullableInt32(&vlanId), Type: "networking-uxi/wired-network", }, }, Count: 1, - Next: *openapiclient.NewNullableString(nil), + Next: *config_api_client.NewNullableString(nil), }) }) @@ -557,7 +625,7 @@ func TestConfigurationAPI(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Get("/networking-uxi/v1alpha1/wireless-networks"). MatchParams(map[string]string{"id": "uid", "limit": "10", "next": "some-cursor"}). - Reply(200). + Reply(http.StatusOK). JSON(map[string]interface{}{ "items": []map[string]interface{}{ { @@ -591,20 +659,20 @@ func TestConfigurationAPI(t *testing.T) { dnsLookupDomain := "dns_lookup_domain" require.Nil(t, err) - assert.Equal(t, 200, httpRes.StatusCode) - assert.Equal(t, resp, &openapiclient.WirelessNetworksResponse{ - Items: []openapiclient.WirelessNetworksItem{ + assert.Equal(t, http.StatusOK, httpRes.StatusCode) + assert.Equal(t, resp, &config_api_client.WirelessNetworksResponse{ + Items: []config_api_client.WirelessNetworksItem{ { Id: "uid", Name: "alias", Ssid: "ssid", - Security: *openapiclient.NewNullableString(&security), + Security: *config_api_client.NewNullableString(&security), IpVersion: "ip_version", CreatedAt: time.Date(2024, 9, 11, 12, 0, 0, 0, time.UTC), UpdatedAt: time.Date(2024, 9, 11, 12, 0, 0, 0, time.UTC), Hidden: false, BandLocking: "band_locking", - DnsLookupDomain: *openapiclient.NewNullableString(&dnsLookupDomain), + DnsLookupDomain: *config_api_client.NewNullableString(&dnsLookupDomain), DisableEdns: true, UseDns64: false, ExternalConnectivity: true, @@ -612,7 +680,7 @@ func TestConfigurationAPI(t *testing.T) { }, }, Count: 1, - Next: *openapiclient.NewNullableString(nil), + Next: *config_api_client.NewNullableString(nil), }) }) @@ -621,7 +689,7 @@ func TestConfigurationAPI(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Get("/networking-uxi/v1alpha1/network-group-assignments"). MatchParams(map[string]string{"id": "uid", "limit": "10", "next": "some-cursor"}). - Reply(200). + Reply(http.StatusOK). JSON(map[string]interface{}{ "items": []map[string]interface{}{ { @@ -642,18 +710,18 @@ func TestConfigurationAPI(t *testing.T) { Execute() require.Nil(t, err) - assert.Equal(t, 200, httpRes.StatusCode) - assert.Equal(t, resp, &openapiclient.NetworkGroupAssignmentsResponse{ - Items: []openapiclient.NetworkGroupAssignmentsItem{ + assert.Equal(t, http.StatusOK, httpRes.StatusCode) + assert.Equal(t, resp, &config_api_client.NetworkGroupAssignmentsResponse{ + Items: []config_api_client.NetworkGroupAssignmentsItem{ { Id: "uid", - Group: *openapiclient.NewGroup("group_uid"), - Network: *openapiclient.NewNetwork("network_uid"), + Group: *config_api_client.NewGroup("group_uid"), + Network: *config_api_client.NewNetwork("network_uid"), Type: "networking-uxi/network-group-assignment", }, }, Count: 1, - Next: *openapiclient.NewNullableString(nil), + Next: *config_api_client.NewNullableString(nil), }) }) @@ -665,7 +733,7 @@ func TestConfigurationAPI(t *testing.T) { "groupId": "group_uid", "networkId": "network_uid", }). - Reply(200). + Reply(http.StatusOK). JSON(map[string]interface{}{ "id": "uid", "group": map[string]string{"id": "group_uid"}, @@ -673,7 +741,7 @@ func TestConfigurationAPI(t *testing.T) { "type": "networking-uxi/network-group-assignment", }) - postRequest := openapiclient.NewNetworkGroupAssignmentsPostRequest( + postRequest := config_api_client.NewNetworkGroupAssignmentsPostRequest( "group_uid", "network_uid", ) @@ -683,11 +751,11 @@ func TestConfigurationAPI(t *testing.T) { Execute() require.Nil(t, err) - assert.Equal(t, 200, httpRes.StatusCode) - assert.Equal(t, resp, &openapiclient.NetworkGroupAssignmentsPostResponse{ + assert.Equal(t, http.StatusOK, httpRes.StatusCode) + assert.Equal(t, resp, &config_api_client.NetworkGroupAssignmentsPostResponse{ Id: "uid", - Group: *openapiclient.NewGroup("group_uid"), - Network: *openapiclient.NewNetwork("network_uid"), + Group: *config_api_client.NewGroup("group_uid"), + Network: *config_api_client.NewNetwork("network_uid"), Type: "networking-uxi/network-group-assignment", }) }) @@ -695,14 +763,14 @@ func TestConfigurationAPI(t *testing.T) { t.Run("Test ConfigurationAPI NetworkGroupAssignmentsDelete", func(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Delete("/networking-uxi/v1alpha1/network-group-assignments/uid"). - Reply(204) + Reply(http.StatusNoContent) _, httpRes, err := apiClient.ConfigurationAPI. NetworkGroupAssignmentsDelete(context.Background(), "uid"). Execute() require.Nil(t, err) - assert.Equal(t, 204, httpRes.StatusCode) + assert.Equal(t, http.StatusNoContent, httpRes.StatusCode) }) t.Run("Test ConfigurationAPI ServiceTestGroupAssignmentsGet", func(t *testing.T) { @@ -710,7 +778,7 @@ func TestConfigurationAPI(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Get("/networking-uxi/v1alpha1/service-test-group-assignments"). MatchParams(map[string]string{"id": "uid", "limit": "10", "next": "some-cursor"}). - Reply(200). + Reply(http.StatusOK). JSON(map[string]interface{}{ "items": []map[string]interface{}{ { @@ -731,18 +799,18 @@ func TestConfigurationAPI(t *testing.T) { Execute() require.Nil(t, err) - assert.Equal(t, 200, httpRes.StatusCode) - assert.Equal(t, resp, &openapiclient.ServiceTestGroupAssignmentsResponse{ - Items: []openapiclient.ServiceTestGroupAssignmentsItem{ + assert.Equal(t, http.StatusOK, httpRes.StatusCode) + assert.Equal(t, resp, &config_api_client.ServiceTestGroupAssignmentsResponse{ + Items: []config_api_client.ServiceTestGroupAssignmentsItem{ { Id: "uid", - Group: *openapiclient.NewGroup("group_uid"), - ServiceTest: *openapiclient.NewServiceTest("service_test_uid"), + Group: *config_api_client.NewGroup("group_uid"), + ServiceTest: *config_api_client.NewServiceTest("service_test_uid"), Type: "networking-uxi/service-test-group-assignment", }, }, Count: 1, - Next: *openapiclient.NewNullableString(nil), + Next: *config_api_client.NewNullableString(nil), }) }) @@ -754,7 +822,7 @@ func TestConfigurationAPI(t *testing.T) { "groupId": "group_uid", "serviceTestId": "service_test_uid", }). - Reply(200). + Reply(http.StatusOK). JSON(map[string]interface{}{ "id": "uid", "group": map[string]string{"id": "group_uid"}, @@ -762,7 +830,7 @@ func TestConfigurationAPI(t *testing.T) { "type": "networking-uxi/service-test-group-assignment", }) - postRequest := openapiclient.NewServiceTestGroupAssignmentsPostRequest( + postRequest := config_api_client.NewServiceTestGroupAssignmentsPostRequest( "group_uid", "service_test_uid", ) @@ -772,11 +840,11 @@ func TestConfigurationAPI(t *testing.T) { Execute() require.Nil(t, err) - assert.Equal(t, 200, httpRes.StatusCode) - assert.Equal(t, resp, &openapiclient.ServiceTestGroupAssignmentsPostResponse{ + assert.Equal(t, http.StatusOK, httpRes.StatusCode) + assert.Equal(t, resp, &config_api_client.ServiceTestGroupAssignmentsPostResponse{ Id: "uid", - Group: *openapiclient.NewGroup("group_uid"), - ServiceTest: *openapiclient.NewServiceTest("service_test_uid"), + Group: *config_api_client.NewGroup("group_uid"), + ServiceTest: *config_api_client.NewServiceTest("service_test_uid"), Type: "networking-uxi/service-test-group-assignment", }) }) @@ -785,13 +853,13 @@ func TestConfigurationAPI(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Delete("/networking-uxi/v1alpha1/service-test-group-assignments/uid"). - Reply(204) + Reply(http.StatusNoContent) _, httpRes, err := apiClient.ConfigurationAPI. ServiceTestGroupAssignmentsDelete(context.Background(), "uid"). Execute() require.Nil(t, err) - assert.Equal(t, 204, httpRes.StatusCode) + assert.Equal(t, http.StatusNoContent, httpRes.StatusCode) }) } diff --git a/pkg/config-api-client/utils.go b/pkg/config-api-client/utils.go index 47f82b36..12f75903 100644 --- a/pkg/config-api-client/utils.go +++ b/pkg/config-api-client/utils.go @@ -3,7 +3,7 @@ Configuration Api Nice description goes here -API version: 5.6.0 +API version: 5.10.0 Contact: support@capenetworks.com */ diff --git a/test/live/config/config.go b/test/live/config/config.go index ddd9a23e..0abcdc0b 100644 --- a/test/live/config/config.go +++ b/test/live/config/config.go @@ -1,8 +1,19 @@ package config -const WiredNetworkUid = "ethernet-0ee5b46c2ef0" +// These constants are from the customer: +// Configuration-API Acceptance Testing (844457745a1111ef880836000a52e73e) +// And therefore the client_id and client_secret used for the acceptance tests must match this +// customer. +const AgentPermanentId = "8260f349-5c73-394a-b786-57985d001763" +const AgentCreateSerial = "56fb38331f19d278" +const CustomerId = "9c16d493-7649-40bc-975b-07422d227c0b" +const GroupIdRoot = "07422d227c0b" +const WiredNetworkId = "ethernet-0ee5b46c2ef0" const WiredNetworkName = "tf-provider-acceptance-tests-ethernet-0" -const WirelessNetworkUid = "ssid-bf704ff37dc0" +const WirelessNetworkId = "ssid-bf704ff37dc0" const WirelessNetworkName = "tf-provider-acceptance-tests-ssid-0" -const ServiceTestUid = "6f81e43d-76f1-4a15-aafe-4ce2371d918a" +const ServiceTestId = "6f81e43d-76f1-4a15-aafe-4ce2371d918a" const ServiceTestName = "tf-provider-acceptance-test-0" +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 new file mode 100644 index 00000000..693682b4 --- /dev/null +++ b/test/live/datasources/agent_group_assignment_test.go @@ -0,0 +1,58 @@ +package data_source_test + +import ( + "testing" + + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/util" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" +) + +func TestAgentGroupAssignmentDataSource(t *testing.T) { + const groupName = "tf_provider_acceptance_test_agent_group_assignment_datasource" + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: provider.ProviderConfig + ` + // create the resource to be used as a datasource + resource "uxi_group" "my_group" { + name = "` + groupName + `" + } + + data "uxi_agent" "my_agent" { + filter = { + agent_id = "` + config.AgentPermanentId + `" + } + } + + resource "uxi_agent_group_assignment" "my_agent_group_assignment" { + agent_id = data.uxi_agent.my_agent.id + group_id = uxi_group.my_group.id + } + + // the actual datasource + data "uxi_agent_group_assignment" "my_agent_group_assignment" { + filter = { + agent_group_assignment_id = uxi_agent_group_assignment.my_agent_group_assignment.id + } + } + `, + Check: resource.ComposeTestCheckFunc( + 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", + util.GetAgentGroupAssignment(rs.Primary.ID), + )(s) + }, + ), + }, + }, + }) +} diff --git a/test/live/datasources/agent_test.go b/test/live/datasources/agent_test.go new file mode 100644 index 00000000..a300ec54 --- /dev/null +++ b/test/live/datasources/agent_test.go @@ -0,0 +1,29 @@ +package data_source_test + +import ( + "testing" + + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/util" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAgentDataSource(t *testing.T) { + agent := util.GetAgentProperties(config.AgentPermanentId) + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: provider.ProviderConfig + ` + data "uxi_agent" "my_agent" { + filter = { + agent_id = "` + config.AgentPermanentId + `" + } + } + `, + Check: util.CheckStateAgainstAgent(t, agent), + }, + }, + }) +} diff --git a/test/live/datasources/group_test.go b/test/live/datasources/group_test.go new file mode 100644 index 00000000..7906a25c --- /dev/null +++ b/test/live/datasources/group_test.go @@ -0,0 +1,70 @@ +package data_source_test + +import ( + "regexp" + "testing" + + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/util" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/nbio/st" +) + +func TestGroupDataSource(t *testing.T) { + groupName := "tf_provider_acceptance_test_group_datasource" + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: provider.ProviderConfig + ` + data "uxi_group" "my_group" { + filter = { + group_id = "` + config.GroupIdRoot + `" + } + } + `, + ExpectError: regexp.MustCompile(`The root group cannot be used as a data source`), + }, + { + Config: provider.ProviderConfig + ` + // create the resource to use subsequently as datasource + resource "uxi_group" "my_group_resource" { + name = "` + groupName + `" + } + + data "uxi_group" "my_group" { + filter = { + group_id = uxi_group.my_group_resource.id + } + } + `, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttrWith( + "data.uxi_group.my_group", + "id", + func(value string) error { + st.Assert(t, value, util.GetGroupByName(groupName).Id) + return nil + }, + ), + resource.TestCheckResourceAttr("data.uxi_group.my_group", "name", groupName), + resource.TestCheckResourceAttrWith( + "data.uxi_group.my_group", + "path", + func(value string) error { + st.Assert(t, value, util.GetGroupByName(groupName).Path) + return nil + }, + ), + resource.TestCheckResourceAttr( + "data.uxi_group.my_group", + "parent_group_id", + config.GroupIdRoot, + ), + ), + }, + }, + }) +} diff --git a/test/live/datasources/network_group_assignment_test.go b/test/live/datasources/network_group_assignment_test.go new file mode 100644 index 00000000..ddd5b159 --- /dev/null +++ b/test/live/datasources/network_group_assignment_test.go @@ -0,0 +1,58 @@ +package data_source_test + +import ( + "testing" + + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/util" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" +) + +func TestNetworkGroupAssignmentDataSource(t *testing.T) { + const groupName = "tf_provider_acceptance_test_network_group_assignment_datasource" + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: provider.ProviderConfig + ` + // create the resource to be used as a datasource + resource "uxi_group" "my_group" { + name = "` + groupName + `" + } + + data "uxi_wired_network" "my_network" { + filter = { + wired_network_id = "` + config.WiredNetworkId + `" + } + } + + resource "uxi_network_group_assignment" "my_network_group_assignment" { + network_id = data.uxi_wired_network.my_network.id + group_id = uxi_group.my_group.id + } + + // the actual datasource + data "uxi_network_group_assignment" "my_network_group_assignment" { + filter = { + network_group_assignment_id = uxi_network_group_assignment.my_network_group_assignment.id + } + } + `, + Check: resource.ComposeTestCheckFunc( + 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", + util.GetNetworkGroupAssignment(rs.Primary.ID), + )(s) + }, + ), + }, + }, + }) +} diff --git a/test/live/datasources/sensor_group_assignment_test.go b/test/live/datasources/sensor_group_assignment_test.go new file mode 100644 index 00000000..e3b6456e --- /dev/null +++ b/test/live/datasources/sensor_group_assignment_test.go @@ -0,0 +1,58 @@ +package data_source_test + +import ( + "testing" + + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/util" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" +) + +func TestSensorGroupAssignmentDataSource(t *testing.T) { + const groupName = "tf_provider_acceptance_test_sensor_group_assignment_datasource" + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: provider.ProviderConfig + ` + // create the resource to be used as a datasource + resource "uxi_group" "my_group" { + name = "` + groupName + `" + } + + data "uxi_sensor" "my_sensor" { + filter = { + sensor_id = "` + config.SensorId + `" + } + } + + resource "uxi_sensor_group_assignment" "my_sensor_group_assignment" { + sensor_id = data.uxi_sensor.my_sensor.id + group_id = uxi_group.my_group.id + } + + // the actual datasource + data "uxi_sensor_group_assignment" "my_sensor_group_assignment" { + filter = { + sensor_group_assignment_id = uxi_sensor_group_assignment.my_sensor_group_assignment.id + } + } + `, + Check: resource.ComposeTestCheckFunc( + 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", + util.GetSensorGroupAssignment(rs.Primary.ID), + )(s) + }, + ), + }, + }, + }) +} diff --git a/test/live/datasources/sensor_test.go b/test/live/datasources/sensor_test.go new file mode 100644 index 00000000..8cddb2b0 --- /dev/null +++ b/test/live/datasources/sensor_test.go @@ -0,0 +1,33 @@ +package data_source_test + +import ( + "testing" + + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/util" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestSensorDataSource(t *testing.T) { + sensor := util.GetSensorProperties(config.SensorId) + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: provider.ProviderConfig + ` + data "uxi_sensor" "my_sensor" { + filter = { + sensor_id = "` + config.SensorId + `" + } + } + `, + Check: util.CheckDataSourceStateAgainstSensor( + t, + "data.uxi_sensor.my_sensor", + sensor, + ), + }, + }, + }) +} diff --git a/test/live/datasources/service_test.go b/test/live/datasources/service_test.go new file mode 100644 index 00000000..dbdc9ff9 --- /dev/null +++ b/test/live/datasources/service_test.go @@ -0,0 +1,30 @@ +package data_source_test + +import ( + "testing" + + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/util" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestServiceTestDataSource(t *testing.T) { + serviceTest := util.GetServiceTest(config.ServiceTestId) + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: provider.ProviderConfig + ` + data "uxi_service_test" "my_service_test" { + filter = { + service_test_id = "` + config.ServiceTestId + `" + } + } + `, + Check: util.CheckStateAgainstServiceTest(t, serviceTest), + }, + }, + }) +} diff --git a/test/live/datasources/service_test_group_assignment_test.go b/test/live/datasources/service_test_group_assignment_test.go new file mode 100644 index 00000000..03b4ef65 --- /dev/null +++ b/test/live/datasources/service_test_group_assignment_test.go @@ -0,0 +1,60 @@ +package data_source_test + +import ( + "testing" + + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/util" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" +) + +func TestServiceTestGroupAssignmentDataSource(t *testing.T) { + const groupName = "tf_provider_acceptance_test_service_test_group_assignment_datasource" + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: provider.ProviderConfig + ` + // create the resource to be used as a datasource + resource "uxi_group" "my_group" { + name = "` + groupName + `" + } + + data "uxi_service_test" "my_service_test" { + filter = { + service_test_id = "` + config.ServiceTestId + `" + } + } + + resource "uxi_service_test_group_assignment" "my_service_test_group_assignment" { + service_test_id = data.uxi_service_test.my_service_test.id + group_id = uxi_group.my_group.id + } + + // the actual datasource + data "uxi_service_test_group_assignment" "my_service_test_group_assignment" { + filter = { + service_test_group_assignment_id = uxi_service_test_group_assignment.my_service_test_group_assignment.id + } + } + `, + Check: resource.ComposeTestCheckFunc( + 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", + util.GetServiceTestGroupAssignment(rs.Primary.ID), + )( + s, + ) + }, + ), + }, + }, + }) +} diff --git a/test/live/datasources/wired_network_test.go b/test/live/datasources/wired_network_test.go new file mode 100644 index 00000000..545e1cb8 --- /dev/null +++ b/test/live/datasources/wired_network_test.go @@ -0,0 +1,30 @@ +package data_source_test + +import ( + "testing" + + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/util" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestWiredNetworkDataSource(t *testing.T) { + wired_network := util.GetWiredNetwork(config.WiredNetworkId) + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: provider.ProviderConfig + ` + data "uxi_wired_network" "my_wired_network" { + filter = { + wired_network_id = "` + config.WiredNetworkId + `" + } + } + `, + Check: util.CheckStateAgainstWiredNetwork(t, wired_network), + }, + }, + }) +} diff --git a/test/live/datasources/wireless_network_test.go b/test/live/datasources/wireless_network_test.go new file mode 100644 index 00000000..13a479b4 --- /dev/null +++ b/test/live/datasources/wireless_network_test.go @@ -0,0 +1,30 @@ +package data_source_test + +import ( + "testing" + + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/util" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestWirelessNetworkDataSource(t *testing.T) { + wireless_network := util.GetWirelessNetwork(config.WirelessNetworkId) + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: provider.ProviderConfig + ` + data "uxi_wireless_network" "my_wireless_network" { + filter = { + wireless_network_id = "` + config.WirelessNetworkId + `" + } + } + `, + Check: util.CheckStateAgainstWirelessNetwork(t, wireless_network), + }, + }, + }) +} diff --git a/test/live/provider/provider.go b/test/live/provider/provider.go index 4f824e29..acfa1cfc 100644 --- a/test/live/provider/provider.go +++ b/test/live/provider/provider.go @@ -1,8 +1,8 @@ package provider import ( - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider" - "github.com/aruba-uxi/terraform-provider-configuration/test/live/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/util" "github.com/hashicorp/terraform-plugin-framework/providerserver" "github.com/hashicorp/terraform-plugin-go/tfprotov6" ) diff --git a/test/live/resources/agent_group_assignment_test.go b/test/live/resources/agent_group_assignment_test.go new file mode 100644 index 00000000..4b672f6f --- /dev/null +++ b/test/live/resources/agent_group_assignment_test.go @@ -0,0 +1,125 @@ +package resource_test + +import ( + "testing" + + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/util" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" + "github.com/nbio/st" +) + +func TestAgentGroupAssignmentResource(t *testing.T) { + const groupName = "tf_provider_acceptance_test_agent_group_assignment_resource" + const group2Name = "tf_provider_acceptance_test_agent_group_assignment_resource_two" + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Creating a agent group assignment + { + Config: provider.ProviderConfig + ` + resource "uxi_group" "my_group" { + name = "` + groupName + `" + } + + data "uxi_agent" "my_agent" { + filter = { + agent_id = "` + config.AgentPermanentId + `" + } + } + + resource "uxi_agent_group_assignment" "my_agent_group_assignment" { + agent_id = data.uxi_agent.my_agent.id + group_id = uxi_group.my_group.id + }`, + Check: resource.ComposeAggregateTestCheckFunc( + // Check properties are what we configured + resource.TestCheckResourceAttr( + "uxi_agent_group_assignment.my_agent_group_assignment", + "agent_id", + config.AgentPermanentId, + ), + resource.TestCheckResourceAttrWith( + "uxi_agent_group_assignment.my_agent_group_assignment", + "group_id", + func(value string) error { + st.Assert(t, util.GetGroupByName(groupName).Id, value) + return nil + }, + ), + // Check properties match what is on backend + func(s *terraform.State) error { + resourceName := "uxi_agent_group_assignment.my_agent_group_assignment" + rs := s.RootModule().Resources[resourceName] + return util.CheckStateAgainstAgentGroupAssignment( + t, + "uxi_agent_group_assignment.my_agent_group_assignment", + util.GetAgentGroupAssignment(rs.Primary.ID), + )(s) + }, + ), + }, + // ImportState testing + { + ResourceName: "uxi_agent_group_assignment.my_agent_group_assignment", + ImportState: true, + ImportStateVerify: true, + }, + // Update testing + { + Config: provider.ProviderConfig + ` + // the original resources + resource "uxi_group" "my_group" { + name = "` + groupName + `" + } + + data "uxi_agent" "my_agent" { + filter = { + agent_id = "` + config.AgentPermanentId + `" + } + } + + // the new resources we wanna update the assignment to + resource "uxi_group" "my_group_2" { + name = "` + group2Name + `" + } + + // the assignment update, updated from agent/group to agent/group_2 + resource "uxi_agent_group_assignment" "my_agent_group_assignment" { + agent_id = data.uxi_agent.my_agent.id + group_id = uxi_group.my_group_2.id + }`, + Check: resource.ComposeAggregateTestCheckFunc( + // Check properties are what we configured + resource.TestCheckResourceAttr( + "uxi_agent_group_assignment.my_agent_group_assignment", + "agent_id", + config.AgentPermanentId, + ), + resource.TestCheckResourceAttrWith( + "uxi_agent_group_assignment.my_agent_group_assignment", + "group_id", + func(value string) error { + st.Assert(t, util.GetGroupByName(group2Name).Id, value) + return nil + }, + ), + // Check properties match what is on backend + func(s *terraform.State) error { + resourceName := "uxi_agent_group_assignment.my_agent_group_assignment" + rs := s.RootModule().Resources[resourceName] + return util.CheckStateAgainstAgentGroupAssignment( + t, + "uxi_agent_group_assignment.my_agent_group_assignment", + util.GetAgentGroupAssignment(rs.Primary.ID), + )(s) + }, + ), + }, + // Delete testing happens automatically + }, + }) +} diff --git a/test/live/resources/agent_test.go b/test/live/resources/agent_test.go new file mode 100644 index 00000000..deb802ec --- /dev/null +++ b/test/live/resources/agent_test.go @@ -0,0 +1,90 @@ +package resource_test + +import ( + "os" + "regexp" + "testing" + + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/util" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAgentResource(t *testing.T) { + const ( + agentName = "tf_provider_acceptance_test_agent_resource" + agentNameUpdated = agentName + "_updated" + ) + + // we provision an agent here so that we have something to delete later on + agentId, err := util.ProvisionAgent{ + CustomerId: config.CustomerId, + ProvisionToken: os.Getenv("UXI_PROVISION_TOKEN"), + DeviceSerial: config.AgentCreateSerial, + DeviceGatewayHost: config.DeviceGatewayHost, + }.Provision() + if err != nil { + panic(err) + } + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Creating an agent is not allowed + { + Config: provider.ProviderConfig + ` + resource "uxi_agent" "my_agent" { + name = "` + agentName + `" + }`, + + ExpectError: regexp.MustCompile( + `creating an agent is not supported; agents can only be imported`, + ), + }, + // Importing an agent + { + Config: provider.ProviderConfig + ` + resource "uxi_agent" "my_agent" { + name = "` + agentName + `" + notes = "" + pcap_mode = "light" + } + + import { + to = uxi_agent.my_agent + id = "` + agentId + `" + }`, + + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("uxi_agent.my_agent", "name", agentName), + resource.TestCheckResourceAttr("uxi_agent.my_agent", "notes", ""), + resource.TestCheckResourceAttr("uxi_agent.my_agent", "pcap_mode", "light"), + resource.TestCheckResourceAttr("uxi_agent.my_agent", "id", agentId), + ), + }, + // ImportState testing + { + ResourceName: "uxi_agent.my_agent", + ImportState: true, + ImportStateVerify: true, + }, + // Update testing + { + Config: provider.ProviderConfig + ` + resource "uxi_agent" "my_agent" { + name = "` + agentNameUpdated + `" + notes = "notes" + pcap_mode = "off" + }`, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("uxi_agent.my_agent", "id", agentId), + resource.TestCheckResourceAttr("uxi_agent.my_agent", "name", agentNameUpdated), + resource.TestCheckResourceAttr("uxi_agent.my_agent", "notes", "notes"), + resource.TestCheckResourceAttr("uxi_agent.my_agent", "pcap_mode", "off"), + ), + }, + // Delete testing happen automatically + }, + }) +} diff --git a/test/live/resources/group_test.go b/test/live/resources/group_test.go index 4fe28540..745f1dee 100644 --- a/test/live/resources/group_test.go +++ b/test/live/resources/group_test.go @@ -5,8 +5,9 @@ import ( "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration/test/live/provider" - "github.com/aruba-uxi/terraform-provider-configuration/test/live/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/util" "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) @@ -14,8 +15,6 @@ type Fetcher interface { FetchData() ([]byte, error) } -var rootGroup = util.GetRoot() - func TestGroupResource(t *testing.T) { const groupNameParent = "tf_provider_acceptance_test_parent" const groupNameParentUpdated = groupNameParent + "_updated" @@ -186,7 +185,7 @@ func TestRootGroupResource(t *testing.T) { import { to = uxi_group.my_root_group - id = "` + rootGroup.Id + `" + id = "` + config.GroupIdRoot + `" }`, ExpectError: regexp.MustCompile(`The root group cannot be used as a resource`), }, diff --git a/test/live/resources/network_group_assignment_test.go b/test/live/resources/network_group_assignment_test.go index b57988b6..2121d02d 100644 --- a/test/live/resources/network_group_assignment_test.go +++ b/test/live/resources/network_group_assignment_test.go @@ -3,16 +3,16 @@ package resource_test import ( "testing" - "github.com/aruba-uxi/terraform-provider-configuration/test/live/config" - "github.com/aruba-uxi/terraform-provider-configuration/test/live/provider" - "github.com/aruba-uxi/terraform-provider-configuration/test/live/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/util" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/nbio/st" ) func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { - const groupName = "tf_provider_acceptance_test_network_association_test" - const group2Name = "tf_provider_acceptance_test_network_association_test_two" + const groupName = "tf_provider_acceptance_test_network_assignment_test" + const group2Name = "tf_provider_acceptance_test_network_assignment_test_two" // Test Wired Network Group Assignment resource.Test(t, resource.TestCase{ @@ -31,7 +31,7 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { import { to = uxi_wired_network.my_network - id = "` + config.WiredNetworkUid + `" + id = "` + config.WiredNetworkId + `" } resource "uxi_network_group_assignment" "my_network_group_assignment" { @@ -42,7 +42,7 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { resource.TestCheckResourceAttr( "uxi_network_group_assignment.my_network_group_assignment", "network_id", - config.WiredNetworkUid, + config.WiredNetworkId, ), resource.TestCheckResourceAttrWith( "uxi_network_group_assignment.my_network_group_assignment", @@ -74,7 +74,7 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { import { to = uxi_wired_network.my_network - id = "` + config.WiredNetworkUid + `" + id = "` + config.WiredNetworkId + `" } // the new resources we wanna update the assignment to @@ -91,7 +91,7 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { resource.TestCheckResourceAttr( "uxi_network_group_assignment.my_network_group_assignment", "network_id", - config.WiredNetworkUid, + config.WiredNetworkId, ), resource.TestCheckResourceAttrWith( "uxi_network_group_assignment.my_network_group_assignment", @@ -119,8 +119,8 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { } func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { - const groupName = "tf_provider_acceptance_test_network_association_test" - const group2Name = "tf_provider_acceptance_test_network_association_test_two" + const groupName = "tf_provider_acceptance_test_network_assignment_test" + const group2Name = "tf_provider_acceptance_test_network_assignment_test_two" // Test Wired Network Group Assignment resource.Test(t, resource.TestCase{ @@ -139,7 +139,7 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { import { to = uxi_wireless_network.my_network - id = "` + config.WirelessNetworkUid + `" + id = "` + config.WirelessNetworkId + `" } resource "uxi_network_group_assignment" "my_network_group_assignment" { @@ -150,7 +150,7 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { resource.TestCheckResourceAttr( "uxi_network_group_assignment.my_network_group_assignment", "network_id", - config.WirelessNetworkUid, + config.WirelessNetworkId, ), resource.TestCheckResourceAttrWith( "uxi_network_group_assignment.my_network_group_assignment", @@ -182,7 +182,7 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { import { to = uxi_wireless_network.my_network - id = "` + config.WirelessNetworkUid + `" + id = "` + config.WirelessNetworkId + `" } // the new resources we wanna update the assignment to @@ -199,7 +199,7 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { resource.TestCheckResourceAttr( "uxi_network_group_assignment.my_network_group_assignment", "network_id", - config.WirelessNetworkUid, + config.WirelessNetworkId, ), resource.TestCheckResourceAttrWith( "uxi_network_group_assignment.my_network_group_assignment", diff --git a/test/live/resources/sensor_group_assignment_test.go b/test/live/resources/sensor_group_assignment_test.go new file mode 100644 index 00000000..938af090 --- /dev/null +++ b/test/live/resources/sensor_group_assignment_test.go @@ -0,0 +1,120 @@ +package resource_test + +import ( + "testing" + + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/util" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/nbio/st" +) + +func TestSensorGroupAssignmentResource(t *testing.T) { + const groupName = "tf_provider_acceptance_test_sensor_assignment_test" + const group2Name = "tf_provider_acceptance_test_sensor_assignment_test_two" + existingSensorProperties := util.GetSensorProperties(config.SensorId) + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Creating a sensor group assignment + { + Config: provider.ProviderConfig + ` + resource "uxi_group" "my_group" { + name = "` + groupName + `" + } + + resource "uxi_sensor" "my_sensor" { + name = "` + existingSensorProperties.Name + `" + ` + util.ConditionalProperty("address_note", existingSensorProperties.AddressNote.Get()) + ` + ` + util.ConditionalProperty("notes", existingSensorProperties.Notes.Get()) + ` + ` + util.ConditionalProperty("pcap_mode", existingSensorProperties.PcapMode.Get()) + ` + } + + import { + to = uxi_sensor.my_sensor + id = "` + config.SensorId + `" + } + + resource "uxi_sensor_group_assignment" "my_sensor_group_assignment" { + sensor_id = uxi_sensor.my_sensor.id + group_id = uxi_group.my_group.id + }`, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr( + "uxi_sensor_group_assignment.my_sensor_group_assignment", + "sensor_id", + config.SensorId, + ), + resource.TestCheckResourceAttrWith( + "uxi_sensor_group_assignment.my_sensor_group_assignment", + "group_id", + func(value string) error { + st.Assert(t, value, util.GetGroupByName(groupName).Id) + return nil + }, + ), + ), + }, + // ImportState testing + { + ResourceName: "uxi_sensor_group_assignment.my_sensor_group_assignment", + ImportState: true, + ImportStateVerify: true, + }, + // Update and Read testing + { + Config: provider.ProviderConfig + ` + // the original resources + resource "uxi_group" "my_group" { + name = "` + groupName + `" + } + + resource "uxi_sensor" "my_sensor" { + name = "` + existingSensorProperties.Name + `" + ` + util.ConditionalProperty("address_note", existingSensorProperties.AddressNote.Get()) + ` + ` + util.ConditionalProperty("notes", existingSensorProperties.Notes.Get()) + ` + ` + util.ConditionalProperty("pcap_mode", existingSensorProperties.PcapMode.Get()) + ` + } + + // the new resources we wanna update the assignment to + resource "uxi_group" "my_group_2" { + name = "` + group2Name + `" + } + + // the assignment update, updated from sensor/group to sensor/group_2 + resource "uxi_sensor_group_assignment" "my_sensor_group_assignment" { + sensor_id = uxi_sensor.my_sensor.id + group_id = uxi_group.my_group_2.id + }`, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr( + "uxi_sensor_group_assignment.my_sensor_group_assignment", + "sensor_id", + config.SensorId, + ), + resource.TestCheckResourceAttrWith( + "uxi_sensor_group_assignment.my_sensor_group_assignment", + "group_id", + func(value string) error { + st.Assert(t, value, util.GetGroupByName(group2Name).Id) + return nil + }, + ), + ), + }, + // Delete sensor-group assignments and remove sensors from state + { + Config: provider.ProviderConfig + ` + removed { + from = uxi_sensor.my_sensor + + lifecycle { + destroy = false + } + }`, + }, + }, + }) +} diff --git a/test/live/resources/sensor_test.go b/test/live/resources/sensor_test.go new file mode 100644 index 00000000..bc55e61b --- /dev/null +++ b/test/live/resources/sensor_test.go @@ -0,0 +1,116 @@ +package resource_test + +import ( + config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/util" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/tfversion" + + "regexp" + "testing" +) + +func TestSensorResource(t *testing.T) { + originalSensor := util.GetSensorProperties(config.SensorId) + updatedNotes := "tf_provider_acceptance_test_update_notes" + updatedAddressNote := "tf_provider_acceptance_test_update_address_note" + updatedPcapMode := "off" + updatedSensor := config_api_client.SensorItem{ + Id: config.SensorId, + Name: "tf_provider_acceptance_test_update_name", + Notes: *config_api_client.NewNullableString(&updatedNotes), + AddressNote: *config_api_client.NewNullableString(&updatedAddressNote), + PcapMode: *config_api_client.NewNullableString(&updatedPcapMode), + } + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + // we required terraform 1.7.0 and above for the `removed` block + tfversion.RequireAbove(tfversion.Version1_7_0), + }, + Steps: []resource.TestStep{ + // Creating a sensor is not allowed + { + Config: provider.ProviderConfig + ` + resource "uxi_sensor" "my_sensor" { + name = "` + originalSensor.Name + `" + }`, + + ExpectError: regexp.MustCompile( + `creating a sensor is not supported; sensors can only be imported`, + ), + }, + // Importing a sensor + { + Config: provider.ProviderConfig + ` + resource "uxi_sensor" "my_sensor" { + name = "` + originalSensor.Name + `" + } + + import { + to = uxi_sensor.my_sensor + id = "` + config.SensorId + `" + }`, + + Check: resource.ComposeAggregateTestCheckFunc(), + }, + // ImportState testing + { + ResourceName: "uxi_sensor.my_sensor", + ImportState: true, + ImportStateVerify: true, + }, + // Update testing + { + Config: provider.ProviderConfig + ` + resource "uxi_sensor" "my_sensor" { + name = "` + updatedSensor.Name + `" + address_note = "` + updatedSensor.GetAddressNote() + `" + notes = "` + updatedSensor.GetNotes() + `" + pcap_mode = "` + updatedSensor.GetPcapMode() + `" + }`, + Check: util.CheckResourceStateAgainstSensor( + t, + "uxi_sensor.my_sensor", + updatedSensor, + ), + }, + // Update sensor back to original + { + Config: provider.ProviderConfig + ` + resource "uxi_sensor" "my_sensor" { + name = "` + originalSensor.Name + `" + address_note = "` + originalSensor.GetAddressNote() + `" + notes = "` + originalSensor.GetNotes() + `" + pcap_mode = "` + originalSensor.GetPcapMode() + `" + }`, + Check: util.CheckResourceStateAgainstSensor( + t, + "uxi_sensor.my_sensor", + originalSensor, + ), + }, + // Deleting a sensor is not allowed + { + Config: provider.ProviderConfig + ``, + ExpectError: regexp.MustCompile( + `deleting a sensor is not supported; sensors can only removed from state`, + ), + }, + // Remove sensor from state + { + Config: provider.ProviderConfig + ` + removed { + from = uxi_sensor.my_sensor + + lifecycle { + destroy = false + } + }`, + }, + }, + }) +} diff --git a/test/live/resources/service_test.go b/test/live/resources/service_test.go index d737ced1..eab081f9 100644 --- a/test/live/resources/service_test.go +++ b/test/live/resources/service_test.go @@ -1,8 +1,8 @@ package resource_test import ( - "github.com/aruba-uxi/terraform-provider-configuration/test/live/config" - "github.com/aruba-uxi/terraform-provider-configuration/test/live/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/provider" "regexp" "testing" @@ -38,7 +38,7 @@ func TestServiceTestResource(t *testing.T) { import { to = uxi_service_test.my_service_test - id = "` + config.ServiceTestUid + `" + id = "` + config.ServiceTestId + `" }`, Check: resource.ComposeAggregateTestCheckFunc( @@ -50,7 +50,7 @@ func TestServiceTestResource(t *testing.T) { resource.TestCheckResourceAttr( "uxi_service_test.my_service_test", "id", - config.ServiceTestUid, + config.ServiceTestId, ), ), }, diff --git a/test/live/resources/service_test_group_assignment_test.go b/test/live/resources/service_test_group_assignment_test.go new file mode 100644 index 00000000..74ffc26e --- /dev/null +++ b/test/live/resources/service_test_group_assignment_test.go @@ -0,0 +1,113 @@ +package resource_test + +import ( + "testing" + + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/util" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/nbio/st" +) + +func TestServiceTestGroupAssignmentResource(t *testing.T) { + const groupName = "tf_acceptance_test_service_test_group_assignment" + const group2Name = "tf_acceptance_test_service_test_group_assignment_two" + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Creating a serviceTest group assignment + { + Config: provider.ProviderConfig + ` + resource "uxi_group" "my_group" { + name = "` + groupName + `" + } + + resource "uxi_service_test" "my_service_test" { + name = "` + config.ServiceTestName + `" + } + + import { + to = uxi_service_test.my_service_test + id = "` + config.ServiceTestId + `" + } + + resource "uxi_service_test_group_assignment" "my_service_test_group_assignment" { + service_test_id = uxi_service_test.my_service_test.id + group_id = uxi_group.my_group.id + }`, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr( + "uxi_service_test_group_assignment.my_service_test_group_assignment", + "service_test_id", + config.ServiceTestId, + ), + resource.TestCheckResourceAttrWith( + "uxi_service_test_group_assignment.my_service_test_group_assignment", + "group_id", + func(value string) error { + st.Assert(t, value, util.GetGroupByName(groupName).Id) + return nil + }, + ), + ), + }, + // ImportState testing + { + ResourceName: "uxi_service_test_group_assignment.my_service_test_group_assignment", + ImportState: true, + ImportStateVerify: true, + }, + // Update and Read testing + { + Config: provider.ProviderConfig + ` + // the original resources + resource "uxi_group" "my_group" { + name = "` + groupName + `" + } + + resource "uxi_service_test" "my_service_test" { + name = "` + config.ServiceTestName + `" + } + + // the new resources we wanna update the assignment to + resource "uxi_group" "my_group_2" { + name = "` + group2Name + `" + } + + // the assignment update, updated from service_test/group to service_test/group_2 + resource "uxi_service_test_group_assignment" "my_service_test_group_assignment" { + service_test_id = uxi_service_test.my_service_test.id + group_id = uxi_group.my_group_2.id + }`, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr( + "uxi_service_test_group_assignment.my_service_test_group_assignment", + "service_test_id", + config.ServiceTestId, + ), + resource.TestCheckResourceAttrWith( + "uxi_service_test_group_assignment.my_service_test_group_assignment", + "group_id", + func(value string) error { + st.Assert(t, value, util.GetGroupByName(group2Name).Id) + return nil + }, + ), + ), + }, + // Remove serviceTests from state + { + Config: provider.ProviderConfig + ` + removed { + from = uxi_service_test.my_service_test + + lifecycle { + destroy = false + } + }`, + }, + }, + }) +} diff --git a/test/live/resources/wired_network_test.go b/test/live/resources/wired_network_test.go index db148dd8..9c8cef6b 100644 --- a/test/live/resources/wired_network_test.go +++ b/test/live/resources/wired_network_test.go @@ -1,8 +1,8 @@ package resource_test import ( - "github.com/aruba-uxi/terraform-provider-configuration/test/live/config" - "github.com/aruba-uxi/terraform-provider-configuration/test/live/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/provider" "regexp" "testing" @@ -38,7 +38,7 @@ func TestWiredNetworkResource(t *testing.T) { import { to = uxi_wired_network.wired_network_0 - id = "` + config.WiredNetworkUid + `" + id = "` + config.WiredNetworkId + `" }`, Check: resource.ComposeAggregateTestCheckFunc( @@ -50,7 +50,7 @@ func TestWiredNetworkResource(t *testing.T) { resource.TestCheckResourceAttr( "uxi_wired_network.wired_network_0", "id", - config.WiredNetworkUid, + config.WiredNetworkId, ), ), }, @@ -64,7 +64,7 @@ func TestWiredNetworkResource(t *testing.T) { { Config: provider.ProviderConfig + ` resource "uxi_wired_network" "wired_network_0" { - name = "` + config.WiredNetworkUid + `-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 7470d01c..9c8ed66e 100644 --- a/test/live/resources/wireless_network_test.go +++ b/test/live/resources/wireless_network_test.go @@ -1,8 +1,8 @@ package resource_test import ( - "github.com/aruba-uxi/terraform-provider-configuration/test/live/config" - "github.com/aruba-uxi/terraform-provider-configuration/test/live/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/provider" "regexp" "testing" @@ -38,7 +38,7 @@ func TestWirelessNetworkResource(t *testing.T) { import { to = uxi_wireless_network.wireless_network_0 - id = "` + config.WirelessNetworkUid + `" + id = "` + config.WirelessNetworkId + `" }`, Check: resource.ComposeAggregateTestCheckFunc( @@ -50,7 +50,7 @@ func TestWirelessNetworkResource(t *testing.T) { resource.TestCheckResourceAttr( "uxi_wireless_network.wireless_network_0", "id", - config.WirelessNetworkUid, + config.WirelessNetworkId, ), ), }, diff --git a/test/live/util/agent.go b/test/live/util/agent.go new file mode 100644 index 00000000..b1f741e1 --- /dev/null +++ b/test/live/util/agent.go @@ -0,0 +1,137 @@ +package util + +import ( + "bytes" + "context" + "crypto/md5" + "encoding/json" + "fmt" + "io" + "net/http" + + config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/nbio/st" +) + +func GetAgentProperties(id string) config_api_client.AgentItem { + result, _, err := Client.ConfigurationAPI. + AgentsGet(context.Background()). + Id(id). + Execute() + if err != nil { + panic(err) + } + if len(result.Items) != 1 { + panic("agent with id `" + id + "` could not be found") + } + return result.Items[0] +} + +func CheckStateAgainstAgent(t st.Fatalf, agent config_api_client.AgentItem) resource.TestCheckFunc { + return resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("data.uxi_agent.my_agent", "id", config.AgentPermanentId), + resource.TestCheckResourceAttr("data.uxi_agent.my_agent", "serial", agent.Serial), + TestOptionalValue(t, "data.uxi_agent.my_agent", "model_number", agent.ModelNumber.Get()), + resource.TestCheckResourceAttrWith( + "data.uxi_agent.my_agent", + "name", + func(value string) error { + st.Assert(t, value, agent.Name) + return nil + }, + ), + TestOptionalValue( + t, + "data.uxi_agent.my_agent", + "wifi_mac_address", + agent.WifiMacAddress.Get(), + ), + TestOptionalValue( + t, + "data.uxi_agent.my_agent", + "ethernet_mac_address", + agent.EthernetMacAddress.Get(), + ), + TestOptionalValue(t, "data.uxi_agent.my_agent", "notes", agent.Notes.Get()), + TestOptionalValue(t, "data.uxi_agent.my_agent", "pcap_mode", agent.PcapMode.Get()), + ) +} + +type ProvisionAgent struct { + CustomerId string + ProvisionToken string + DeviceSerial string + DeviceGatewayHost string +} + +type provisionAgentRequest struct { + Uid string `json:"uid"` + CustomerUid string `json:"customer_uid"` + ProvisionToken string `json:"provision_token"` + PlatformName string `json:"platform_name"` + DeviceSerial string `json:"device_serial"` +} + +func (p ProvisionAgent) Provision() (string, error) { + url := p.DeviceGatewayHost + "/provision-zebra-device" + id, err := p.generateId() + if err != nil { + return id, err + } + + request := provisionAgentRequest{ + Uid: id, + CustomerUid: p.CustomerId, + ProvisionToken: p.ProvisionToken, + PlatformName: "zebra", + DeviceSerial: p.DeviceSerial, + } + jsonData, err := json.Marshal(request) + if err != nil { + return id, err + } + + req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData)) + if err != nil { + return id, err + } + + req.Header.Set("Content-Type", "application/json") + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + return id, err + } + defer resp.Body.Close() + + body, _ := io.ReadAll(resp.Body) + if resp.StatusCode != http.StatusCreated { + return id, fmt.Errorf( + "unexpected status code returned: %d\nresponse: %s", + resp.StatusCode, + string(body), + ) + } + + return id, nil +} + +func (p ProvisionAgent) generateId() (string, error) { + // Create an MD5 hash of the serial string + hasher := md5.New() + hasher.Write([]byte(p.DeviceSerial)) + digest := hasher.Sum(nil) + + // Use the first 16 bytes of the digest to create a UUID v3 + uuid, err := uuid.FromBytes(digest[:16]) + if err != nil { + return "", err + } + uuid[6] = (uuid[6] & 0x0f) | 0x30 // Set the version to 3 (MD5-based UUID) + uuid[8] = (uuid[8] & 0x3f) | 0x80 // Set the variant to RFC 4122 + + return uuid.String(), nil +} diff --git a/test/live/util/agent_group_assignment.go b/test/live/util/agent_group_assignment.go new file mode 100644 index 00000000..9f95f13f --- /dev/null +++ b/test/live/util/agent_group_assignment.go @@ -0,0 +1,35 @@ +package util + +import ( + "context" + + config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/nbio/st" +) + +func GetAgentGroupAssignment(id string) config_api_client.AgentGroupAssignmentsItem { + result, _, err := Client.ConfigurationAPI. + AgentGroupAssignmentsGet(context.Background()). + Id(id). + Execute() + if err != nil { + panic(err) + } + if len(result.Items) != 1 { + panic("agent_group_assignment with id `" + id + "` could not be found") + } + return result.Items[0] +} + +func CheckStateAgainstAgentGroupAssignment( + t st.Fatalf, + entity string, + agentGroupAssignment config_api_client.AgentGroupAssignmentsItem, +) resource.TestCheckFunc { + return resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr(entity, "id", agentGroupAssignment.Id), + resource.TestCheckResourceAttr(entity, "group_id", agentGroupAssignment.Group.Id), + resource.TestCheckResourceAttr(entity, "agent_id", agentGroupAssignment.Agent.Id), + ) +} diff --git a/test/live/util/client.go b/test/live/util/client.go new file mode 100644 index 00000000..909d6322 --- /dev/null +++ b/test/live/util/client.go @@ -0,0 +1,35 @@ +package util + +import ( + "context" + "os" + + "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" + "golang.org/x/oauth2" + "golang.org/x/oauth2/clientcredentials" +) + +var CLIENT_ID = os.Getenv("UXI_CLIENT_ID") +var CLIENT_SECRET = os.Getenv("UXI_CLIENT_SECRET") + +const HOST = "api.staging.capedev.io" +const TOKEN_URL = "https://sso.common.cloud.hpe.com/as/token.oauth2" + +func NewClient() *config_api_client.APIClient { + config := &clientcredentials.Config{ + ClientID: CLIENT_ID, + ClientSecret: CLIENT_SECRET, + TokenURL: TOKEN_URL, + AuthStyle: oauth2.AuthStyleInParams, + } + + // Create a context and fetch a token + uxiConfiguration := config_api_client.NewConfiguration() + uxiConfiguration.Host = HOST + uxiConfiguration.Scheme = "https" + uxiConfiguration.HTTPClient = config.Client(context.Background()) + + return config_api_client.NewAPIClient(uxiConfiguration) +} + +var Client = NewClient() diff --git a/test/live/util/group.go b/test/live/util/group.go new file mode 100644 index 00000000..febc4623 --- /dev/null +++ b/test/live/util/group.go @@ -0,0 +1,17 @@ +package util + +import ( + "context" + + "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" +) + +func GetGroupByName(name string) *config_api_client.GroupsGetItem { + groups, _, _ := Client.ConfigurationAPI.GroupsGet(context.Background()).Execute() + 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 new file mode 100644 index 00000000..3ef454c0 --- /dev/null +++ b/test/live/util/network_group_assignment.go @@ -0,0 +1,35 @@ +package util + +import ( + "context" + + config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/nbio/st" +) + +func GetNetworkGroupAssignment(id string) config_api_client.NetworkGroupAssignmentsItem { + result, _, err := Client.ConfigurationAPI. + NetworkGroupAssignmentsGet(context.Background()). + Id(id). + Execute() + if err != nil { + panic(err) + } + if len(result.Items) != 1 { + panic("network_group_assignment with id `" + id + "` could not be found") + } + return result.Items[0] +} + +func CheckStateAgainstNetworkGroupAssignment( + t st.Fatalf, + entity string, + networkGroupAssignment config_api_client.NetworkGroupAssignmentsItem, +) resource.TestCheckFunc { + return resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr(entity, "id", networkGroupAssignment.Id), + resource.TestCheckResourceAttr(entity, "group_id", networkGroupAssignment.Group.Id), + resource.TestCheckResourceAttr(entity, "network_id", networkGroupAssignment.Network.Id), + ) +} diff --git a/test/live/util/sensor.go b/test/live/util/sensor.go new file mode 100644 index 00000000..bcb9fa26 --- /dev/null +++ b/test/live/util/sensor.go @@ -0,0 +1,72 @@ +package util + +import ( + "context" + + config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/nbio/st" +) + +func GetSensorProperties(id string) config_api_client.SensorItem { + result, _, err := Client.ConfigurationAPI. + SensorsGet(context.Background()). + Id(id). + Execute() + if err != nil { + panic(err) + } + if len(result.Items) != 1 { + panic("sensor with id `" + id + "` could not be found") + } + return result.Items[0] +} + +func CheckDataSourceStateAgainstSensor( + t st.Fatalf, + entity string, + sensor config_api_client.SensorItem, +) resource.TestCheckFunc { + return resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr(entity, "id", config.SensorId), + resource.TestCheckResourceAttr(entity, "serial", sensor.Serial), + resource.TestCheckResourceAttr(entity, "model_number", sensor.ModelNumber), + resource.TestCheckResourceAttrWith( + entity, + "name", + func(value string) error { + st.Assert(t, value, sensor.Name) + return nil + }, + ), + TestOptionalValue(t, entity, "wifi_mac_address", sensor.WifiMacAddress.Get()), + TestOptionalValue(t, entity, "ethernet_mac_address", sensor.EthernetMacAddress.Get()), + TestOptionalValue(t, entity, "address_note", sensor.AddressNote.Get()), + TestOptionalFloatValue(t, entity, "latitude", sensor.Latitude.Get()), + TestOptionalFloatValue(t, entity, "longitude", sensor.Longitude.Get()), + TestOptionalValue(t, entity, "notes", sensor.Notes.Get()), + TestOptionalValue(t, entity, "pcap_mode", sensor.PcapMode.Get()), + ) +} + +func CheckResourceStateAgainstSensor( + t st.Fatalf, + entity string, + sensor config_api_client.SensorItem, +) resource.TestCheckFunc { + return resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr(entity, "id", config.SensorId), + resource.TestCheckResourceAttrWith( + entity, + "name", + func(value string) error { + st.Assert(t, value, sensor.Name) + return nil + }, + ), + TestOptionalValue(t, entity, "address_note", sensor.AddressNote.Get()), + TestOptionalValue(t, entity, "notes", sensor.Notes.Get()), + TestOptionalValue(t, entity, "pcap_mode", sensor.PcapMode.Get()), + ) +} diff --git a/test/live/util/sensor_group_assignment.go b/test/live/util/sensor_group_assignment.go new file mode 100644 index 00000000..801dae2c --- /dev/null +++ b/test/live/util/sensor_group_assignment.go @@ -0,0 +1,35 @@ +package util + +import ( + "context" + + config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/nbio/st" +) + +func GetSensorGroupAssignment(id string) config_api_client.SensorGroupAssignmentsItem { + result, _, err := Client.ConfigurationAPI. + SensorGroupAssignmentsGet(context.Background()). + Id(id). + Execute() + if err != nil { + panic(err) + } + if len(result.Items) != 1 { + panic("sensor_group_assignment with id `" + id + "` could not be found") + } + return result.Items[0] +} + +func CheckStateAgainstSensorGroupAssignment( + t st.Fatalf, + entity string, + sensorGroupAssignment config_api_client.SensorGroupAssignmentsItem, +) resource.TestCheckFunc { + return resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr(entity, "id", sensorGroupAssignment.Id), + resource.TestCheckResourceAttr(entity, "group_id", sensorGroupAssignment.Group.Id), + resource.TestCheckResourceAttr(entity, "sensor_id", sensorGroupAssignment.Sensor.Id), + ) +} diff --git a/test/live/util/service.go b/test/live/util/service.go new file mode 100644 index 00000000..eed04f48 --- /dev/null +++ b/test/live/util/service.go @@ -0,0 +1,64 @@ +package util + +import ( + "context" + "strconv" + + config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/nbio/st" +) + +func GetServiceTest(id string) config_api_client.ServiceTestsListItem { + result, _, err := Client.ConfigurationAPI. + ServiceTestsGet(context.Background()). + Id(id). + Execute() + if err != nil { + panic(err) + } + if len(result.Items) != 1 { + panic("service_test with id `" + id + "` could not be found") + } + return result.Items[0] +} + +func CheckStateAgainstServiceTest( + t st.Fatalf, + serviceTest config_api_client.ServiceTestsListItem, +) resource.TestCheckFunc { + return resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr( + "data.uxi_service_test.my_service_test", + "id", + config.ServiceTestId, + ), + resource.TestCheckResourceAttr( + "data.uxi_service_test.my_service_test", + "category", + serviceTest.Category, + ), + resource.TestCheckResourceAttr( + "data.uxi_service_test.my_service_test", + "name", + serviceTest.Name, + ), + TestOptionalValue( + t, + "data.uxi_service_test.my_service_test", + "target", + serviceTest.Target.Get(), + ), + resource.TestCheckResourceAttr( + "data.uxi_service_test.my_service_test", + "template", + serviceTest.Template, + ), + resource.TestCheckResourceAttr( + "data.uxi_service_test.my_service_test", + "is_enabled", + strconv.FormatBool(serviceTest.IsEnabled), + ), + ) +} diff --git a/test/live/util/service_test_group_assignment.go b/test/live/util/service_test_group_assignment.go new file mode 100644 index 00000000..24c546ec --- /dev/null +++ b/test/live/util/service_test_group_assignment.go @@ -0,0 +1,39 @@ +package util + +import ( + "context" + + config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/nbio/st" +) + +func GetServiceTestGroupAssignment(id string) config_api_client.ServiceTestGroupAssignmentsItem { + result, _, err := Client.ConfigurationAPI. + ServiceTestGroupAssignmentsGet(context.Background()). + Id(id). + Execute() + if err != nil { + panic(err) + } + if len(result.Items) != 1 { + panic("service_test_group_assignment with id `" + id + "` could not be found") + } + return result.Items[0] +} + +func CheckStateAgainstServiceTestGroupAssignment( + t st.Fatalf, + entity string, + serviceTestGroupAssignment config_api_client.ServiceTestGroupAssignmentsItem, +) resource.TestCheckFunc { + return resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr(entity, "id", serviceTestGroupAssignment.Id), + resource.TestCheckResourceAttr(entity, "group_id", serviceTestGroupAssignment.Group.Id), + resource.TestCheckResourceAttr( + entity, + "service_test_id", + serviceTestGroupAssignment.ServiceTest.Id, + ), + ) +} diff --git a/test/live/util/util.go b/test/live/util/util.go index e866b77a..aa7d8b1b 100644 --- a/test/live/util/util.go +++ b/test/live/util/util.go @@ -1,56 +1,79 @@ package util import ( - "context" - "os" + "fmt" + "math" + "strconv" - "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - resources_util "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" - "golang.org/x/oauth2" - "golang.org/x/oauth2/clientcredentials" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/nbio/st" ) -var CLIENT_ID = os.Getenv("UXI_CLIENT_ID") -var CLIENT_SECRET = os.Getenv("UXI_CLIENT_SECRET") - -const HOST = "api.staging.capedev.io" -const TOKEN_URL = "https://sso.common.cloud.hpe.com/as/token.oauth2" - -func NewClient() *config_api_client.APIClient { - config := &clientcredentials.Config{ - ClientID: CLIENT_ID, - ClientSecret: CLIENT_SECRET, - TokenURL: TOKEN_URL, - AuthStyle: oauth2.AuthStyleInParams, +func ConditionalProperty(property string, value *string) string { + if value == nil { + return "" } + return property + `= "` + *value + `"` +} - // Create a context and fetch a token - uxiConfiguration := config_api_client.NewConfiguration() - uxiConfiguration.Host = HOST - uxiConfiguration.Scheme = "https" - uxiConfiguration.HTTPClient = config.Client(context.Background()) +func TestOptionalValue( + t st.Fatalf, + tfResource string, + tfKey string, + property *string, +) resource.TestCheckFunc { + if property == nil { + return resource.TestCheckNoResourceAttr(tfResource, tfKey) + } - return config_api_client.NewAPIClient(uxiConfiguration) + return resource.TestCheckResourceAttrWith( + tfResource, + tfKey, + func(value string) error { + if value != *property { + return fmt.Errorf("have `%s`; but want `%s`", value, *property) + } + return nil + }, + ) } -func GetRoot() *config_api_client.GroupsGetItem { - groups, _, _ := Client.ConfigurationAPI.GroupsGet(context.Background()).Execute() - for _, group := range groups.Items { - if resources_util.IsRoot(group) { - return &group - } +// This is required to do a check against floats since 100% accuracy is not guaranteed for floating +// point numbers in the terraform plugin framework +func TestOptionalFloatValue( + t st.Fatalf, + tfResource string, + tfKey string, + property *float32, +) resource.TestCheckFunc { + + if property == nil { + return resource.TestCheckNoResourceAttr(tfResource, tfKey) } - return nil + + return resource.TestCheckResourceAttrWith( + tfResource, + tfKey, + func(value string) error { + have := math.Round(stringToFloat64(value)*1e6) / 1e6 + want := math.Round(float64(*property*1e6)) / 1e6 + if have != want { + return fmt.Errorf("have `%f`; but want `%f`", have, want) + } + return nil + }, + ) } -func GetGroupByName(name string) *config_api_client.GroupsGetItem { - groups, _, _ := Client.ConfigurationAPI.GroupsGet(context.Background()).Execute() - for _, group := range groups.Items { - if group.Name == name { - return &group - } - } - return nil +func stringToFloat64(s string) float64 { + val, _ := strconv.ParseFloat(s, 32) + return float64(val) } -var Client = NewClient() +func Int32PtrToStringPtr(value *int32) *string { + if value == nil { + return nil + } + result := strconv.Itoa(int(*value)) + return &result +} diff --git a/test/live/util/wired_network.go b/test/live/util/wired_network.go new file mode 100644 index 00000000..399224f4 --- /dev/null +++ b/test/live/util/wired_network.go @@ -0,0 +1,84 @@ +package util + +import ( + "context" + "strconv" + + config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/nbio/st" +) + +func GetWiredNetwork(id string) config_api_client.WiredNetworksItem { + result, _, err := Client.ConfigurationAPI. + WiredNetworksGet(context.Background()). + Id(id). + Execute() + if err != nil { + panic(err) + } + if len(result.Items) != 1 { + panic("wired_network with id `" + id + "` could not be found") + } + return result.Items[0] +} + +func CheckStateAgainstWiredNetwork( + t st.Fatalf, + wired_network config_api_client.WiredNetworksItem, +) resource.TestCheckFunc { + return resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr( + "data.uxi_wired_network.my_wired_network", + "id", + config.WiredNetworkId, + ), + resource.TestCheckResourceAttrWith( + "data.uxi_wired_network.my_wired_network", + "name", + func(value string) error { + st.Assert(t, value, wired_network.Name) + return nil + }, + ), + resource.TestCheckResourceAttr( + "data.uxi_wired_network.my_wired_network", + "ip_version", + wired_network.IpVersion, + ), + TestOptionalValue( + t, + "data.uxi_wired_network.my_wired_network", + "security", + wired_network.Security.Get(), + ), + TestOptionalValue( + t, + "data.uxi_wired_network.my_wired_network", + "dns_lookup_domain", + wired_network.DnsLookupDomain.Get(), + ), + resource.TestCheckResourceAttr( + "data.uxi_wired_network.my_wired_network", + "disable_edns", + strconv.FormatBool(wired_network.DisableEdns), + ), + resource.TestCheckResourceAttr( + "data.uxi_wired_network.my_wired_network", + "use_dns64", + strconv.FormatBool(wired_network.UseDns64), + ), + resource.TestCheckResourceAttr( + "data.uxi_wired_network.my_wired_network", + "external_connectivity", + strconv.FormatBool(wired_network.ExternalConnectivity), + ), + TestOptionalValue( + t, + "data.uxi_wired_network.my_wired_network", + "vlan_id", + Int32PtrToStringPtr(wired_network.VLanId.Get()), + ), + ) +} diff --git a/test/live/util/wireless_network.go b/test/live/util/wireless_network.go new file mode 100644 index 00000000..f2b15eea --- /dev/null +++ b/test/live/util/wireless_network.go @@ -0,0 +1,93 @@ +package util + +import ( + "context" + "strconv" + + config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/nbio/st" +) + +func GetWirelessNetwork(id string) config_api_client.WirelessNetworksItem { + result, _, err := Client.ConfigurationAPI. + WirelessNetworksGet(context.Background()). + Id(id). + Execute() + if err != nil { + panic(err) + } + if len(result.Items) != 1 { + panic("wireless_network with id `" + id + "` could not be found") + } + return result.Items[0] +} + +func CheckStateAgainstWirelessNetwork( + t st.Fatalf, + wireless_network config_api_client.WirelessNetworksItem, +) resource.TestCheckFunc { + return resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr( + "data.uxi_wireless_network.my_wireless_network", + "id", + config.WirelessNetworkId, + ), + resource.TestCheckResourceAttr( + "data.uxi_wireless_network.my_wireless_network", + "ssid", + wireless_network.Ssid, + ), + resource.TestCheckResourceAttrWith( + "data.uxi_wireless_network.my_wireless_network", + "name", + func(value string) error { + st.Assert(t, value, wireless_network.Name) + return nil + }, + ), + resource.TestCheckResourceAttr( + "data.uxi_wireless_network.my_wireless_network", + "ip_version", + wireless_network.IpVersion, + ), + TestOptionalValue( + t, + "data.uxi_wireless_network.my_wireless_network", + "security", + wireless_network.Security.Get(), + ), + resource.TestCheckResourceAttr( + "data.uxi_wireless_network.my_wireless_network", + "hidden", + strconv.FormatBool(wireless_network.Hidden), + ), + resource.TestCheckResourceAttr( + "data.uxi_wireless_network.my_wireless_network", + "band_locking", + wireless_network.BandLocking, + ), + TestOptionalValue( + t, + "data.uxi_wireless_network.my_wireless_network", + "dns_lookup_domain", + wireless_network.DnsLookupDomain.Get(), + ), + resource.TestCheckResourceAttr( + "data.uxi_wireless_network.my_wireless_network", + "disable_edns", + strconv.FormatBool(wireless_network.DisableEdns), + ), + resource.TestCheckResourceAttr( + "data.uxi_wireless_network.my_wireless_network", + "use_dns64", + strconv.FormatBool(wireless_network.UseDns64), + ), + resource.TestCheckResourceAttr( + "data.uxi_wireless_network.my_wireless_network", + "external_connectivity", + strconv.FormatBool(wireless_network.ExternalConnectivity), + ), + ) +} diff --git a/test/mocked/data-sources/agent_group_assignment_test.go b/test/mocked/datasources/agent_group_assignment_test.go similarity index 79% rename from test/mocked/data-sources/agent_group_assignment_test.go rename to test/mocked/datasources/agent_group_assignment_test.go index 3f686523..c7ff292b 100644 --- a/test/mocked/data-sources/agent_group_assignment_test.go +++ b/test/mocked/datasources/agent_group_assignment_test.go @@ -1,11 +1,12 @@ package data_source_test import ( + "net/http" "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/util" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -23,10 +24,10 @@ func TestAgentGroupAssignmentDataSource(t *testing.T) { { PreConfig: func() { util.MockGetAgentGroupAssignment( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateAgentGroupAssignmentResponse("uid", ""), + util.GenerateAgentGroupAssignmentResponse("id", ""), }, ), 3, @@ -35,7 +36,7 @@ func TestAgentGroupAssignmentDataSource(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_agent_group_assignment" "my_agent_group_assignment" { filter = { - agent_group_assignment_id = "uid" + agent_group_assignment_id = "id" } } `, @@ -43,17 +44,17 @@ func TestAgentGroupAssignmentDataSource(t *testing.T) { resource.TestCheckResourceAttr( "data.uxi_agent_group_assignment.my_agent_group_assignment", "id", - "uid", + "id", ), resource.TestCheckResourceAttr( "data.uxi_agent_group_assignment.my_agent_group_assignment", "group_id", - "group_uid", + "group_id", ), resource.TestCheckResourceAttr( "data.uxi_agent_group_assignment.my_agent_group_assignment", "agent_id", - "agent_uid", + "agent_id", ), ), }, @@ -63,10 +64,10 @@ func TestAgentGroupAssignmentDataSource(t *testing.T) { mockOAuth.Mock.Disable() } -func TestAgentGroupAssignmentDataSource429Handling(t *testing.T) { +func TestAgentGroupAssignmentDataSourceTooManyRequestsHandling(t *testing.T) { defer gock.Off() mockOAuth := util.MockOAuth() - var mock429 *gock.Response + var mockTooManyRequests *gock.Response resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -74,15 +75,15 @@ func TestAgentGroupAssignmentDataSource429Handling(t *testing.T) { // Read testing { PreConfig: func() { - mock429 = gock.New("https://test.api.capenetworks.com"). + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/agent-group-assignments"). - Reply(429). + Reply(http.StatusTooManyRequests). SetHeaders(util.RateLimitingHeaders) util.MockGetAgentGroupAssignment( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateAgentGroupAssignmentResponse("uid", ""), + util.GenerateAgentGroupAssignmentResponse("id", ""), }, ), 3, @@ -91,7 +92,7 @@ func TestAgentGroupAssignmentDataSource429Handling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_agent_group_assignment" "my_agent_group_assignment" { filter = { - agent_group_assignment_id = "uid" + agent_group_assignment_id = "id" } } `, @@ -99,10 +100,10 @@ func TestAgentGroupAssignmentDataSource429Handling(t *testing.T) { resource.TestCheckResourceAttr( "data.uxi_agent_group_assignment.my_agent_group_assignment", "id", - "uid", + "id", ), func(s *terraform.State) error { - st.Assert(t, mock429.Mock.Request().Counter, 0) + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) return nil }, ), @@ -123,9 +124,9 @@ func TestAgentGroupAssignmentDataSourceHttpErrorHandling(t *testing.T) { PreConfig: func() { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/agent-group-assignments"). - Reply(500). + Reply(http.StatusInternalServerError). JSON(map[string]interface{}{ - "httpStatusCode": 500, + "httpStatusCode": http.StatusInternalServerError, "errorCode": "HPE_GL_ERROR_INTERNAL_SERVER_ERROR", "message": "Current request cannot be processed due to unknown issue", "debugId": "12312-123123-123123-1231212", @@ -134,7 +135,7 @@ func TestAgentGroupAssignmentDataSourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_agent_group_assignment" "my_agent_group_assignment" { filter = { - agent_group_assignment_id = "uid" + agent_group_assignment_id = "id" } } `, @@ -145,7 +146,7 @@ func TestAgentGroupAssignmentDataSourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetAgentGroupAssignment( - "uid", + "id", util.GeneratePaginatedResponse([]map[string]interface{}{}), 1, ) @@ -153,7 +154,7 @@ func TestAgentGroupAssignmentDataSourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_agent_group_assignment" "my_agent_group_assignment" { filter = { - agent_group_assignment_id = "uid" + agent_group_assignment_id = "id" } } `, diff --git a/test/mocked/data-sources/agent_test.go b/test/mocked/datasources/agent_test.go similarity index 68% rename from test/mocked/data-sources/agent_test.go rename to test/mocked/datasources/agent_test.go index 062cd6b0..d79a89a5 100644 --- a/test/mocked/data-sources/agent_test.go +++ b/test/mocked/datasources/agent_test.go @@ -1,11 +1,12 @@ package data_source_test import ( + "net/http" "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/util" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -23,9 +24,9 @@ func TestAgentDataSource(t *testing.T) { { PreConfig: func() { util.MockGetAgent( - "uid", + "id", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}, + []map[string]interface{}{util.GenerateAgentResponseModel("id", "")}, ), 3, ) @@ -33,12 +34,31 @@ func TestAgentDataSource(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_agent" "my_agent" { filter = { - agent_id = "uid" + agent_id = "id" } } `, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.uxi_agent.my_agent", "id", "uid"), + resource.TestCheckResourceAttr("data.uxi_agent.my_agent", "id", "id"), + resource.TestCheckResourceAttr("data.uxi_agent.my_agent", "name", "name"), + resource.TestCheckResourceAttr("data.uxi_agent.my_agent", "serial", "serial"), + resource.TestCheckResourceAttr( + "data.uxi_agent.my_agent", + "model_number", + "model_number", + ), + resource.TestCheckResourceAttr( + "data.uxi_agent.my_agent", + "wifi_mac_address", + "wifi_mac_address", + ), + resource.TestCheckResourceAttr( + "data.uxi_agent.my_agent", + "ethernet_mac_address", + "ethernet_mac_address", + ), + resource.TestCheckResourceAttr("data.uxi_agent.my_agent", "notes", "notes"), + resource.TestCheckResourceAttr("data.uxi_agent.my_agent", "pcap_mode", "light"), ), }, }, @@ -47,10 +67,10 @@ func TestAgentDataSource(t *testing.T) { mockOAuth.Mock.Disable() } -func TestAgentDataSource429Handling(t *testing.T) { +func TestAgentDataSourceTooManyRequestsHandling(t *testing.T) { defer gock.Off() mockOAuth := util.MockOAuth() - var mock429 *gock.Response + var mockTooManyRequests *gock.Response resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -59,14 +79,14 @@ func TestAgentDataSource429Handling(t *testing.T) { // Test Read { PreConfig: func() { - mock429 = gock.New("https://test.api.capenetworks.com"). + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/agents"). - Reply(429). + Reply(http.StatusTooManyRequests). SetHeaders(util.RateLimitingHeaders) util.MockGetAgent( - "uid", + "id", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}, + []map[string]interface{}{util.GenerateAgentResponseModel("id", "")}, ), 3, ) @@ -74,14 +94,14 @@ func TestAgentDataSource429Handling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_agent" "my_agent" { filter = { - agent_id = "uid" + agent_id = "id" } } `, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.uxi_agent.my_agent", "id", "uid"), + resource.TestCheckResourceAttr("data.uxi_agent.my_agent", "id", "id"), func(s *terraform.State) error { - st.Assert(t, mock429.Mock.Request().Counter, 0) + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) return nil }, ), @@ -103,9 +123,9 @@ func TestAgentDataSourceHttpErrorHandling(t *testing.T) { PreConfig: func() { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/agents"). - Reply(500). + Reply(http.StatusInternalServerError). JSON(map[string]interface{}{ - "httpStatusCode": 500, + "httpStatusCode": http.StatusInternalServerError, "errorCode": "HPE_GL_ERROR_INTERNAL_SERVER_ERROR", "message": "Current request cannot be processed due to unknown issue", "debugId": "12312-123123-123123-1231212", @@ -114,7 +134,7 @@ func TestAgentDataSourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_agent" "my_agent" { filter = { - agent_id = "uid" + agent_id = "id" } } `, @@ -126,7 +146,7 @@ func TestAgentDataSourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetAgent( - "uid", + "id", util.GeneratePaginatedResponse([]map[string]interface{}{}), 1, ) @@ -134,7 +154,7 @@ func TestAgentDataSourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_agent" "my_agent" { filter = { - agent_id = "uid" + agent_id = "id" } } `, diff --git a/test/mocked/data-sources/group_test.go b/test/mocked/datasources/group_test.go similarity index 77% rename from test/mocked/data-sources/group_test.go rename to test/mocked/datasources/group_test.go index 650c0a8b..b6c3f646 100644 --- a/test/mocked/data-sources/group_test.go +++ b/test/mocked/datasources/group_test.go @@ -1,12 +1,14 @@ package data_source_test import ( - config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" + "net/http" "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" + config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" + + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/util" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -24,10 +26,10 @@ func TestGroupDataSource(t *testing.T) { { PreConfig: func() { util.MockGetGroup( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("uid", "", ""), + util.GenerateNonRootGroupResponseModel("id", "", ""), }, ), 3, @@ -36,26 +38,26 @@ func TestGroupDataSource(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_group" "my_group" { filter = { - group_id = "uid" + group_id = "id" } } `, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.uxi_group.my_group", "id", "uid"), + resource.TestCheckResourceAttr("data.uxi_group.my_group", "id", "id"), ), }, // TODO: Test retrieving the root group { PreConfig: func() { util.MockGetGroup( - "my_root_group_uid", + "my_root_group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.StructToMap(config_api_client.GroupsGetItem{ - Id: "my_root_group_uid", + Id: "my_root_group_id", Name: "root", Parent: *config_api_client.NewNullableParent(nil), - Path: "my_root_group_uid", + Path: "my_root_group_id", }), }, ), @@ -65,7 +67,7 @@ func TestGroupDataSource(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_group" "my_group" { filter = { - group_id = "my_root_group_uid" + group_id = "my_root_group_id" } } `, @@ -77,10 +79,10 @@ func TestGroupDataSource(t *testing.T) { mockOAuth.Mock.Disable() } -func TestGroupDataSource429Handling(t *testing.T) { +func TestGroupDataSourceTooManyRequestsHandling(t *testing.T) { defer gock.Off() mockOAuth := util.MockOAuth() - var mock429 *gock.Response + var mockTooManyRequests *gock.Response resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -89,15 +91,15 @@ func TestGroupDataSource429Handling(t *testing.T) { // Test Read { PreConfig: func() { - mock429 = gock.New("https://test.api.capenetworks.com"). + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/groups"). - Reply(429). + Reply(http.StatusTooManyRequests). SetHeaders(util.RateLimitingHeaders) util.MockGetGroup( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("uid", "", ""), + util.GenerateNonRootGroupResponseModel("id", "", ""), }, ), 3, @@ -106,14 +108,14 @@ func TestGroupDataSource429Handling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_group" "my_group" { filter = { - group_id = "uid" + group_id = "id" } } `, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.uxi_group.my_group", "id", "uid"), + resource.TestCheckResourceAttr("data.uxi_group.my_group", "id", "id"), func(s *terraform.State) error { - st.Assert(t, mock429.Mock.Request().Counter, 0) + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) return nil }, ), @@ -135,9 +137,9 @@ func TestGroupDataSourceHttpErrorHandling(t *testing.T) { PreConfig: func() { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/groups"). - Reply(500). + Reply(http.StatusInternalServerError). JSON(map[string]interface{}{ - "httpStatusCode": 500, + "httpStatusCode": http.StatusInternalServerError, "errorCode": "HPE_GL_ERROR_INTERNAL_SERVER_ERROR", "message": "Current request cannot be processed due to unknown issue", "debugId": "12312-123123-123123-1231212", @@ -146,7 +148,7 @@ func TestGroupDataSourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_group" "my_group" { filter = { - group_id = "uid" + group_id = "id" } } `, @@ -158,7 +160,7 @@ func TestGroupDataSourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetGroup( - "uid", + "id", util.GeneratePaginatedResponse([]map[string]interface{}{}), 1, ) @@ -166,7 +168,7 @@ func TestGroupDataSourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_group" "my_group" { filter = { - group_id = "uid" + group_id = "id" } } `, diff --git a/test/mocked/data-sources/network_group_assignment_test.go b/test/mocked/datasources/network_group_assignment_test.go similarity index 79% rename from test/mocked/data-sources/network_group_assignment_test.go rename to test/mocked/datasources/network_group_assignment_test.go index 9cfe3f17..f0a60c4d 100644 --- a/test/mocked/data-sources/network_group_assignment_test.go +++ b/test/mocked/datasources/network_group_assignment_test.go @@ -1,11 +1,12 @@ package data_source_test import ( + "net/http" "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/util" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -23,10 +24,10 @@ func TestNetworkGroupAssignmentDataSource(t *testing.T) { { PreConfig: func() { util.MockGetNetworkGroupAssignment( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNetworkGroupAssignmentResponse("uid", ""), + util.GenerateNetworkGroupAssignmentResponse("id", ""), }, ), 3, @@ -35,7 +36,7 @@ func TestNetworkGroupAssignmentDataSource(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_network_group_assignment" "my_network_group_assignment" { filter = { - network_group_assignment_id = "uid" + network_group_assignment_id = "id" } } `, @@ -43,17 +44,17 @@ func TestNetworkGroupAssignmentDataSource(t *testing.T) { resource.TestCheckResourceAttr( "data.uxi_network_group_assignment.my_network_group_assignment", "id", - "uid", + "id", ), resource.TestCheckResourceAttr( "data.uxi_network_group_assignment.my_network_group_assignment", "group_id", - "group_uid", + "group_id", ), resource.TestCheckResourceAttr( "data.uxi_network_group_assignment.my_network_group_assignment", "network_id", - "network_uid", + "network_id", ), ), }, @@ -63,10 +64,10 @@ func TestNetworkGroupAssignmentDataSource(t *testing.T) { mockOAuth.Mock.Disable() } -func TestNetworkGroupAssignmentDataSource429Handling(t *testing.T) { +func TestNetworkGroupAssignmentDataSourceTooManyRequestsHandling(t *testing.T) { defer gock.Off() mockOAuth := util.MockOAuth() - var mock429 *gock.Response + var mockTooManyRequests *gock.Response resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -74,15 +75,15 @@ func TestNetworkGroupAssignmentDataSource429Handling(t *testing.T) { // Read testing { PreConfig: func() { - mock429 = gock.New("https://test.api.capenetworks.com"). + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/network-group-assignments"). - Reply(429). + Reply(http.StatusTooManyRequests). SetHeaders(util.RateLimitingHeaders) util.MockGetNetworkGroupAssignment( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNetworkGroupAssignmentResponse("uid", ""), + util.GenerateNetworkGroupAssignmentResponse("id", ""), }, ), 3, @@ -91,7 +92,7 @@ func TestNetworkGroupAssignmentDataSource429Handling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_network_group_assignment" "my_network_group_assignment" { filter = { - network_group_assignment_id = "uid" + network_group_assignment_id = "id" } } `, @@ -99,10 +100,10 @@ func TestNetworkGroupAssignmentDataSource429Handling(t *testing.T) { resource.TestCheckResourceAttr( "data.uxi_network_group_assignment.my_network_group_assignment", "id", - "uid", + "id", ), func(s *terraform.State) error { - st.Assert(t, mock429.Mock.Request().Counter, 0) + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) return nil }, ), @@ -123,9 +124,9 @@ func TestNetworkGroupAssignmentDataSourceHttpErrorHandling(t *testing.T) { PreConfig: func() { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/network-group-assignments"). - Reply(500). + Reply(http.StatusInternalServerError). JSON(map[string]interface{}{ - "httpStatusCode": 500, + "httpStatusCode": http.StatusInternalServerError, "errorCode": "HPE_GL_ERROR_INTERNAL_SERVER_ERROR", "message": "Current request cannot be processed due to unknown issue", "debugId": "12312-123123-123123-1231212", @@ -134,7 +135,7 @@ func TestNetworkGroupAssignmentDataSourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_network_group_assignment" "my_network_group_assignment" { filter = { - network_group_assignment_id = "uid" + network_group_assignment_id = "id" } } `, @@ -145,7 +146,7 @@ func TestNetworkGroupAssignmentDataSourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetNetworkGroupAssignment( - "uid", + "id", util.GeneratePaginatedResponse([]map[string]interface{}{}), 1, ) @@ -153,7 +154,7 @@ func TestNetworkGroupAssignmentDataSourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_network_group_assignment" "my_network_group_assignment" { filter = { - network_group_assignment_id = "uid" + network_group_assignment_id = "id" } } `, diff --git a/test/mocked/data-sources/sensor_group_assignment_test.go b/test/mocked/datasources/sensor_group_assignment_test.go similarity index 79% rename from test/mocked/data-sources/sensor_group_assignment_test.go rename to test/mocked/datasources/sensor_group_assignment_test.go index b3a5212b..8165508b 100644 --- a/test/mocked/data-sources/sensor_group_assignment_test.go +++ b/test/mocked/datasources/sensor_group_assignment_test.go @@ -1,11 +1,12 @@ package data_source_test import ( + "net/http" "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/util" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -23,10 +24,10 @@ func TestSensorGroupAssignmentDataSource(t *testing.T) { { PreConfig: func() { util.MockGetSensorGroupAssignment( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateSensorGroupAssignmentResponse("uid", ""), + util.GenerateSensorGroupAssignmentResponse("id", ""), }, ), 3, @@ -35,7 +36,7 @@ func TestSensorGroupAssignmentDataSource(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_sensor_group_assignment" "my_sensor_group_assignment" { filter = { - sensor_group_assignment_id = "uid" + sensor_group_assignment_id = "id" } } `, @@ -43,17 +44,17 @@ func TestSensorGroupAssignmentDataSource(t *testing.T) { resource.TestCheckResourceAttr( "data.uxi_sensor_group_assignment.my_sensor_group_assignment", "id", - "uid", + "id", ), resource.TestCheckResourceAttr( "data.uxi_sensor_group_assignment.my_sensor_group_assignment", "group_id", - "group_uid", + "group_id", ), resource.TestCheckResourceAttr( "data.uxi_sensor_group_assignment.my_sensor_group_assignment", "sensor_id", - "sensor_uid", + "sensor_id", ), ), }, @@ -63,10 +64,10 @@ func TestSensorGroupAssignmentDataSource(t *testing.T) { mockOAuth.Mock.Disable() } -func TestSensorGroupAssignmentDataSource429Handling(t *testing.T) { +func TestSensorGroupAssignmentDataSourceTooManyRequestsHandling(t *testing.T) { defer gock.Off() mockOAuth := util.MockOAuth() - var mock429 *gock.Response + var mockTooManyRequests *gock.Response resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -74,15 +75,15 @@ func TestSensorGroupAssignmentDataSource429Handling(t *testing.T) { // Read testing { PreConfig: func() { - mock429 = gock.New("https://test.api.capenetworks.com"). + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/sensor-group-assignments"). - Reply(429). + Reply(http.StatusTooManyRequests). SetHeaders(util.RateLimitingHeaders) util.MockGetSensorGroupAssignment( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateSensorGroupAssignmentResponse("uid", ""), + util.GenerateSensorGroupAssignmentResponse("id", ""), }, ), 3, @@ -91,7 +92,7 @@ func TestSensorGroupAssignmentDataSource429Handling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_sensor_group_assignment" "my_sensor_group_assignment" { filter = { - sensor_group_assignment_id = "uid" + sensor_group_assignment_id = "id" } } `, @@ -99,10 +100,10 @@ func TestSensorGroupAssignmentDataSource429Handling(t *testing.T) { resource.TestCheckResourceAttr( "data.uxi_sensor_group_assignment.my_sensor_group_assignment", "id", - "uid", + "id", ), func(s *terraform.State) error { - st.Assert(t, mock429.Mock.Request().Counter, 0) + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) return nil }, ), @@ -122,9 +123,9 @@ func TestSensorGroupAssignmentDataSourceHttpErrorHandling(t *testing.T) { PreConfig: func() { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/sensor-group-assignments"). - Reply(500). + Reply(http.StatusInternalServerError). JSON(map[string]interface{}{ - "httpStatusCode": 500, + "httpStatusCode": http.StatusInternalServerError, "errorCode": "HPE_GL_ERROR_INTERNAL_SERVER_ERROR", "message": "Current request cannot be processed due to unknown issue", "debugId": "12312-123123-123123-1231212", @@ -133,7 +134,7 @@ func TestSensorGroupAssignmentDataSourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_sensor_group_assignment" "my_sensor_group_assignment" { filter = { - sensor_group_assignment_id = "uid" + sensor_group_assignment_id = "id" } } `, @@ -144,7 +145,7 @@ func TestSensorGroupAssignmentDataSourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetSensorGroupAssignment( - "uid", + "id", util.GeneratePaginatedResponse([]map[string]interface{}{}), 1, ) @@ -152,7 +153,7 @@ func TestSensorGroupAssignmentDataSourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_sensor_group_assignment" "my_sensor_group_assignment" { filter = { - sensor_group_assignment_id = "uid" + sensor_group_assignment_id = "id" } } `, diff --git a/test/mocked/data-sources/sensor_test.go b/test/mocked/datasources/sensor_test.go similarity index 63% rename from test/mocked/data-sources/sensor_test.go rename to test/mocked/datasources/sensor_test.go index 4c2e0f0c..4f1124c5 100644 --- a/test/mocked/data-sources/sensor_test.go +++ b/test/mocked/datasources/sensor_test.go @@ -1,11 +1,12 @@ package data_source_test import ( + "net/http" "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/util" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -23,9 +24,9 @@ func TestSensorDataSource(t *testing.T) { { PreConfig: func() { util.MockGetSensor( - "uid", + "id", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateSensorResponseModel("uid", "")}, + []map[string]interface{}{util.GenerateSensorResponseModel("id", "")}, ), 3, ) @@ -33,12 +34,42 @@ func TestSensorDataSource(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_sensor" "my_sensor" { filter = { - sensor_id = "uid" + sensor_id = "id" } } `, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.uxi_sensor.my_sensor", "id", "uid"), + resource.TestCheckResourceAttr("data.uxi_sensor.my_sensor", "id", "id"), + resource.TestCheckResourceAttr("data.uxi_sensor.my_sensor", "name", "name"), + resource.TestCheckResourceAttr("data.uxi_sensor.my_sensor", "serial", "serial"), + resource.TestCheckResourceAttr( + "data.uxi_sensor.my_sensor", + "model_number", + "model_number", + ), + resource.TestCheckResourceAttr( + "data.uxi_sensor.my_sensor", + "wifi_mac_address", + "wifi_mac_address", + ), + resource.TestCheckResourceAttr( + "data.uxi_sensor.my_sensor", + "ethernet_mac_address", + "ethernet_mac_address", + ), + resource.TestCheckResourceAttr( + "data.uxi_sensor.my_sensor", + "address_note", + "address_note", + ), + resource.TestCheckResourceAttr("data.uxi_sensor.my_sensor", "latitude", "0"), + resource.TestCheckResourceAttr("data.uxi_sensor.my_sensor", "longitude", "0"), + resource.TestCheckResourceAttr("data.uxi_sensor.my_sensor", "notes", "notes"), + resource.TestCheckResourceAttr( + "data.uxi_sensor.my_sensor", + "pcap_mode", + "light", + ), ), }, }, @@ -47,10 +78,10 @@ func TestSensorDataSource(t *testing.T) { mockOAuth.Mock.Disable() } -func TestSensorDataSource429Handling(t *testing.T) { +func TestSensorDataSourceTooManyRequestsHandling(t *testing.T) { defer gock.Off() mockOAuth := util.MockOAuth() - var mock429 *gock.Response + var mockTooManyRequests *gock.Response resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -59,14 +90,14 @@ func TestSensorDataSource429Handling(t *testing.T) { // Test Read { PreConfig: func() { - mock429 = gock.New("https://test.api.capenetworks.com"). + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/sensors"). - Reply(429). + Reply(http.StatusTooManyRequests). SetHeaders(util.RateLimitingHeaders) util.MockGetSensor( - "uid", + "id", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateSensorResponseModel("uid", "")}, + []map[string]interface{}{util.GenerateSensorResponseModel("id", "")}, ), 3, ) @@ -74,14 +105,14 @@ func TestSensorDataSource429Handling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_sensor" "my_sensor" { filter = { - sensor_id = "uid" + sensor_id = "id" } } `, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.uxi_sensor.my_sensor", "id", "uid"), + resource.TestCheckResourceAttr("data.uxi_sensor.my_sensor", "id", "id"), func(s *terraform.State) error { - st.Assert(t, mock429.Mock.Request().Counter, 0) + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) return nil }, ), @@ -103,9 +134,9 @@ func TestSensorDataSourceHttpErrorHandling(t *testing.T) { PreConfig: func() { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/sensors"). - Reply(500). + Reply(http.StatusInternalServerError). JSON(map[string]interface{}{ - "httpStatusCode": 500, + "httpStatusCode": http.StatusInternalServerError, "errorCode": "HPE_GL_ERROR_INTERNAL_SERVER_ERROR", "message": "Current request cannot be processed due to unknown issue", "debugId": "12312-123123-123123-1231212", @@ -114,7 +145,7 @@ func TestSensorDataSourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_sensor" "my_sensor" { filter = { - sensor_id = "uid" + sensor_id = "id" } } `, @@ -126,7 +157,7 @@ func TestSensorDataSourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetSensor( - "uid", + "id", util.GeneratePaginatedResponse([]map[string]interface{}{}), 1, ) @@ -134,7 +165,7 @@ func TestSensorDataSourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_sensor" "my_sensor" { filter = { - sensor_id = "uid" + sensor_id = "id" } } `, diff --git a/test/mocked/data-sources/service_test.go b/test/mocked/datasources/service_test.go similarity index 68% rename from test/mocked/data-sources/service_test.go rename to test/mocked/datasources/service_test.go index 8af308ba..8ae8b3ae 100644 --- a/test/mocked/data-sources/service_test.go +++ b/test/mocked/datasources/service_test.go @@ -1,11 +1,12 @@ package data_source_test import ( + "net/http" "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/util" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -23,10 +24,10 @@ func TestServiceTestDataSource(t *testing.T) { { PreConfig: func() { util.MockGetServiceTest( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateServiceTestResponseModel("uid", ""), + util.GenerateServiceTestResponseModel("id", ""), }, ), 3, @@ -35,7 +36,7 @@ func TestServiceTestDataSource(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_service_test" "my_service_test" { filter = { - service_test_id = "uid" + service_test_id = "id" } } `, @@ -43,7 +44,32 @@ func TestServiceTestDataSource(t *testing.T) { resource.TestCheckResourceAttr( "data.uxi_service_test.my_service_test", "id", - "uid", + "id", + ), + resource.TestCheckResourceAttr( + "data.uxi_service_test.my_service_test", + "category", + "external", + ), + resource.TestCheckResourceAttr( + "data.uxi_service_test.my_service_test", + "name", + "name", + ), + resource.TestCheckResourceAttr( + "data.uxi_service_test.my_service_test", + "target", + "target", + ), + resource.TestCheckResourceAttr( + "data.uxi_service_test.my_service_test", + "template", + "template", + ), + resource.TestCheckResourceAttr( + "data.uxi_service_test.my_service_test", + "is_enabled", + "true", ), ), }, @@ -53,10 +79,10 @@ func TestServiceTestDataSource(t *testing.T) { mockOAuth.Mock.Disable() } -func TestServiceTestDataSource429Handling(t *testing.T) { +func TestServiceTestDataSourceTooManyRequestsHandling(t *testing.T) { defer gock.Off() mockOAuth := util.MockOAuth() - var mock429 *gock.Response + var mockTooManyRequests *gock.Response resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -65,15 +91,15 @@ func TestServiceTestDataSource429Handling(t *testing.T) { // Test Read { PreConfig: func() { - mock429 = gock.New("https://test.api.capenetworks.com"). + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/service-tests"). - Reply(429). + Reply(http.StatusTooManyRequests). SetHeaders(util.RateLimitingHeaders) util.MockGetServiceTest( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateServiceTestResponseModel("uid", ""), + util.GenerateServiceTestResponseModel("id", ""), }, ), 3, @@ -82,7 +108,7 @@ func TestServiceTestDataSource429Handling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_service_test" "my_service_test" { filter = { - service_test_id = "uid" + service_test_id = "id" } } `, @@ -90,10 +116,10 @@ func TestServiceTestDataSource429Handling(t *testing.T) { resource.TestCheckResourceAttr( "data.uxi_service_test.my_service_test", "id", - "uid", + "id", ), func(s *terraform.State) error { - st.Assert(t, mock429.Mock.Request().Counter, 0) + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) return nil }, ), @@ -115,9 +141,9 @@ func TestServiceTestDataSourceHttpErrorHandling(t *testing.T) { PreConfig: func() { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/service-tests"). - Reply(500). + Reply(http.StatusInternalServerError). JSON(map[string]interface{}{ - "httpStatusCode": 500, + "httpStatusCode": http.StatusInternalServerError, "errorCode": "HPE_GL_ERROR_INTERNAL_SERVER_ERROR", "message": "Current request cannot be processed due to unknown issue", "debugId": "12312-123123-123123-1231212", @@ -126,7 +152,7 @@ func TestServiceTestDataSourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_service_test" "my_service_test" { filter = { - service_test_id = "uid" + service_test_id = "id" } } `, @@ -138,7 +164,7 @@ func TestServiceTestDataSourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetServiceTest( - "uid", + "id", util.GeneratePaginatedResponse([]map[string]interface{}{}), 1, ) @@ -146,7 +172,7 @@ func TestServiceTestDataSourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_service_test" "my_service_test" { filter = { - service_test_id = "uid" + service_test_id = "id" } } `, diff --git a/test/mocked/data-sources/service_test_group_assignment_test.go b/test/mocked/datasources/service_test_group_assignment_test.go similarity index 79% rename from test/mocked/data-sources/service_test_group_assignment_test.go rename to test/mocked/datasources/service_test_group_assignment_test.go index 61ab2a1f..94ae56a3 100644 --- a/test/mocked/data-sources/service_test_group_assignment_test.go +++ b/test/mocked/datasources/service_test_group_assignment_test.go @@ -1,11 +1,12 @@ package data_source_test import ( + "net/http" "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/util" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -23,10 +24,10 @@ func TestServiceTestGroupAssignmentDataSource(t *testing.T) { { PreConfig: func() { util.MockGetServiceTestGroupAssignment( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateServiceTestGroupAssignmentResponse("uid", ""), + util.GenerateServiceTestGroupAssignmentResponse("id", ""), }, ), 3, @@ -35,7 +36,7 @@ func TestServiceTestGroupAssignmentDataSource(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_service_test_group_assignment" "my_service_test_group_assignment" { filter = { - service_test_group_assignment_id = "uid" + service_test_group_assignment_id = "id" } } `, @@ -43,17 +44,17 @@ func TestServiceTestGroupAssignmentDataSource(t *testing.T) { resource.TestCheckResourceAttr( "data.uxi_service_test_group_assignment.my_service_test_group_assignment", "id", - "uid", + "id", ), resource.TestCheckResourceAttr( "data.uxi_service_test_group_assignment.my_service_test_group_assignment", "group_id", - "group_uid", + "group_id", ), resource.TestCheckResourceAttr( "data.uxi_service_test_group_assignment.my_service_test_group_assignment", "service_test_id", - "service_test_uid", + "service_test_id", ), ), }, @@ -63,10 +64,10 @@ func TestServiceTestGroupAssignmentDataSource(t *testing.T) { mockOAuth.Mock.Disable() } -func TestServiceTestGroupAssignmentDataSource429Handling(t *testing.T) { +func TestServiceTestGroupAssignmentDataSourceTooManyRequestsHandling(t *testing.T) { defer gock.Off() mockOAuth := util.MockOAuth() - var mock429 *gock.Response + var mockTooManyRequests *gock.Response resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -74,15 +75,15 @@ func TestServiceTestGroupAssignmentDataSource429Handling(t *testing.T) { // Read testing { PreConfig: func() { - mock429 = gock.New("https://test.api.capenetworks.com"). + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/service-test-group-assignments"). - Reply(429). + Reply(http.StatusTooManyRequests). SetHeaders(util.RateLimitingHeaders) util.MockGetServiceTestGroupAssignment( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateServiceTestGroupAssignmentResponse("uid", ""), + util.GenerateServiceTestGroupAssignmentResponse("id", ""), }, ), 3, @@ -91,7 +92,7 @@ func TestServiceTestGroupAssignmentDataSource429Handling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_service_test_group_assignment" "my_service_test_group_assignment" { filter = { - service_test_group_assignment_id = "uid" + service_test_group_assignment_id = "id" } } `, @@ -99,10 +100,10 @@ func TestServiceTestGroupAssignmentDataSource429Handling(t *testing.T) { resource.TestCheckResourceAttr( "data.uxi_service_test_group_assignment.my_service_test_group_assignment", "id", - "uid", + "id", ), func(s *terraform.State) error { - st.Assert(t, mock429.Mock.Request().Counter, 0) + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) return nil }, ), @@ -122,9 +123,9 @@ func TestServiceTestGroupAssignmentDataSourceHttpErrorHandling(t *testing.T) { PreConfig: func() { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/service-test-group-assignments"). - Reply(500). + Reply(http.StatusInternalServerError). JSON(map[string]interface{}{ - "httpStatusCode": 500, + "httpStatusCode": http.StatusInternalServerError, "errorCode": "HPE_GL_ERROR_INTERNAL_SERVER_ERROR", "message": "Current request cannot be processed due to unknown issue", "debugId": "12312-123123-123123-1231212", @@ -133,7 +134,7 @@ func TestServiceTestGroupAssignmentDataSourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_service_test_group_assignment" "my_service_test_group_assignment" { filter = { - service_test_group_assignment_id = "uid" + service_test_group_assignment_id = "id" } } `, @@ -144,7 +145,7 @@ func TestServiceTestGroupAssignmentDataSourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetServiceTestGroupAssignment( - "uid", + "id", util.GeneratePaginatedResponse([]map[string]interface{}{}), 1, ) @@ -152,7 +153,7 @@ func TestServiceTestGroupAssignmentDataSourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_service_test_group_assignment" "my_service_test_group_assignment" { filter = { - service_test_group_assignment_id = "uid" + service_test_group_assignment_id = "id" } } `, diff --git a/test/mocked/data-sources/wired_network_test.go b/test/mocked/datasources/wired_network_test.go similarity index 85% rename from test/mocked/data-sources/wired_network_test.go rename to test/mocked/datasources/wired_network_test.go index 8b7c7661..bb8d4221 100644 --- a/test/mocked/data-sources/wired_network_test.go +++ b/test/mocked/datasources/wired_network_test.go @@ -1,11 +1,12 @@ package data_source_test import ( + "net/http" "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/util" "github.com/nbio/st" "github.com/h2non/gock" @@ -24,9 +25,9 @@ func TestWiredNetworkDataSource(t *testing.T) { { PreConfig: func() { util.MockGetWiredNetwork( - "uid", + "id", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}, + []map[string]interface{}{util.GenerateWiredNetworkResponse("id", "")}, ), 3, ) @@ -34,7 +35,7 @@ func TestWiredNetworkDataSource(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_wired_network" "my_wired_network" { filter = { - wired_network_id = "uid" + wired_network_id = "id" } } `, @@ -42,7 +43,7 @@ func TestWiredNetworkDataSource(t *testing.T) { resource.TestCheckResourceAttr( "data.uxi_wired_network.my_wired_network", "id", - "uid", + "id", ), resource.TestCheckResourceAttr( "data.uxi_wired_network.my_wired_network", @@ -92,10 +93,10 @@ func TestWiredNetworkDataSource(t *testing.T) { mockOAuth.Mock.Disable() } -func TestWiredNetworkDataSource429Handling(t *testing.T) { +func TestWiredNetworkDataSourceTooManyRequestsHandling(t *testing.T) { defer gock.Off() mockOAuth := util.MockOAuth() - var mock429 *gock.Response + var mockTooManyRequests *gock.Response resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -103,14 +104,14 @@ func TestWiredNetworkDataSource429Handling(t *testing.T) { // Read testing { PreConfig: func() { - mock429 = gock.New("https://test.api.capenetworks.com"). + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/wired-networks"). - Reply(429). + Reply(http.StatusTooManyRequests). SetHeaders(util.RateLimitingHeaders) util.MockGetWiredNetwork( - "uid", + "id", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}, + []map[string]interface{}{util.GenerateWiredNetworkResponse("id", "")}, ), 3, ) @@ -118,7 +119,7 @@ func TestWiredNetworkDataSource429Handling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_wired_network" "my_wired_network" { filter = { - wired_network_id = "uid" + wired_network_id = "id" } } `, @@ -126,10 +127,10 @@ func TestWiredNetworkDataSource429Handling(t *testing.T) { resource.TestCheckResourceAttr( "data.uxi_wired_network.my_wired_network", "id", - "uid", + "id", ), func(s *terraform.State) error { - st.Assert(t, mock429.Mock.Request().Counter, 0) + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) return nil }, ), @@ -150,9 +151,9 @@ func TestWiredNetworkAssignmentDataSourceHttpErrorHandling(t *testing.T) { PreConfig: func() { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/wired-networks"). - Reply(500). + Reply(http.StatusInternalServerError). JSON(map[string]interface{}{ - "httpStatusCode": 500, + "httpStatusCode": http.StatusInternalServerError, "errorCode": "HPE_GL_ERROR_INTERNAL_SERVER_ERROR", "message": "Current request cannot be processed due to unknown issue", "debugId": "12312-123123-123123-1231212", @@ -161,7 +162,7 @@ func TestWiredNetworkAssignmentDataSourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_wired_network" "my_wired_network" { filter = { - wired_network_id = "uid" + wired_network_id = "id" } } `, @@ -172,7 +173,7 @@ func TestWiredNetworkAssignmentDataSourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetWiredNetwork( - "uid", + "id", util.GeneratePaginatedResponse([]map[string]interface{}{}), 1, ) @@ -180,7 +181,7 @@ func TestWiredNetworkAssignmentDataSourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_wired_network" "my_wired_network" { filter = { - wired_network_id = "uid" + wired_network_id = "id" } } `, diff --git a/test/mocked/data-sources/wireless_network_test.go b/test/mocked/datasources/wireless_network_test.go similarity index 84% rename from test/mocked/data-sources/wireless_network_test.go rename to test/mocked/datasources/wireless_network_test.go index e89e3f7d..2813a5be 100644 --- a/test/mocked/data-sources/wireless_network_test.go +++ b/test/mocked/datasources/wireless_network_test.go @@ -1,11 +1,12 @@ package data_source_test import ( + "net/http" "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/util" "github.com/nbio/st" "github.com/h2non/gock" @@ -24,10 +25,10 @@ func TestWirelessNetworkDataSource(t *testing.T) { { PreConfig: func() { util.MockGetWirelessNetwork( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWirelessNetworkResponse("uid", ""), + util.GenerateWirelessNetworkResponse("id", ""), }, ), 3, @@ -36,7 +37,7 @@ func TestWirelessNetworkDataSource(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_wireless_network" "my_wireless_network" { filter = { - wireless_network_id = "uid" + wireless_network_id = "id" } } `, @@ -44,7 +45,7 @@ func TestWirelessNetworkDataSource(t *testing.T) { resource.TestCheckResourceAttr( "data.uxi_wireless_network.my_wireless_network", "id", - "uid", + "id", ), resource.TestCheckResourceAttr( "data.uxi_wireless_network.my_wireless_network", @@ -104,10 +105,10 @@ func TestWirelessNetworkDataSource(t *testing.T) { mockOAuth.Mock.Disable() } -func TestWirelessNetworkDataSource429Handling(t *testing.T) { +func TestWirelessNetworkDataSourceTooManyRequestsHandling(t *testing.T) { defer gock.Off() mockOAuth := util.MockOAuth() - var mock429 *gock.Response + var mockTooManyRequests *gock.Response resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -115,15 +116,15 @@ func TestWirelessNetworkDataSource429Handling(t *testing.T) { // Read testing { PreConfig: func() { - mock429 = gock.New("https://test.api.capenetworks.com"). + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/wireless-networks"). - Reply(429). + Reply(http.StatusTooManyRequests). SetHeaders(util.RateLimitingHeaders) util.MockGetWirelessNetwork( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWirelessNetworkResponse("uid", ""), + util.GenerateWirelessNetworkResponse("id", ""), }, ), 3, @@ -132,7 +133,7 @@ func TestWirelessNetworkDataSource429Handling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_wireless_network" "my_wireless_network" { filter = { - wireless_network_id = "uid" + wireless_network_id = "id" } } `, @@ -140,10 +141,10 @@ func TestWirelessNetworkDataSource429Handling(t *testing.T) { resource.TestCheckResourceAttr( "data.uxi_wireless_network.my_wireless_network", "id", - "uid", + "id", ), func(s *terraform.State) error { - st.Assert(t, mock429.Mock.Request().Counter, 0) + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) return nil }, ), @@ -164,9 +165,9 @@ func TestWirelessNetworkAssignmentDataSourceHttpErrorHandling(t *testing.T) { PreConfig: func() { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/wireless-networks"). - Reply(500). + Reply(http.StatusInternalServerError). JSON(map[string]interface{}{ - "httpStatusCode": 500, + "httpStatusCode": http.StatusInternalServerError, "errorCode": "HPE_GL_ERROR_INTERNAL_SERVER_ERROR", "message": "Current request cannot be processed due to unknown issue", "debugId": "12312-123123-123123-1231212", @@ -175,7 +176,7 @@ func TestWirelessNetworkAssignmentDataSourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_wireless_network" "my_wireless_network" { filter = { - wireless_network_id = "uid" + wireless_network_id = "id" } } `, @@ -186,7 +187,7 @@ func TestWirelessNetworkAssignmentDataSourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetWirelessNetwork( - "uid", + "id", util.GeneratePaginatedResponse([]map[string]interface{}{}), 1, ) @@ -194,7 +195,7 @@ func TestWirelessNetworkAssignmentDataSourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` data "uxi_wireless_network" "my_wireless_network" { filter = { - wireless_network_id = "uid" + wireless_network_id = "id" } } `, diff --git a/test/mocked/provider/provider.go b/test/mocked/provider/provider.go index b8c5cd1b..deacb4bb 100644 --- a/test/mocked/provider/provider.go +++ b/test/mocked/provider/provider.go @@ -1,7 +1,7 @@ package provider import ( - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider" "github.com/hashicorp/terraform-plugin-framework/providerserver" "github.com/hashicorp/terraform-plugin-go/tfprotov6" ) diff --git a/test/mocked/resources/agent_group_assignment_test.go b/test/mocked/resources/agent_group_assignment_test.go index e7145ba4..183959af 100644 --- a/test/mocked/resources/agent_group_assignment_test.go +++ b/test/mocked/resources/agent_group_assignment_test.go @@ -1,12 +1,16 @@ package resource_test import ( - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" + "net/http" + "regexp" "testing" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/util" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" + "github.com/nbio/st" ) func TestAgentGroupAssignmentResource(t *testing.T) { @@ -21,10 +25,10 @@ func TestAgentGroupAssignmentResource(t *testing.T) { PreConfig: func() { // required for agent import util.MockGetAgent( - "agent_uid", + "agent_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateAgentResponseModel("agent_uid", ""), + util.GenerateAgentResponseModel("agent_id", ""), }, ), 2, @@ -32,17 +36,17 @@ func TestAgentGroupAssignmentResource(t *testing.T) { // required for group create util.MockPostGroup( - util.GenerateGroupRequestModel("group_uid", "", ""), + util.GenerateGroupRequestModel("group_id", "", ""), util.StructToMap( - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), ), 1, ) util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 1, @@ -50,16 +54,16 @@ func TestAgentGroupAssignmentResource(t *testing.T) { // required for agent group assignment create util.MockPostAgentGroupAssignment( - util.GenerateAgentGroupAssignmentRequest("agent_group_assignment_uid", ""), - util.GenerateAgentGroupAssignmentResponse("agent_group_assignment_uid", ""), + util.GenerateAgentGroupAssignmentRequest("agent_group_assignment_id", ""), + util.GenerateAgentGroupAssignmentResponse("agent_group_assignment_id", ""), 1, ) util.MockGetAgentGroupAssignment( - "agent_group_assignment_uid", + "agent_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateAgentGroupAssignmentResponse( - "agent_group_assignment_uid", + "agent_group_assignment_id", "", ), }, @@ -71,7 +75,7 @@ func TestAgentGroupAssignmentResource(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" } resource "uxi_agent" "my_agent" { @@ -82,7 +86,7 @@ func TestAgentGroupAssignmentResource(t *testing.T) { import { to = uxi_agent.my_agent - id = "agent_uid" + id = "agent_id" } resource "uxi_agent_group_assignment" "my_agent_group_assignment" { @@ -93,17 +97,17 @@ func TestAgentGroupAssignmentResource(t *testing.T) { resource.TestCheckResourceAttr( "uxi_agent_group_assignment.my_agent_group_assignment", "agent_id", - "agent_uid", + "agent_id", ), resource.TestCheckResourceAttr( "uxi_agent_group_assignment.my_agent_group_assignment", "group_id", - "group_uid", + "group_id", ), resource.TestCheckResourceAttr( "uxi_agent_group_assignment.my_agent_group_assignment", "id", - "agent_group_assignment_uid", + "agent_group_assignment_id", ), ), }, @@ -111,11 +115,11 @@ func TestAgentGroupAssignmentResource(t *testing.T) { { PreConfig: func() { util.MockGetAgentGroupAssignment( - "agent_group_assignment_uid", + "agent_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateAgentGroupAssignmentResponse( - "agent_group_assignment_uid", + "agent_group_assignment_id", "", ), }, @@ -127,62 +131,63 @@ func TestAgentGroupAssignmentResource(t *testing.T) { ImportState: true, ImportStateVerify: true, }, - // Update and Read testing + // Update testing { PreConfig: func() { util.MockGetAgent( - "agent_uid_2", + "agent_id_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateAgentResponseModel("agent_uid_2", "_2"), + util.GenerateAgentResponseModel("agent_id_2", "_2"), }, ), 2, ) util.MockGetAgent( - "agent_uid", + "agent_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateAgentResponseModel("agent_uid", ""), + util.GenerateAgentResponseModel("agent_id", ""), }, ), 2, ) util.MockGetGroup( - "group_uid_2", + "group_id_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_id_2", "_2", "_2"), }, ), 1, ) util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 2, ) + util.MockDeleteAgentGroupAssignment("agent_group_assignment_id", 1) // required for creating another group util.MockPostGroup( - util.GenerateGroupRequestModel("group_uid_2", "_2", "_2"), + util.GenerateGroupRequestModel("group_id_2", "_2", "_2"), util.StructToMap( - util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_id_2", "_2", "_2"), ), 1, ) // required for agent group assignment create util.MockGetAgentGroupAssignment( - "agent_group_assignment_uid_2", + "agent_group_assignment_id_2", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateAgentGroupAssignmentResponse( - "agent_group_assignment_uid_2", + "agent_group_assignment_id_2", "_2", ), }, @@ -190,11 +195,11 @@ func TestAgentGroupAssignmentResource(t *testing.T) { 2, ) util.MockGetAgentGroupAssignment( - "agent_group_assignment_uid", + "agent_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateAgentGroupAssignmentResponse( - "agent_group_assignment_uid", + "agent_group_assignment_id", "", ), }, @@ -203,11 +208,11 @@ func TestAgentGroupAssignmentResource(t *testing.T) { ) util.MockPostAgentGroupAssignment( util.GenerateAgentGroupAssignmentRequest( - "agent_group_assignment_uid_2", + "agent_group_assignment_id_2", "_2", ), util.GenerateAgentGroupAssignmentResponse( - "agent_group_assignment_uid_2", + "agent_group_assignment_id_2", "_2", ), 1, @@ -217,7 +222,7 @@ func TestAgentGroupAssignmentResource(t *testing.T) { // the original resources resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" } resource "uxi_agent" "my_agent" { @@ -228,13 +233,13 @@ func TestAgentGroupAssignmentResource(t *testing.T) { import { to = uxi_agent.my_agent - id = "agent_uid" + id = "agent_id" } // the new resources we wanna update the assignment to resource "uxi_group" "my_group_2" { name = "name_2" - parent_group_id = "parent_uid_2" + parent_group_id = "parent_id_2" } resource "uxi_agent" "my_agent_2" { @@ -245,7 +250,7 @@ func TestAgentGroupAssignmentResource(t *testing.T) { import { to = uxi_agent.my_agent_2 - id = "agent_uid_2" + id = "agent_id_2" } // the assignment update, updated from agent/group to agent_2/group_2 @@ -257,65 +262,668 @@ func TestAgentGroupAssignmentResource(t *testing.T) { resource.TestCheckResourceAttr( "uxi_agent_group_assignment.my_agent_group_assignment", "agent_id", - "agent_uid_2", + "agent_id_2", ), resource.TestCheckResourceAttr( "uxi_agent_group_assignment.my_agent_group_assignment", "group_id", - "group_uid_2", + "group_id_2", ), resource.TestCheckResourceAttr( "uxi_agent_group_assignment.my_agent_group_assignment", "id", - "agent_group_assignment_uid_2", + "agent_group_assignment_id_2", ), ), }, - // Delete testing automatically occurs in TestCase + // Delete testing { PreConfig: func() { util.MockGetAgent( - "agent_uid", + "agent_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateAgentResponseModel("agent_uid", ""), + util.GenerateAgentResponseModel("agent_id", ""), }, ), 2, ) util.MockGetAgent( - "agent_uid_2", + "agent_id_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateAgentResponseModel("agent_uid_2", "_2"), + util.GenerateAgentResponseModel("agent_id_2", "_2"), }, ), 1, ) util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 2, ) util.MockGetGroup( - "group_uid_2", + "group_id_2", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("group_id_2", "_2", "_2"), + }, + ), + 1, + ) + util.MockGetAgentGroupAssignment( + "agent_group_assignment_id", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateAgentGroupAssignmentResponse( + "agent_group_assignment_id", + "", + ), + }, + ), + 2, + ) + util.MockGetAgentGroupAssignment( + "agent_group_assignment_id_2", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateAgentGroupAssignmentResponse( + "agent_group_assignment_id_2", + "_2", + ), + }, + ), + 1, + ) + util.MockDeleteGroup("group_id", 1) + util.MockDeleteGroup("group_id_2", 1) + util.MockDeleteAgent("agent_id", 1) + util.MockDeleteAgent("agent_id_2", 1) + util.MockDeleteAgentGroupAssignment("agent_group_assignment_id_2", 1) + }, + Config: provider.ProviderConfig, + }, + }, + }) + + mockOAuth.Mock.Disable() +} + +func TestAgentGroupAssignmentResourceTooManyRequestsHandling(t *testing.T) { + defer gock.Off() + mockOAuth := util.MockOAuth() + var mockTooManyRequests *gock.Response + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Creating a agent group assignment + { + PreConfig: func() { + // required for agent import + util.MockGetAgent( + "agent_id", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateAgentResponseModel("agent_id", ""), + }, + ), + 2, + ) + + // required for agent group assignment create + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). + Post("/networking-uxi/v1alpha1/agent-group-assignments"). + Reply(http.StatusTooManyRequests). + SetHeaders(util.RateLimitingHeaders) + util.MockPostGroup( + util.GenerateGroupRequestModel("group_id", "", ""), + util.StructToMap( + util.GenerateNonRootGroupResponseModel("group_id", "", ""), + ), + 1, + ) + util.MockGetGroup( + "group_id", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("group_id", "", ""), + }, + ), + 1, + ) + + // required for agent group assignment create + util.MockPostAgentGroupAssignment( + util.GenerateAgentGroupAssignmentRequest("agent_group_assignment_id", ""), + util.GenerateAgentGroupAssignmentResponse("agent_group_assignment_id", ""), + 1, + ) + util.MockGetAgentGroupAssignment( + "agent_group_assignment_id", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateAgentGroupAssignmentResponse( + "agent_group_assignment_id", + "", + ), + }, + ), + 1, + ) + }, + + Config: provider.ProviderConfig + ` + resource "uxi_group" "my_group" { + name = "name" + parent_group_id = "parent_id" + } + + resource "uxi_agent" "my_agent" { + name = "name" + notes = "notes" + pcap_mode = "light" + } + + import { + to = uxi_agent.my_agent + id = "agent_id" + } + + resource "uxi_agent_group_assignment" "my_agent_group_assignment" { + agent_id = uxi_agent.my_agent.id + group_id = uxi_group.my_group.id + }`, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr( + "uxi_agent_group_assignment.my_agent_group_assignment", + "id", + "agent_group_assignment_id", + ), + func(s *terraform.State) error { + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil + }, + ), + }, + // ImportState testing + { + PreConfig: func() { + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). + Get("/networking-uxi/v1alpha1/agent-group-assignments"). + Reply(http.StatusTooManyRequests). + SetHeaders(util.RateLimitingHeaders) + util.MockGetAgentGroupAssignment( + "agent_group_assignment_id", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateAgentGroupAssignmentResponse( + "agent_group_assignment_id", + "", + ), + }, + ), + 1, + ) + }, + ResourceName: "uxi_agent_group_assignment.my_agent_group_assignment", + ImportState: true, + ImportStateVerify: true, + Check: func(s *terraform.State) error { + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil + }, + }, + // Delete testing + { + PreConfig: func() { + util.MockGetAgent( + "agent_id", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateAgentResponseModel("agent_id", ""), + }, + ), + 1, + ) + util.MockGetGroup( + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 1, ) - util.MockDeleteGroup("group_uid", 1) - util.MockDeleteGroup("group_uid_2", 1) - util.MockDeleteAgent("agent_uid", 1) - util.MockDeleteAgent("agent_uid_2", 1) + util.MockGetAgentGroupAssignment( + "agent_group_assignment_id", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateAgentGroupAssignmentResponse( + "agent_group_assignment_id", + "", + ), + }, + ), + 1, + ) + util.MockDeleteGroup("group_id", 1) + util.MockDeleteAgent("agent_id", 1) + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). + Delete("/networking-uxi/v1alpha1/agent-group-assignments/agent_group_assignment_id"). + Reply(http.StatusTooManyRequests). + SetHeaders(util.RateLimitingHeaders) + util.MockDeleteAgentGroupAssignment("agent_group_assignment_id", 1) }, Config: provider.ProviderConfig, + Check: func(s *terraform.State) error { + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil + }, + }, + }, + }) + + mockOAuth.Mock.Disable() +} + +func TestAgentGroupAssignmentResourceHttpErrorHandling(t *testing.T) { + defer gock.Off() + mockOAuth := util.MockOAuth() + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Creating an agent group assignment - errors + { + PreConfig: func() { + util.MockGetAgent( + "agent_id", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateAgentResponseModel("agent_id", ""), + }, + ), + 2, + ) + + // required for group create + util.MockPostGroup( + util.GenerateGroupRequestModel("group_id", "", ""), + util.StructToMap( + util.GenerateNonRootGroupResponseModel("group_id", "", ""), + ), + 1, + ) + util.MockGetGroup("group_id", util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("group_id", "", ""), + }, + ), + 2, + ) + + // agent group assignment create + gock.New("https://test.api.capenetworks.com"). + Post("/networking-uxi/v1alpha1/agent-group-assignments"). + Reply(http.StatusBadRequest). + JSON(map[string]interface{}{ + "httpStatusCode": http.StatusBadRequest, + "errorCode": "HPE_GL_ERROR_BAD_REQUEST", + "message": "Validation error - bad request", + "debugId": "12312-123123-123123-1231212", + }) + }, + + Config: provider.ProviderConfig + ` + resource "uxi_group" "my_group" { + name = "name" + parent_group_id = "parent_id" + } + + resource "uxi_agent" "my_agent" { + name = "name" + notes = "notes" + pcap_mode = "light" + } + + import { + to = uxi_agent.my_agent + id = "agent_id" + } + + resource "uxi_agent_group_assignment" "my_agent_group_assignment" { + agent_id = uxi_agent.my_agent.id + group_id = uxi_group.my_group.id + }`, + ExpectError: regexp.MustCompile( + `(?s)Validation error - bad request\s*DebugID: 12312-123123-123123-1231212`, + ), + }, + // read not found error + { + PreConfig: func() { + util.MockGetAgent( + "agent_id", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateAgentResponseModel("agent_id", ""), + }, + ), + 2, + ) + + // required for group create + util.MockPostGroup( + util.GenerateGroupRequestModel("group_id", "", ""), + util.StructToMap( + util.GenerateNonRootGroupResponseModel("group_id", "", ""), + ), + 1, + ) + util.MockGetGroup("group_id", util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("group_id", "", ""), + }, + ), + 2, + ) + + // agent group assignment read + util.MockGetAgentGroupAssignment( + "agent_group_assignment_id", + util.GeneratePaginatedResponse([]map[string]interface{}{}), + 1, + ) + }, + Config: provider.ProviderConfig + ` + resource "uxi_group" "my_group" { + name = "name" + parent_group_id = "parent_id" + } + + resource "uxi_agent" "my_agent" { + name = "name" + notes = "notes" + pcap_mode = "light" + } + + import { + to = uxi_agent.my_agent + id = "agent_id" + } + + resource "uxi_agent_group_assignment" "my_agent_group_assignment" { + agent_id = uxi_agent.my_agent.id + group_id = uxi_group.my_group.id + } + + import { + to = uxi_agent_group_assignment.my_agent_group_assignment + id = "agent_group_assignment_id" + } + `, + ExpectError: regexp.MustCompile(`Error: Cannot import non-existent remote object`), + }, + // Read 5xx error + { + PreConfig: func() { + util.MockGetAgent( + "agent_id", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateAgentResponseModel("agent_id", ""), + }, + ), + 2, + ) + + // required for group create + util.MockPostGroup( + util.GenerateGroupRequestModel("group_id", "", ""), + util.StructToMap( + util.GenerateNonRootGroupResponseModel("group_id", "", ""), + ), + 1, + ) + util.MockGetGroup("group_id", util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("group_id", "", ""), + }, + ), + 2, + ) + + // agent group assignment read + gock.New("https://test.api.capenetworks.com"). + Get("/networking-uxi/v1alpha1/agent-group-assignments"). + Reply(http.StatusInternalServerError). + JSON(map[string]interface{}{ + "httpStatusCode": http.StatusInternalServerError, + "errorCode": "HPE_GL_ERROR_INTERNAL_SERVER_ERROR", + "message": "Current request cannot be processed due to unknown issue", + "debugId": "12312-123123-123123-1231212", + }) + }, + Config: provider.ProviderConfig + ` + resource "uxi_group" "my_group" { + name = "name" + parent_group_id = "parent_id" + } + + resource "uxi_agent" "my_agent" { + name = "name" + notes = "notes" + pcap_mode = "light" + } + + import { + to = uxi_agent.my_agent + id = "agent_id" + } + + resource "uxi_agent_group_assignment" "my_agent_group_assignment" { + agent_id = uxi_agent.my_agent.id + group_id = uxi_group.my_group.id + } + + import { + to = uxi_agent_group_assignment.my_agent_group_assignment + id = "agent_group_assignment_id" + } + `, + + ExpectError: regexp.MustCompile( + `(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`, + ), + }, + // Actually creating an agent group assignment - for next step + { + PreConfig: func() { + util.MockGetAgent( + "agent_id", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateAgentResponseModel("agent_id", ""), + }, + ), + 2, + ) + + // required for group create + util.MockPostGroup( + util.GenerateGroupRequestModel("group_id", "", ""), + util.StructToMap( + util.GenerateNonRootGroupResponseModel("group_id", "", ""), + ), + 1, + ) + util.MockGetGroup("group_id", util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("group_id", "", ""), + }, + ), + 2, + ) + + // required for agent group assignment create + util.MockPostAgentGroupAssignment( + util.GenerateAgentGroupAssignmentRequest( + "agent_group_assignment_id", + "", + ), + util.GenerateAgentGroupAssignmentResponse( + "agent_group_assignment_id", + "", + ), + 1, + ) + util.MockGetAgentGroupAssignment( + "agent_group_assignment_id", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateAgentGroupAssignmentResponse( + "agent_group_assignment_id", + "", + ), + }, + ), + 1, + ) + }, + + Config: provider.ProviderConfig + ` + resource "uxi_group" "my_group" { + name = "name" + parent_group_id = "parent_id" + } + + resource "uxi_agent" "my_agent" { + name = "name" + notes = "notes" + pcap_mode = "light" + + } + + import { + to = uxi_agent.my_agent + id = "agent_id" + } + + resource "uxi_agent_group_assignment" "my_agent_group_assignment" { + agent_id = uxi_agent.my_agent.id + group_id = uxi_group.my_group.id + }`, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr( + "uxi_agent_group_assignment.my_agent_group_assignment", + "agent_id", + "agent_id", + ), + ), + }, + // Delete agent-group assignment and remove agents from state - errors + { + PreConfig: func() { + util.MockGetAgent( + "agent_id", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateAgentResponseModel("agent_id", ""), + }, + ), + 1, + ) + util.MockGetGroup("group_id", util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("group_id", "", ""), + }, + ), + 1, + ) + util.MockGetAgentGroupAssignment( + "agent_group_assignment_id", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateAgentGroupAssignmentResponse( + "agent_group_assignment_id", + "", + ), + }, + ), + 1, + ) + + // agent group assignment create + gock.New("https://test.api.capenetworks.com"). + Delete("/networking-uxi/v1alpha1/agent-group-assignments"). + Reply(http.StatusForbidden). + JSON(map[string]interface{}{ + "httpStatusCode": http.StatusForbidden, + "errorCode": "HPE_GL_ERROR_FORBIDDEN", + "message": "Forbidden - user has insufficient permissions to complete the request", + "debugId": "12312-123123-123123-1231212", + }) + + }, + Config: provider.ProviderConfig + ` + removed { + from = uxi_agent.my_agent + + lifecycle { + destroy = false + } + }`, + ExpectError: regexp.MustCompile( + `(?s)Forbidden - user has insufficient permissions to complete the request\s*DebugID: 12312-123123-123123-1231212`, + ), + }, + // Actually delete agent-group assignment and remove agents from state + { + PreConfig: func() { + util.MockGetAgent( + "agent_id", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateAgentResponseModel("agent_id", ""), + }, + ), + 1, + ) + util.MockGetGroup("group_id", util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateNonRootGroupResponseModel("group_id", "", ""), + }, + ), + 1, + ) + util.MockGetAgentGroupAssignment( + "agent_group_assignment_id", + util.GeneratePaginatedResponse( + []map[string]interface{}{ + util.GenerateAgentGroupAssignmentResponse( + "agent_group_assignment_id", + "", + ), + }, + ), + 1, + ) + util.MockDeleteGroup("group_id", 1) + util.MockDeleteAgentGroupAssignment("agent_group_assignment_id", 1) + }, + Config: provider.ProviderConfig + ` + removed { + from = uxi_agent.my_agent + + lifecycle { + destroy = false + } + }`, }, }, }) diff --git a/test/mocked/resources/agent_test.go b/test/mocked/resources/agent_test.go index 83e1cb3e..86a921bd 100644 --- a/test/mocked/resources/agent_test.go +++ b/test/mocked/resources/agent_test.go @@ -1,12 +1,12 @@ package resource_test import ( + "net/http" "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/resources" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/util" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -38,9 +38,9 @@ func TestAgentResource(t *testing.T) { { PreConfig: func() { util.MockGetAgent( - "uid", + "id", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}, + []map[string]interface{}{util.GenerateAgentResponseModel("id", "")}, ), 2, ) @@ -54,23 +54,23 @@ func TestAgentResource(t *testing.T) { import { to = uxi_agent.my_agent - id = "uid" + id = "id" }`, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("uxi_agent.my_agent", "name", "name"), resource.TestCheckResourceAttr("uxi_agent.my_agent", "notes", "notes"), resource.TestCheckResourceAttr("uxi_agent.my_agent", "pcap_mode", "light"), - resource.TestCheckResourceAttr("uxi_agent.my_agent", "id", "uid"), + resource.TestCheckResourceAttr("uxi_agent.my_agent", "id", "id"), ), }, // ImportState testing { PreConfig: func() { util.MockGetAgent( - "uid", + "id", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}, + []map[string]interface{}{util.GenerateAgentResponseModel("id", "")}, ), 1, ) @@ -84,20 +84,23 @@ func TestAgentResource(t *testing.T) { PreConfig: func() { // original util.MockGetAgent( - "uid", + "id", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}, + []map[string]interface{}{util.GenerateAgentResponseModel("id", "")}, ), 1, ) - resources.UpdateAgent = func(request resources.AgentUpdateRequestModel) resources.AgentResponseModel { - return util.GenerateMockedAgentResponseModel("uid", "_2") - } + util.MockUpdateAgent( + "id", + util.GenerateAgentRequestUpdateModel("_2"), + util.GenerateAgentResponseModel("id", "_2"), + 1, + ) // updated util.MockGetAgent( - "uid", + "id", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateAgentResponseModel("uid", "_2")}, + []map[string]interface{}{util.GenerateAgentResponseModel("id", "_2")}, ), 1, ) @@ -117,11 +120,11 @@ func TestAgentResource(t *testing.T) { // Delete testing { PreConfig: func() { - util.MockGetAgent("uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}), + util.MockGetAgent("id", util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateAgentResponseModel("id", "")}), 1, ) - util.MockDeleteAgent("uid", 1) + util.MockDeleteAgent("id", 1) }, Config: provider.ProviderConfig, }, @@ -131,10 +134,10 @@ func TestAgentResource(t *testing.T) { mockOAuth.Mock.Disable() } -func TestAgentResource429Handling(t *testing.T) { +func TestAgentResourceTooManyRequestsHandling(t *testing.T) { defer gock.Off() mockOAuth := util.MockOAuth() - var request429 *gock.Response + var mockTooManyRequests *gock.Response resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -146,12 +149,12 @@ func TestAgentResource429Handling(t *testing.T) { // Importing a agent { PreConfig: func() { - request429 = gock.New("https://test.api.capenetworks.com"). + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/agents"). - Reply(429). + Reply(http.StatusTooManyRequests). SetHeaders(util.RateLimitingHeaders) - util.MockGetAgent("uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}), + util.MockGetAgent("id", util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateAgentResponseModel("id", "")}), 2, ) }, @@ -164,13 +167,57 @@ func TestAgentResource429Handling(t *testing.T) { import { to = uxi_agent.my_agent - id = "uid" + id = "id" }`, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_agent.my_agent", "id", "uid"), + resource.TestCheckResourceAttr("uxi_agent.my_agent", "id", "id"), + func(s *terraform.State) error { + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil + }, + ), + }, + // Update testing + { + PreConfig: func() { + // original + util.MockGetAgent( + "id", + util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateAgentResponseModel("id", "")}, + ), + 1, + ) + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). + Patch("/networking-uxi/v1alpha1/agents"). + Reply(http.StatusTooManyRequests). + SetHeaders(util.RateLimitingHeaders) + util.MockUpdateAgent( + "id", + util.GenerateAgentRequestUpdateModel("_2"), + util.GenerateAgentResponseModel("id", "_2"), + 1, + ) + // updated + util.MockGetAgent( + "id", + util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateAgentResponseModel("id", "_2")}, + ), + 1, + ) + }, + Config: provider.ProviderConfig + ` + resource "uxi_agent" "my_agent" { + name = "name_2" + notes = "notes_2" + pcap_mode = "light_2" + }`, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("uxi_agent.my_agent", "name", "name_2"), func(s *terraform.State) error { - st.Assert(t, request429.Mock.Request().Counter, 0) + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) return nil }, ), @@ -178,20 +225,20 @@ func TestAgentResource429Handling(t *testing.T) { // Delete testing { PreConfig: func() { - util.MockGetAgent("uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}), + util.MockGetAgent("id", util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateAgentResponseModel("id", "")}), 1, ) - request429 = gock.New("https://test.api.capenetworks.com"). - Delete("/networking-uxi/v1alpha1/agents/uid"). - Reply(429). + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). + Delete("/networking-uxi/v1alpha1/agents/id"). + Reply(http.StatusTooManyRequests). SetHeaders(util.RateLimitingHeaders) - util.MockDeleteAgent("uid", 1) + util.MockDeleteAgent("id", 1) }, Config: provider.ProviderConfig, Check: resource.ComposeAggregateTestCheckFunc( func(s *terraform.State) error { - st.Assert(t, request429.Mock.Request().Counter, 0) + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) return nil }, ), @@ -218,9 +265,9 @@ func TestAgentResourceHttpErrorHandling(t *testing.T) { PreConfig: func() { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/agents"). - Reply(500). + Reply(http.StatusInternalServerError). JSON(map[string]interface{}{ - "httpStatusCode": 500, + "httpStatusCode": http.StatusInternalServerError, "errorCode": "HPE_GL_ERROR_INTERNAL_SERVER_ERROR", "message": "Current request cannot be processed due to unknown issue", "debugId": "12312-123123-123123-1231212", @@ -235,7 +282,7 @@ func TestAgentResourceHttpErrorHandling(t *testing.T) { import { to = uxi_agent.my_agent - id = "uid" + id = "id" }`, ExpectError: regexp.MustCompile( @@ -246,7 +293,7 @@ func TestAgentResourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetAgent( - "uid", + "id", util.GeneratePaginatedResponse([]map[string]interface{}{}), 1, ) @@ -260,7 +307,7 @@ func TestAgentResourceHttpErrorHandling(t *testing.T) { import { to = uxi_agent.my_agent - id = "uid" + id = "id" }`, ExpectError: regexp.MustCompile(`Error: Cannot import non-existent remote object`), @@ -269,9 +316,9 @@ func TestAgentResourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetAgent( - "uid", + "id", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}, + []map[string]interface{}{util.GenerateAgentResponseModel("id", "")}, ), 2, ) @@ -285,27 +332,60 @@ func TestAgentResourceHttpErrorHandling(t *testing.T) { import { to = uxi_agent.my_agent - id = "uid" + id = "id" }`, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_agent.my_agent", "id", "uid"), + resource.TestCheckResourceAttr("uxi_agent.my_agent", "id", "id"), + ), + }, + // update 4xx + { + PreConfig: func() { + // original + util.MockGetAgent( + "id", + util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateAgentResponseModel("id", "")}, + ), + 1, + ) + // patch agent - with error + gock.New("https://test.api.capenetworks.com"). + Patch("/networking-uxi/v1alpha1/agents/id"). + Reply(http.StatusUnprocessableEntity). + JSON(map[string]interface{}{ + "httpStatusCode": http.StatusUnprocessableEntity, + "errorCode": "HPE_GL_UXI_INVALID_PCAP_MODE_ERROR", + "message": "Unable to update agent - pcap_mode must be one the following ['light', 'full', 'off'].", + "debugId": "12312-123123-123123-1231212", + "type": "hpe.greenlake.uxi.invalid_pcap_mode", + }) + }, + Config: provider.ProviderConfig + ` + resource "uxi_agent" "my_agent" { + name = "name_2" + notes = "notes_2" + pcap_mode = "light_2" + }`, + ExpectError: regexp.MustCompile( + `(?s)Unable to update agent - pcap_mode must be one the following \['light',\s*'full', 'off'\].\s*DebugID: 12312-123123-123123-1231212`, ), }, // Delete 4xx { PreConfig: func() { // existing agent - util.MockGetAgent("uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}), + util.MockGetAgent("id", util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateAgentResponseModel("id", "")}), 1, ) // delete agent - with error gock.New("https://test.api.capenetworks.com"). - Delete("/networking-uxi/v1alpha1/agents/uid"). - Reply(422). + Delete("/networking-uxi/v1alpha1/agents/id"). + Reply(http.StatusUnprocessableEntity). JSON(map[string]interface{}{ - "httpStatusCode": 422, + "httpStatusCode": http.StatusUnprocessableEntity, "errorCode": "HPE_GL_NETWORKING_UXI_HARDWARE_SENSOR_DELETION_FORBIDDEN", "message": "Cant delete sensor - hardware sensor deletion is forbidden", "debugId": "12312-123123-123123-1231212", @@ -320,12 +400,12 @@ func TestAgentResourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { // existing group - util.MockGetAgent("uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}), + util.MockGetAgent("id", util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateAgentResponseModel("id", "")}), 1, ) // delete group - util.MockDeleteAgent("uid", 1) + util.MockDeleteAgent("id", 1) }, Config: provider.ProviderConfig, }, diff --git a/test/mocked/resources/group_test.go b/test/mocked/resources/group_test.go index e2200451..b9bfb286 100644 --- a/test/mocked/resources/group_test.go +++ b/test/mocked/resources/group_test.go @@ -1,12 +1,13 @@ package resource_test import ( + "net/http" "regexp" "testing" - config_api_client "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" + config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/util" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -28,24 +29,24 @@ func TestGroupResource(t *testing.T) { { PreConfig: func() { util.MockPostGroup( - util.GenerateGroupRequestModel("uid", "", ""), - util.StructToMap(util.GenerateNonRootGroupResponseModel("uid", "", "")), + util.GenerateGroupRequestModel("id", "", ""), + util.StructToMap(util.GenerateNonRootGroupResponseModel("id", "", "")), 1, ) - util.MockGetGroup("uid", + util.MockGetGroup("id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("uid", "", ""), + util.GenerateNonRootGroupResponseModel("id", "", ""), }, ), 2, ) // to indicate the group has a parent util.MockGetGroup( - "parent_uid", + "parent_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("parent_uid", "", ""), + util.GenerateNonRootGroupResponseModel("parent_id", "", ""), }, ), 1, @@ -54,36 +55,36 @@ func TestGroupResource(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" }`, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("uxi_group.my_group", "name", "name"), resource.TestCheckResourceAttr( "uxi_group.my_group", "parent_group_id", - "parent_uid", + "parent_id", ), - resource.TestCheckResourceAttr("uxi_group.my_group", "id", "uid"), + resource.TestCheckResourceAttr("uxi_group.my_group", "id", "id"), ), }, // ImportState testing { PreConfig: func() { util.MockGetGroup( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("uid", "", ""), + util.GenerateNonRootGroupResponseModel("id", "", ""), }, ), 1, ) // to indicate the group has a parent util.MockGetGroup( - "parent_uid", + "parent_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("parent_uid", "", ""), + util.GenerateNonRootGroupResponseModel("parent_id", "", ""), }, ), 1, @@ -97,32 +98,32 @@ func TestGroupResource(t *testing.T) { { PreConfig: func() { // existing group - util.MockGetGroup("uid", util.GeneratePaginatedResponse( + util.MockGetGroup("id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("uid", "", ""), + util.GenerateNonRootGroupResponseModel("id", "", ""), }, ), 1, ) // updated group util.MockUpdateGroup( - "uid", + "id", map[string]interface{}{"name": "name_2"}, - util.GenerateNonRootGroupResponseModel("uid", "_2", ""), + util.GenerateNonRootGroupResponseModel("id", "_2", ""), 1, ) - util.MockGetGroup("uid", util.GeneratePaginatedResponse( + util.MockGetGroup("id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("uid", "_2", ""), + util.GenerateNonRootGroupResponseModel("id", "_2", ""), }, ), 3, ) util.MockGetGroup( - "parent_uid", + "parent_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("parent_uid", "", ""), + util.GenerateNonRootGroupResponseModel("parent_id", "", ""), }, ), 1, @@ -131,71 +132,71 @@ func TestGroupResource(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name_2" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" }`, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("uxi_group.my_group", "name", "name_2"), resource.TestCheckResourceAttr( "uxi_group.my_group", "parent_group_id", - "parent_uid", + "parent_id", ), - resource.TestCheckResourceAttr("uxi_group.my_group", "id", "uid"), + resource.TestCheckResourceAttr("uxi_group.my_group", "id", "id"), ), }, // Update that does trigger a recreate { PreConfig: func() { // existing group - util.MockGetGroup("uid", util.GeneratePaginatedResponse( + util.MockGetGroup("id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("uid", "", ""), + util.GenerateNonRootGroupResponseModel("id", "", ""), }, ), 1, ) // new group (replacement) util.MockPostGroup( - util.GenerateGroupRequestModel("new_uid", "", "_2"), - util.GenerateNonRootGroupResponseModel("new_uid", "", "_2"), + util.GenerateGroupRequestModel("new_id", "", "_2"), + util.GenerateNonRootGroupResponseModel("new_id", "", "_2"), 1, ) - util.MockGetGroup("new_uid", util.GeneratePaginatedResponse( + util.MockGetGroup("new_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("new_uid", "", "_2"), + util.GenerateNonRootGroupResponseModel("new_id", "", "_2"), }, ), 1, ) // delete old group (being replaced) - util.MockDeleteGroup("uid", 1) + util.MockDeleteGroup("id", 1) }, Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid_2" + parent_group_id = "parent_id_2" }`, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("uxi_group.my_group", "name", "name"), resource.TestCheckResourceAttr( "uxi_group.my_group", "parent_group_id", - "parent_uid_2", + "parent_id_2", ), - resource.TestCheckResourceAttr("uxi_group.my_group", "id", "new_uid"), + resource.TestCheckResourceAttr("uxi_group.my_group", "id", "new_id"), ), }, // Delete testing { PreConfig: func() { - util.MockGetGroup("new_uid", util.GeneratePaginatedResponse( + util.MockGetGroup("new_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("new_uid", "", "_2"), + util.GenerateNonRootGroupResponseModel("new_id", "", "_2"), }, ), 1, ) - util.MockDeleteGroup("new_uid", 1) + util.MockDeleteGroup("new_id", 1) }, Config: provider.ProviderConfig, }, @@ -216,13 +217,13 @@ func TestRootGroupResource(t *testing.T) { { PreConfig: func() { util.MockGetGroup( - "my_root_group_uid", + "my_root_group_id", util.GeneratePaginatedResponse([]map[string]interface{}{ { - "id": "my_root_group_uid", + "id": "my_root_group_id", "name": "root", "parent": *config_api_client.NewNullableParent(nil), - "path": "my_root_group_uid", + "path": "my_root_group_id", "type": "networking-uxi/group", }, }), @@ -236,7 +237,7 @@ func TestRootGroupResource(t *testing.T) { import { to = uxi_group.my_root_group - id = "my_root_group_uid" + id = "my_root_group_id" }`, ExpectError: regexp.MustCompile(`The root group cannot be used as a resource`), }, @@ -246,23 +247,23 @@ func TestRootGroupResource(t *testing.T) { util.MockPostGroup( map[string]interface{}{"name": "name"}, map[string]interface{}{ - "id": "uid", + "id": "id", "name": "name", "parent": map[string]interface{}{"id": "root"}, - "path": "uid", + "path": "id", "type": "networking-uxi/group", }, 1, ) util.MockGetGroup( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ { - "id": "uid", + "id": "id", "name": "name", "parent": map[string]interface{}{"id": "root"}, - "path": "uid", + "path": "id", "type": "networking-uxi/group", }, }, @@ -290,7 +291,7 @@ func TestRootGroupResource(t *testing.T) { name = "name" }`, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_group.my_group", "id", "uid"), + resource.TestCheckResourceAttr("uxi_group.my_group", "id", "id"), resource.TestCheckResourceAttr("uxi_group.my_group", "name", "name"), resource.TestCheckNoResourceAttr("uxi_group.my_group", "parent_group_id"), ), @@ -300,21 +301,21 @@ func TestRootGroupResource(t *testing.T) { PreConfig: func() { // existing group util.MockGetGroup( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ { - "id": "uid", + "id": "id", "name": "name", "parent": map[string]interface{}{"id": "root"}, - "path": "uid", + "path": "id", "type": "networking-uxi/group", }, }, ), 1, ) - util.MockDeleteGroup("uid", 1) + util.MockDeleteGroup("id", 1) }, Config: provider.ProviderConfig, }, @@ -324,11 +325,10 @@ func TestRootGroupResource(t *testing.T) { mockOAuth.Mock.Disable() } -func TestGroupResource429Handling(t *testing.T) { +func TestGroupResourceTooManyRequestsHandling(t *testing.T) { defer gock.Off() mockOAuth := util.MockOAuth() - var request429 *gock.Response - var update429 *gock.Response + var mockTooManyRequests *gock.Response resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -336,30 +336,30 @@ func TestGroupResource429Handling(t *testing.T) { // Create and Read testing { PreConfig: func() { - request429 = gock.New("https://test.api.capenetworks.com"). + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). Post("/networking-uxi/v1alpha1/groups"). - Reply(429). + Reply(http.StatusTooManyRequests). SetHeaders(util.RateLimitingHeaders) util.MockPostGroup( - util.GenerateGroupRequestModel("uid", "", ""), - util.GenerateNonRootGroupResponseModel("uid", "", ""), + util.GenerateGroupRequestModel("id", "", ""), + util.GenerateNonRootGroupResponseModel("id", "", ""), 1, ) util.MockGetGroup( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("uid", "", ""), + util.GenerateNonRootGroupResponseModel("id", "", ""), }, ), 2, ) // to indicate the group has a parent util.MockGetGroup( - "parent_uid", + "parent_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("parent_uid", "", ""), + util.GenerateNonRootGroupResponseModel("parent_id", "", ""), }, ), 1, @@ -368,12 +368,12 @@ func TestGroupResource429Handling(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" }`, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_group.my_group", "id", "uid"), + resource.TestCheckResourceAttr("uxi_group.my_group", "id", "id"), func(s *terraform.State) error { - st.Assert(t, request429.Mock.Request().Counter, 0) + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) return nil }, ), @@ -382,37 +382,37 @@ func TestGroupResource429Handling(t *testing.T) { { PreConfig: func() { // existing group - util.MockGetGroup("uid", util.GeneratePaginatedResponse( + util.MockGetGroup("id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("uid", "", ""), + util.GenerateNonRootGroupResponseModel("id", "", ""), }, ), 1, ) // new group - update429 = gock.New("https://test.api.capenetworks.com"). - Patch("/networking-uxi/v1alpha1/groups/uid"). - Reply(429). + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). + Patch("/networking-uxi/v1alpha1/groups/id"). + Reply(http.StatusTooManyRequests). SetHeaders(util.RateLimitingHeaders) util.MockUpdateGroup( - "uid", + "id", map[string]interface{}{"name": "name_2"}, - util.GenerateNonRootGroupResponseModel("uid", "_2", ""), + util.GenerateNonRootGroupResponseModel("id", "_2", ""), 1, ) - util.MockGetGroup("uid", util.GeneratePaginatedResponse( + util.MockGetGroup("id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("uid", "_2", ""), + util.GenerateNonRootGroupResponseModel("id", "_2", ""), }, ), 3, ) // to indicate the group has a parent util.MockGetGroup( - "parent_uid", + "parent_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("parent_uid", "", ""), + util.GenerateNonRootGroupResponseModel("parent_id", "", ""), }, ), 1, @@ -421,12 +421,12 @@ func TestGroupResource429Handling(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name_2" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" }`, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("uxi_group.my_group", "name", "name_2"), func(s *terraform.State) error { - st.Assert(t, update429.Mock.Request().Counter, 0) + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) return nil }, ), @@ -434,14 +434,14 @@ func TestGroupResource429Handling(t *testing.T) { // Delete testing { PreConfig: func() { - util.MockGetGroup("uid", util.GeneratePaginatedResponse( + util.MockGetGroup("id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("uid", "", ""), + util.GenerateNonRootGroupResponseModel("id", "", ""), }, ), 1, ) - util.MockDeleteGroup("uid", 1) + util.MockDeleteGroup("id", 1) }, Config: provider.ProviderConfig, }, @@ -463,9 +463,9 @@ func TestGroupResourceHttpErrorHandling(t *testing.T) { PreConfig: func() { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/groups"). - Reply(500). + Reply(http.StatusInternalServerError). JSON(map[string]interface{}{ - "httpStatusCode": 500, + "httpStatusCode": http.StatusInternalServerError, "errorCode": "HPE_GL_ERROR_INTERNAL_SERVER_ERROR", "message": "Current request cannot be processed due to unknown issue", "debugId": "12312-123123-123123-1231212", @@ -474,12 +474,12 @@ func TestGroupResourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" } import { to = uxi_group.my_group - id = "uid" + id = "id" } `, ExpectError: regexp.MustCompile( @@ -490,7 +490,7 @@ func TestGroupResourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetGroup( - "uid", + "id", util.GeneratePaginatedResponse([]map[string]interface{}{}), 1, ) @@ -498,12 +498,12 @@ func TestGroupResourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" } import { to = uxi_group.my_group - id = "uid" + id = "id" } `, @@ -514,9 +514,9 @@ func TestGroupResourceHttpErrorHandling(t *testing.T) { PreConfig: func() { gock.New("https://test.api.capenetworks.com"). Post("/networking-uxi/v1alpha1/groups"). - Reply(400). + Reply(http.StatusBadRequest). JSON(map[string]interface{}{ - "httpStatusCode": 400, + "httpStatusCode": http.StatusBadRequest, "errorCode": "HPE_GL_ERROR_BAD_REQUEST", "message": "Validation error - bad request", "debugId": "12312-123123-123123-1231212", @@ -525,7 +525,7 @@ func TestGroupResourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" }`, ExpectError: regexp.MustCompile( `(?s)Validation error - bad request\s*DebugID: 12312-123123-123123-1231212`, @@ -535,25 +535,25 @@ func TestGroupResourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockPostGroup( - util.GenerateGroupRequestModel("uid", "", ""), - util.GenerateNonRootGroupResponseModel("uid", "", ""), + util.GenerateGroupRequestModel("id", "", ""), + util.GenerateNonRootGroupResponseModel("id", "", ""), 1, ) util.MockGetGroup( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("uid", "", ""), + util.GenerateNonRootGroupResponseModel("id", "", ""), }, ), 2, ) // to indicate the group has a parent util.MockGetGroup( - "parent_uid", + "parent_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("parent_uid", "", ""), + util.GenerateNonRootGroupResponseModel("parent_id", "", ""), }, ), 1, @@ -562,29 +562,29 @@ func TestGroupResourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" }`, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_group.my_group", "id", "uid"), + resource.TestCheckResourceAttr("uxi_group.my_group", "id", "id"), ), }, // Update 4xx { PreConfig: func() { // existing group - util.MockGetGroup("uid", util.GeneratePaginatedResponse( + util.MockGetGroup("id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("uid", "", ""), + util.GenerateNonRootGroupResponseModel("id", "", ""), }, ), 1, ) // new group - with error gock.New("https://test.api.capenetworks.com"). - Patch("/networking-uxi/v1alpha1/groups/uid"). - Reply(422). + Patch("/networking-uxi/v1alpha1/groups/id"). + Reply(http.StatusUnprocessableEntity). JSON(map[string]interface{}{ - "httpStatusCode": 422, + "httpStatusCode": http.StatusUnprocessableEntity, "errorCode": "HPE_GL_UXI_DUPLICATE_SIBLING_GROUP_NAME", "message": "Unable to create group - a sibling group already has the specified name", "debugId": "12312-123123-123123-1231212", @@ -593,7 +593,7 @@ func TestGroupResourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name_2" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" }`, ExpectError: regexp.MustCompile( `(?s)Unable to create group - a sibling group already has the specified name\s*DebugID: 12312-123123-123123-1231212`, @@ -603,19 +603,19 @@ func TestGroupResourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { // existing group - util.MockGetGroup("uid", util.GeneratePaginatedResponse( + util.MockGetGroup("id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("uid", "", ""), + util.GenerateNonRootGroupResponseModel("id", "", ""), }, ), 1, ) // delete group - with error gock.New("https://test.api.capenetworks.com"). - Delete("/networking-uxi/v1alpha1/groups/uid"). - Reply(422). + Delete("/networking-uxi/v1alpha1/groups/id"). + Reply(http.StatusUnprocessableEntity). JSON(map[string]interface{}{ - "httpStatusCode": 422, + "httpStatusCode": http.StatusUnprocessableEntity, "errorCode": "HPE_GL_UXI_GROUP_CANNOT_BE_DELETED", "message": "Unable to delete group", "debugId": "12312-123123-123123-1231212", @@ -630,15 +630,15 @@ func TestGroupResourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { // existing group - util.MockGetGroup("uid", util.GeneratePaginatedResponse( + util.MockGetGroup("id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("uid", "", ""), + util.GenerateNonRootGroupResponseModel("id", "", ""), }, ), 1, ) // delete group - util.MockDeleteGroup("uid", 1) + util.MockDeleteGroup("id", 1) }, Config: provider.ProviderConfig, }, diff --git a/test/mocked/resources/network_group_assignment_test.go b/test/mocked/resources/network_group_assignment_test.go index b5aa2ef0..06a6d80a 100644 --- a/test/mocked/resources/network_group_assignment_test.go +++ b/test/mocked/resources/network_group_assignment_test.go @@ -1,11 +1,12 @@ package resource_test import ( + "net/http" "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/util" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -24,10 +25,10 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { { PreConfig: func() { util.MockGetWiredNetwork( - "network_uid", + "network_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWiredNetworkResponse("network_uid", ""), + util.GenerateWiredNetworkResponse("network_id", ""), }, ), 2, @@ -35,15 +36,15 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { // required for group create util.MockPostGroup( - util.GenerateGroupRequestModel("group_uid", "", ""), + util.GenerateGroupRequestModel("group_id", "", ""), util.StructToMap( - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), ), 1, ) - util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( + util.MockGetGroup("group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 2, @@ -52,21 +53,21 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { // required for network group assignment create util.MockPostNetworkGroupAssignment( util.GenerateNetworkGroupAssignmentRequest( - "network_group_assignment_uid", + "network_group_assignment_id", "", ), util.GenerateNetworkGroupAssignmentResponse( - "network_group_assignment_uid", + "network_group_assignment_id", "", ), 1, ) util.MockGetNetworkGroupAssignment( - "network_group_assignment_uid", + "network_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateNetworkGroupAssignmentResponse( - "network_group_assignment_uid", + "network_group_assignment_id", "", ), }, @@ -78,7 +79,7 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" } resource "uxi_wired_network" "my_network" { @@ -87,7 +88,7 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { import { to = uxi_wired_network.my_network - id = "network_uid" + id = "network_id" } resource "uxi_network_group_assignment" "my_network_group_assignment" { @@ -98,17 +99,17 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { resource.TestCheckResourceAttr( "uxi_network_group_assignment.my_network_group_assignment", "network_id", - "network_uid", + "network_id", ), resource.TestCheckResourceAttr( "uxi_network_group_assignment.my_network_group_assignment", "group_id", - "group_uid", + "group_id", ), resource.TestCheckResourceAttr( "uxi_network_group_assignment.my_network_group_assignment", "id", - "network_group_assignment_uid", + "network_group_assignment_id", ), ), }, @@ -116,11 +117,11 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { { PreConfig: func() { util.MockGetNetworkGroupAssignment( - "network_group_assignment_uid", + "network_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateNetworkGroupAssignmentResponse( - "network_group_assignment_uid", + "network_group_assignment_id", "", ), }, @@ -136,37 +137,37 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { { PreConfig: func() { util.MockGetWiredNetwork( - "network_uid_2", + "network_id_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWiredNetworkResponse("network_uid_2", "_2"), + util.GenerateWiredNetworkResponse("network_id_2", "_2"), }, ), 2, ) util.MockGetWiredNetwork( - "network_uid", + "network_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWiredNetworkResponse("network_uid", ""), + util.GenerateWiredNetworkResponse("network_id", ""), }, ), 2, ) util.MockGetGroup( - "group_uid_2", + "group_id_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_id_2", "_2", "_2"), }, ), 1, ) util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 3, @@ -174,32 +175,32 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { // required for creating another group util.MockPostGroup( - util.GenerateGroupRequestModel("group_uid_2", "_2", "_2"), + util.GenerateGroupRequestModel("group_id_2", "_2", "_2"), util.StructToMap( - util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_id_2", "_2", "_2"), ), 1, ) // required for network group assignment create - util.MockDeleteNetworkGroupAssignment("network_group_assignment_uid", 1) + util.MockDeleteNetworkGroupAssignment("network_group_assignment_id", 1) util.MockPostNetworkGroupAssignment( util.GenerateNetworkGroupAssignmentRequest( - "network_group_assignment_uid_2", + "network_group_assignment_id_2", "_2", ), util.GenerateNetworkGroupAssignmentResponse( - "network_group_assignment_uid_2", + "network_group_assignment_id_2", "_2", ), 1, ) util.MockGetNetworkGroupAssignment( - "network_group_assignment_uid_2", + "network_group_assignment_id_2", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateNetworkGroupAssignmentResponse( - "network_group_assignment_uid_2", + "network_group_assignment_id_2", "_2", ), }, @@ -207,11 +208,11 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { 2, ) util.MockGetNetworkGroupAssignment( - "network_group_assignment_uid", + "network_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateNetworkGroupAssignmentResponse( - "network_group_assignment_uid", + "network_group_assignment_id", "", ), }, @@ -223,7 +224,7 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { // the original resources resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" } resource "uxi_wired_network" "my_network" { @@ -232,13 +233,13 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { import { to = uxi_wired_network.my_network - id = "network_uid" + id = "network_id" } // the new resources we wanna update the assignment to resource "uxi_group" "my_group_2" { name = "name_2" - parent_group_id = "parent_uid_2" + parent_group_id = "parent_id_2" } resource "uxi_wired_network" "my_network_2" { @@ -247,7 +248,7 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { import { to = uxi_wired_network.my_network_2 - id = "network_uid_2" + id = "network_id_2" } // the assignment update, updated from network/group to network_2/group_2 @@ -259,17 +260,17 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { resource.TestCheckResourceAttr( "uxi_network_group_assignment.my_network_group_assignment", "network_id", - "network_uid_2", + "network_id_2", ), resource.TestCheckResourceAttr( "uxi_network_group_assignment.my_network_group_assignment", "group_id", - "group_uid_2", + "group_id_2", ), resource.TestCheckResourceAttr( "uxi_network_group_assignment.my_network_group_assignment", "id", - "network_group_assignment_uid_2", + "network_group_assignment_id_2", ), ), }, @@ -277,43 +278,43 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { { PreConfig: func() { util.MockGetWiredNetwork( - "network_uid_2", + "network_id_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWiredNetworkResponse("network_uid_2", "_2"), + util.GenerateWiredNetworkResponse("network_id_2", "_2"), }, ), 1, ) util.MockGetWiredNetwork( - "network_uid", + "network_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWiredNetworkResponse("network_uid", ""), + util.GenerateWiredNetworkResponse("network_id", ""), }, ), 1, ) - util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( + util.MockGetGroup("group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 2, ) - util.MockGetGroup("group_uid_2", util.GeneratePaginatedResponse( + util.MockGetGroup("group_id_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_id_2", "_2", "_2"), }, ), 1, ) util.MockGetNetworkGroupAssignment( - "network_group_assignment_uid_2", + "network_group_assignment_id_2", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateNetworkGroupAssignmentResponse( - "network_group_assignment_uid_2", + "network_group_assignment_id_2", "_2", ), }, @@ -321,11 +322,11 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { 1, ) util.MockGetNetworkGroupAssignment( - "network_group_assignment_uid", + "network_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateNetworkGroupAssignmentResponse( - "network_group_assignment_uid", + "network_group_assignment_id", "", ), }, @@ -333,10 +334,10 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) { 1, ) - util.MockDeleteGroup("group_uid", 1) - util.MockDeleteGroup("group_uid_2", 1) - util.MockDeleteNetworkGroupAssignment("network_group_assignment_uid", 1) - util.MockDeleteNetworkGroupAssignment("network_group_assignment_uid_2", 1) + util.MockDeleteGroup("group_id", 1) + util.MockDeleteGroup("group_id_2", 1) + util.MockDeleteNetworkGroupAssignment("network_group_assignment_id", 1) + util.MockDeleteNetworkGroupAssignment("network_group_assignment_id_2", 1) }, Config: provider.ProviderConfig + ` removed { @@ -374,27 +375,27 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { PreConfig: func() { // required for network import util.MockGetWirelessNetwork( - "network_uid", + "network_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWirelessNetworkResponse("network_uid", ""), + util.GenerateWirelessNetworkResponse("network_id", ""), }, ), 2, ) // required for group create util.MockPostGroup( - util.GenerateGroupRequestModel("group_uid", "", ""), + util.GenerateGroupRequestModel("group_id", "", ""), util.StructToMap( - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), ), 1, ) util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 1, @@ -403,21 +404,21 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { // required for network group assignment create util.MockPostNetworkGroupAssignment( util.GenerateNetworkGroupAssignmentRequest( - "network_group_assignment_uid", + "network_group_assignment_id", "", ), util.GenerateNetworkGroupAssignmentResponse( - "network_group_assignment_uid", + "network_group_assignment_id", "", ), 1, ) util.MockGetNetworkGroupAssignment( - "network_group_assignment_uid", + "network_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateNetworkGroupAssignmentResponse( - "network_group_assignment_uid", + "network_group_assignment_id", "", ), }, @@ -429,7 +430,7 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" } resource "uxi_wireless_network" "my_network" { @@ -438,7 +439,7 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { import { to = uxi_wireless_network.my_network - id = "network_uid" + id = "network_id" } resource "uxi_network_group_assignment" "my_network_group_assignment" { @@ -449,17 +450,17 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { resource.TestCheckResourceAttr( "uxi_network_group_assignment.my_network_group_assignment", "network_id", - "network_uid", + "network_id", ), resource.TestCheckResourceAttr( "uxi_network_group_assignment.my_network_group_assignment", "group_id", - "group_uid", + "group_id", ), resource.TestCheckResourceAttr( "uxi_network_group_assignment.my_network_group_assignment", "id", - "network_group_assignment_uid", + "network_group_assignment_id", ), ), }, @@ -467,11 +468,11 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { { PreConfig: func() { util.MockGetNetworkGroupAssignment( - "network_group_assignment_uid", + "network_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateNetworkGroupAssignmentResponse( - "network_group_assignment_uid", + "network_group_assignment_id", "", ), }, @@ -487,48 +488,48 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { { PreConfig: func() { util.MockGetWirelessNetwork( - "network_uid_2", + "network_id_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWirelessNetworkResponse("network_uid_2", "_2"), + util.GenerateWirelessNetworkResponse("network_id_2", "_2"), }, ), 2, ) util.MockGetWirelessNetwork( - "network_uid", + "network_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWirelessNetworkResponse("network_uid", ""), + util.GenerateWirelessNetworkResponse("network_id", ""), }, ), 2, ) // required for creating another group - util.MockDeleteNetworkGroupAssignment("network_group_assignment_uid", 1) + util.MockDeleteNetworkGroupAssignment("network_group_assignment_id", 1) util.MockPostGroup( - util.GenerateGroupRequestModel("group_uid_2", "_2", "_2"), + util.GenerateGroupRequestModel("group_id_2", "_2", "_2"), util.StructToMap( - util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_id_2", "_2", "_2"), ), 1, ) util.MockGetGroup( - "group_uid_2", + "group_id_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_id_2", "_2", "_2"), }, ), 1, ) util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 3, @@ -536,11 +537,11 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { // required for network group assignment create util.MockGetNetworkGroupAssignment( - "network_group_assignment_uid_2", + "network_group_assignment_id_2", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateNetworkGroupAssignmentResponse( - "network_group_assignment_uid_2", + "network_group_assignment_id_2", "_2", ), }, @@ -548,11 +549,11 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { 2, ) util.MockGetNetworkGroupAssignment( - "network_group_assignment_uid", + "network_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateNetworkGroupAssignmentResponse( - "network_group_assignment_uid", + "network_group_assignment_id", "", ), }, @@ -561,11 +562,11 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { ) util.MockPostNetworkGroupAssignment( util.GenerateNetworkGroupAssignmentRequest( - "network_group_assignment_uid_2", + "network_group_assignment_id_2", "_2", ), util.GenerateNetworkGroupAssignmentResponse( - "network_group_assignment_uid_2", + "network_group_assignment_id_2", "_2", ), 1, @@ -575,7 +576,7 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { // the original resources resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" } resource "uxi_wireless_network" "my_network" { @@ -584,13 +585,13 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { import { to = uxi_wireless_network.my_network - id = "network_uid" + id = "network_id" } // the new resources we wanna update the assignment to resource "uxi_group" "my_group_2" { name = "name_2" - parent_group_id = "parent_uid_2" + parent_group_id = "parent_id_2" } resource "uxi_wireless_network" "my_network_2" { @@ -599,7 +600,7 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { import { to = uxi_wireless_network.my_network_2 - id = "network_uid_2" + id = "network_id_2" } // the assignment update, updated from network/group to network_2/group_2 @@ -611,17 +612,17 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { resource.TestCheckResourceAttr( "uxi_network_group_assignment.my_network_group_assignment", "network_id", - "network_uid_2", + "network_id_2", ), resource.TestCheckResourceAttr( "uxi_network_group_assignment.my_network_group_assignment", "group_id", - "group_uid_2", + "group_id_2", ), resource.TestCheckResourceAttr( "uxi_network_group_assignment.my_network_group_assignment", "id", - "network_group_assignment_uid_2", + "network_group_assignment_id_2", ), ), }, @@ -629,47 +630,47 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { { PreConfig: func() { util.MockGetWirelessNetwork( - "network_uid_2", + "network_id_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWirelessNetworkResponse("network_uid_2", "_2"), + util.GenerateWirelessNetworkResponse("network_id_2", "_2"), }, ), 1, ) util.MockGetWirelessNetwork( - "network_uid", + "network_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWirelessNetworkResponse("network_uid", ""), + util.GenerateWirelessNetworkResponse("network_id", ""), }, ), 1, ) util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 2, ) util.MockGetGroup( - "group_uid_2", + "group_id_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_id_2", "_2", "_2"), }, ), 1, ) util.MockGetNetworkGroupAssignment( - "network_group_assignment_uid_2", + "network_group_assignment_id_2", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateNetworkGroupAssignmentResponse( - "network_group_assignment_uid_2", + "network_group_assignment_id_2", "_2", ), }, @@ -677,11 +678,11 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { 1, ) util.MockGetNetworkGroupAssignment( - "network_group_assignment_uid", + "network_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateNetworkGroupAssignmentResponse( - "network_group_assignment_uid", + "network_group_assignment_id", "", ), }, @@ -689,10 +690,10 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { 1, ) - util.MockDeleteGroup("group_uid", 1) - util.MockDeleteGroup("group_uid_2", 1) - util.MockDeleteNetworkGroupAssignment("network_group_assignment_uid", 1) - util.MockDeleteNetworkGroupAssignment("network_group_assignment_uid_2", 1) + util.MockDeleteGroup("group_id", 1) + util.MockDeleteGroup("group_id_2", 1) + util.MockDeleteNetworkGroupAssignment("network_group_assignment_id", 1) + util.MockDeleteNetworkGroupAssignment("network_group_assignment_id_2", 1) }, Config: provider.ProviderConfig + ` removed { @@ -717,10 +718,10 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) { mockOAuth.Mock.Disable() } -func TestNetworkGroupAssignmentResource429Handling(t *testing.T) { +func TestNetworkGroupAssignmentResourceTooManyRequestsHandling(t *testing.T) { defer gock.Off() mockOAuth := util.MockOAuth() - var mock429 *gock.Response + var mockTooManyRequests *gock.Response resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -729,10 +730,10 @@ func TestNetworkGroupAssignmentResource429Handling(t *testing.T) { { PreConfig: func() { util.MockGetWiredNetwork( - "network_uid", + "network_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWiredNetworkResponse("network_uid", ""), + util.GenerateWiredNetworkResponse("network_id", ""), }, ), 2, @@ -740,42 +741,42 @@ func TestNetworkGroupAssignmentResource429Handling(t *testing.T) { // required for group create util.MockPostGroup( - util.GenerateGroupRequestModel("group_uid", "", ""), + util.GenerateGroupRequestModel("group_id", "", ""), util.StructToMap( - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), ), 1, ) - util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( + util.MockGetGroup("group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 2, ) // required for network group assignment create - mock429 = gock.New("https://test.api.capenetworks.com"). + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). Post("/networking-uxi/v1alpha1/network-group-assignments"). - Reply(429). + Reply(http.StatusTooManyRequests). SetHeaders(util.RateLimitingHeaders) util.MockPostNetworkGroupAssignment( util.GenerateNetworkGroupAssignmentRequest( - "network_group_assignment_uid", + "network_group_assignment_id", "", ), util.GenerateNetworkGroupAssignmentResponse( - "network_group_assignment_uid", + "network_group_assignment_id", "", ), 1, ) util.MockGetNetworkGroupAssignment( - "network_group_assignment_uid", + "network_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateNetworkGroupAssignmentResponse( - "network_group_assignment_uid", + "network_group_assignment_id", "", ), }, @@ -787,7 +788,7 @@ func TestNetworkGroupAssignmentResource429Handling(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" } resource "uxi_wired_network" "my_network" { @@ -796,7 +797,7 @@ func TestNetworkGroupAssignmentResource429Handling(t *testing.T) { import { to = uxi_wired_network.my_network - id = "network_uid" + id = "network_id" } resource "uxi_network_group_assignment" "my_network_group_assignment" { @@ -807,10 +808,10 @@ func TestNetworkGroupAssignmentResource429Handling(t *testing.T) { resource.TestCheckResourceAttr( "uxi_network_group_assignment.my_network_group_assignment", "network_id", - "network_uid", + "network_id", ), func(s *terraform.State) error { - st.Assert(t, mock429.Mock.Request().Counter, 0) + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) return nil }, ), @@ -819,27 +820,27 @@ func TestNetworkGroupAssignmentResource429Handling(t *testing.T) { { PreConfig: func() { util.MockGetWiredNetwork( - "network_uid", + "network_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWiredNetworkResponse("network_uid", ""), + util.GenerateWiredNetworkResponse("network_id", ""), }, ), 1, ) - util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( + util.MockGetGroup("group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 1, ) util.MockGetNetworkGroupAssignment( - "network_group_assignment_uid", + "network_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateNetworkGroupAssignmentResponse( - "network_group_assignment_uid", + "network_group_assignment_id", "", ), }, @@ -847,12 +848,12 @@ func TestNetworkGroupAssignmentResource429Handling(t *testing.T) { 1, ) - util.MockDeleteGroup("group_uid", 1) - mock429 = gock.New("https://test.api.capenetworks.com"). - Delete("/networking-uxi/v1alpha1/network-group-assignments/network_group_assignment_uid"). - Reply(429). + util.MockDeleteGroup("group_id", 1) + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). + Delete("/networking-uxi/v1alpha1/network-group-assignments/network_group_assignment_id"). + Reply(http.StatusTooManyRequests). SetHeaders(util.RateLimitingHeaders) - util.MockDeleteNetworkGroupAssignment("network_group_assignment_uid", 1) + util.MockDeleteNetworkGroupAssignment("network_group_assignment_id", 1) }, Config: provider.ProviderConfig + ` removed { @@ -864,7 +865,7 @@ func TestNetworkGroupAssignmentResource429Handling(t *testing.T) { }`, Check: resource.ComposeAggregateTestCheckFunc( func(s *terraform.State) error { - st.Assert(t, mock429.Mock.Request().Counter, 0) + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) return nil }, ), @@ -886,10 +887,10 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetWiredNetwork( - "network_uid", + "network_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWiredNetworkResponse("network_uid", ""), + util.GenerateWiredNetworkResponse("network_id", ""), }, ), 2, @@ -897,15 +898,15 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // required for group create util.MockPostGroup( - util.GenerateGroupRequestModel("group_uid", "", ""), + util.GenerateGroupRequestModel("group_id", "", ""), util.StructToMap( - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), ), 1, ) - util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( + util.MockGetGroup("group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 2, @@ -914,9 +915,9 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // network group assignment create gock.New("https://test.api.capenetworks.com"). Post("/networking-uxi/v1alpha1/network-group-assignments"). - Reply(400). + Reply(http.StatusBadRequest). JSON(map[string]interface{}{ - "httpStatusCode": 400, + "httpStatusCode": http.StatusBadRequest, "errorCode": "HPE_GL_ERROR_BAD_REQUEST", "message": "Validation error - bad request", "debugId": "12312-123123-123123-1231212", @@ -926,7 +927,7 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" } resource "uxi_wired_network" "my_network" { @@ -935,7 +936,7 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { import { to = uxi_wired_network.my_network - id = "network_uid" + id = "network_id" } resource "uxi_network_group_assignment" "my_network_group_assignment" { @@ -950,10 +951,10 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetWiredNetwork( - "network_uid", + "network_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWiredNetworkResponse("network_uid", ""), + util.GenerateWiredNetworkResponse("network_id", ""), }, ), 2, @@ -961,15 +962,15 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // required for group create util.MockPostGroup( - util.GenerateGroupRequestModel("group_uid", "", ""), + util.GenerateGroupRequestModel("group_id", "", ""), util.StructToMap( - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), ), 1, ) - util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( + util.MockGetGroup("group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 2, @@ -977,7 +978,7 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // network group assignment read util.MockGetNetworkGroupAssignment( - "network_group_assignment_uid", + "network_group_assignment_id", util.GeneratePaginatedResponse([]map[string]interface{}{}), 1, ) @@ -985,7 +986,7 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" } resource "uxi_wired_network" "my_network" { @@ -994,7 +995,7 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { import { to = uxi_wired_network.my_network - id = "network_uid" + id = "network_id" } resource "uxi_network_group_assignment" "my_network_group_assignment" { @@ -1004,7 +1005,7 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { import { to = uxi_network_group_assignment.my_network_group_assignment - id = "network_group_assignment_uid" + id = "network_group_assignment_id" } `, ExpectError: regexp.MustCompile(`Error: Cannot import non-existent remote object`), @@ -1013,10 +1014,10 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetWiredNetwork( - "network_uid", + "network_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWiredNetworkResponse("network_uid", ""), + util.GenerateWiredNetworkResponse("network_id", ""), }, ), 2, @@ -1024,15 +1025,15 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // required for group create util.MockPostGroup( - util.GenerateGroupRequestModel("group_uid", "", ""), + util.GenerateGroupRequestModel("group_id", "", ""), util.StructToMap( - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), ), 1, ) - util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( + util.MockGetGroup("group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 2, @@ -1041,9 +1042,9 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // network group assignment read gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/network-group-assignments"). - Reply(500). + Reply(http.StatusInternalServerError). JSON(map[string]interface{}{ - "httpStatusCode": 500, + "httpStatusCode": http.StatusInternalServerError, "errorCode": "HPE_GL_ERROR_INTERNAL_SERVER_ERROR", "message": "Current request cannot be processed due to unknown issue", "debugId": "12312-123123-123123-1231212", @@ -1052,7 +1053,7 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" } resource "uxi_wired_network" "my_network" { @@ -1061,7 +1062,7 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { import { to = uxi_wired_network.my_network - id = "network_uid" + id = "network_id" } resource "uxi_network_group_assignment" "my_network_group_assignment" { @@ -1071,7 +1072,7 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { import { to = uxi_network_group_assignment.my_network_group_assignment - id = "network_group_assignment_uid" + id = "network_group_assignment_id" } `, @@ -1083,10 +1084,10 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetWiredNetwork( - "network_uid", + "network_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWiredNetworkResponse("network_uid", ""), + util.GenerateWiredNetworkResponse("network_id", ""), }, ), 2, @@ -1094,15 +1095,15 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // required for group create util.MockPostGroup( - util.GenerateGroupRequestModel("group_uid", "", ""), + util.GenerateGroupRequestModel("group_id", "", ""), util.StructToMap( - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), ), 1, ) - util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( + util.MockGetGroup("group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 2, @@ -1111,21 +1112,21 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // required for network group assignment create util.MockPostNetworkGroupAssignment( util.GenerateNetworkGroupAssignmentRequest( - "network_group_assignment_uid", + "network_group_assignment_id", "", ), util.GenerateNetworkGroupAssignmentResponse( - "network_group_assignment_uid", + "network_group_assignment_id", "", ), 1, ) util.MockGetNetworkGroupAssignment( - "network_group_assignment_uid", + "network_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateNetworkGroupAssignmentResponse( - "network_group_assignment_uid", + "network_group_assignment_id", "", ), }, @@ -1137,7 +1138,7 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" } resource "uxi_wired_network" "my_network" { @@ -1146,7 +1147,7 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { import { to = uxi_wired_network.my_network - id = "network_uid" + id = "network_id" } resource "uxi_network_group_assignment" "my_network_group_assignment" { @@ -1157,7 +1158,7 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { resource.TestCheckResourceAttr( "uxi_network_group_assignment.my_network_group_assignment", "network_id", - "network_uid", + "network_id", ), ), }, @@ -1165,27 +1166,27 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetWiredNetwork( - "network_uid", + "network_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWiredNetworkResponse("network_uid", ""), + util.GenerateWiredNetworkResponse("network_id", ""), }, ), 1, ) - util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( + util.MockGetGroup("group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 1, ) util.MockGetNetworkGroupAssignment( - "network_group_assignment_uid", + "network_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateNetworkGroupAssignmentResponse( - "network_group_assignment_uid", + "network_group_assignment_id", "", ), }, @@ -1196,9 +1197,9 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // network group assignment create gock.New("https://test.api.capenetworks.com"). Delete("/networking-uxi/v1alpha1/network-group-assignments"). - Reply(403). + Reply(http.StatusForbidden). JSON(map[string]interface{}{ - "httpStatusCode": 403, + "httpStatusCode": http.StatusForbidden, "errorCode": "HPE_GL_ERROR_FORBIDDEN", "message": "Forbidden - user has insufficient permissions to complete the request", "debugId": "12312-123123-123123-1231212", @@ -1221,35 +1222,35 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetWiredNetwork( - "network_uid", + "network_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWiredNetworkResponse("network_uid", ""), + util.GenerateWiredNetworkResponse("network_id", ""), }, ), 1, ) - util.MockGetGroup("group_uid", util.GeneratePaginatedResponse( + util.MockGetGroup("group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 1, ) util.MockGetNetworkGroupAssignment( - "network_group_assignment_uid", + "network_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateNetworkGroupAssignmentResponse( - "network_group_assignment_uid", + "network_group_assignment_id", "", ), }, ), 1, ) - util.MockDeleteGroup("group_uid", 1) - util.MockDeleteNetworkGroupAssignment("network_group_assignment_uid", 1) + util.MockDeleteGroup("group_id", 1) + util.MockDeleteNetworkGroupAssignment("network_group_assignment_id", 1) }, Config: provider.ProviderConfig + ` removed { diff --git a/test/mocked/resources/sensor_group_assignment_test.go b/test/mocked/resources/sensor_group_assignment_test.go index 216b5f04..7f27bcef 100644 --- a/test/mocked/resources/sensor_group_assignment_test.go +++ b/test/mocked/resources/sensor_group_assignment_test.go @@ -1,11 +1,12 @@ package resource_test import ( + "net/http" "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/util" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -23,9 +24,9 @@ func TestSensorGroupAssignmentResource(t *testing.T) { { PreConfig: func() { // required for sensor import - util.MockGetSensor("uid", util.GeneratePaginatedResponse( + util.MockGetSensor("id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateSensorResponseModel("sensor_uid", ""), + util.GenerateSensorResponseModel("sensor_id", ""), }, ), 2, @@ -33,17 +34,17 @@ func TestSensorGroupAssignmentResource(t *testing.T) { // required for group create util.MockPostGroup( - util.GenerateGroupRequestModel("group_uid", "", ""), + util.GenerateGroupRequestModel("group_id", "", ""), util.StructToMap( - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), ), 1, ) util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 1, @@ -52,21 +53,21 @@ func TestSensorGroupAssignmentResource(t *testing.T) { // required for sensor group assignment create util.MockPostSensorGroupAssignment( util.GenerateSensorGroupAssignmentRequest( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", "", ), util.GenerateSensorGroupAssignmentResponse( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", "", ), 1, ) util.MockGetSensorGroupAssignment( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateSensorGroupAssignmentResponse( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", "", ), }, @@ -78,7 +79,7 @@ func TestSensorGroupAssignmentResource(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" } resource "uxi_sensor" "my_sensor" { @@ -90,7 +91,7 @@ func TestSensorGroupAssignmentResource(t *testing.T) { import { to = uxi_sensor.my_sensor - id = "sensor_uid" + id = "sensor_id" } resource "uxi_sensor_group_assignment" "my_sensor_group_assignment" { @@ -101,17 +102,17 @@ func TestSensorGroupAssignmentResource(t *testing.T) { resource.TestCheckResourceAttr( "uxi_sensor_group_assignment.my_sensor_group_assignment", "sensor_id", - "sensor_uid", + "sensor_id", ), resource.TestCheckResourceAttr( "uxi_sensor_group_assignment.my_sensor_group_assignment", "group_id", - "group_uid", + "group_id", ), resource.TestCheckResourceAttr( "uxi_sensor_group_assignment.my_sensor_group_assignment", "id", - "sensor_group_assignment_uid", + "sensor_group_assignment_id", ), ), }, @@ -119,11 +120,11 @@ func TestSensorGroupAssignmentResource(t *testing.T) { { PreConfig: func() { util.MockGetSensorGroupAssignment( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateSensorGroupAssignmentResponse( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", "", ), }, @@ -138,57 +139,57 @@ func TestSensorGroupAssignmentResource(t *testing.T) { // Update and Read testing { PreConfig: func() { - util.MockGetSensor("sensor_uid_2", util.GeneratePaginatedResponse( + util.MockGetSensor("sensor_id_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateSensorResponseModel("sensor_uid_2", "_2"), + util.GenerateSensorResponseModel("sensor_id_2", "_2"), }, ), 2, ) - util.MockGetSensor("sensor_uid", util.GeneratePaginatedResponse( + util.MockGetSensor("sensor_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateSensorResponseModel("sensor_uid", ""), + util.GenerateSensorResponseModel("sensor_id", ""), }, ), 3, ) util.MockGetGroup( - "group_uid_2", + "group_id_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_id_2", "_2", "_2"), }, ), 1, ) util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 2, ) // required for creating another group - util.MockDeleteSensorGroupAssignment("sensor_group_assignment_uid", 1) + util.MockDeleteSensorGroupAssignment("sensor_group_assignment_id", 1) util.MockPostGroup( - util.GenerateGroupRequestModel("group_uid_2", "_2", "_2"), + util.GenerateGroupRequestModel("group_id_2", "_2", "_2"), util.StructToMap( - util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_id_2", "_2", "_2"), ), 1, ) // required for sensor group assignment create util.MockGetSensorGroupAssignment( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateSensorGroupAssignmentResponse( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", "", ), }, @@ -196,11 +197,11 @@ func TestSensorGroupAssignmentResource(t *testing.T) { 1, ) util.MockGetSensorGroupAssignment( - "sensor_group_assignment_uid_2", + "sensor_group_assignment_id_2", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateSensorGroupAssignmentResponse( - "sensor_group_assignment_uid_2", + "sensor_group_assignment_id_2", "_2", ), }, @@ -210,11 +211,11 @@ func TestSensorGroupAssignmentResource(t *testing.T) { util.MockPostSensorGroupAssignment( util.GenerateSensorGroupAssignmentRequest( - "sensor_group_assignment_uid_2", + "sensor_group_assignment_id_2", "_2", ), util.GenerateSensorGroupAssignmentResponse( - "sensor_group_assignment_uid_2", + "sensor_group_assignment_id_2", "_2", ), 1, @@ -224,7 +225,7 @@ func TestSensorGroupAssignmentResource(t *testing.T) { // the original resources resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" } resource "uxi_sensor" "my_sensor" { @@ -236,13 +237,13 @@ func TestSensorGroupAssignmentResource(t *testing.T) { import { to = uxi_sensor.my_sensor - id = "sensor_uid" + id = "sensor_id" } // the new resources we wanna update the assignment to resource "uxi_group" "my_group_2" { name = "name_2" - parent_group_id = "parent_uid_2" + parent_group_id = "parent_id_2" } resource "uxi_sensor" "my_sensor_2" { @@ -254,7 +255,7 @@ func TestSensorGroupAssignmentResource(t *testing.T) { import { to = uxi_sensor.my_sensor_2 - id = "sensor_uid_2" + id = "sensor_id_2" } // the assignment update, updated from sensor/group to sensor_2/group_2 @@ -266,17 +267,17 @@ func TestSensorGroupAssignmentResource(t *testing.T) { resource.TestCheckResourceAttr( "uxi_sensor_group_assignment.my_sensor_group_assignment", "sensor_id", - "sensor_uid_2", + "sensor_id_2", ), resource.TestCheckResourceAttr( "uxi_sensor_group_assignment.my_sensor_group_assignment", "group_id", - "group_uid_2", + "group_id_2", ), resource.TestCheckResourceAttr( "uxi_sensor_group_assignment.my_sensor_group_assignment", "id", - "sensor_group_assignment_uid_2", + "sensor_group_assignment_id_2", ), ), }, @@ -284,29 +285,29 @@ func TestSensorGroupAssignmentResource(t *testing.T) { { PreConfig: func() { util.MockGetGroup( - "group_uid_2", + "group_id_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_id_2", "_2", "_2"), }, ), 1, ) util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 1, ) util.MockGetSensorGroupAssignment( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateSensorGroupAssignmentResponse( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", "", ), }, @@ -314,9 +315,9 @@ func TestSensorGroupAssignmentResource(t *testing.T) { 1, ) - util.MockDeleteGroup("group_uid", 1) - util.MockDeleteGroup("group_uid_2", 1) - util.MockDeleteSensorGroupAssignment("sensor_group_assignment_uid_2", 1) + util.MockDeleteGroup("group_id", 1) + util.MockDeleteGroup("group_id_2", 1) + util.MockDeleteSensorGroupAssignment("sensor_group_assignment_id_2", 1) }, Config: provider.ProviderConfig + ` removed { @@ -341,10 +342,10 @@ func TestSensorGroupAssignmentResource(t *testing.T) { mockOAuth.Mock.Disable() } -func TestSensorGroupAssignmentResource429Handling(t *testing.T) { +func TestSensorGroupAssignmentResourceTooManyRequestsHandling(t *testing.T) { defer gock.Off() mockOAuth := util.MockOAuth() - var mock429 *gock.Response + var mockTooManyRequests *gock.Response resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -353,9 +354,9 @@ func TestSensorGroupAssignmentResource429Handling(t *testing.T) { { PreConfig: func() { // required for sensor import - util.MockGetSensor("sensor_uid", util.GeneratePaginatedResponse( + util.MockGetSensor("sensor_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateSensorResponseModel("sensor_uid", ""), + util.GenerateSensorResponseModel("sensor_id", ""), }, ), 2, @@ -363,44 +364,44 @@ func TestSensorGroupAssignmentResource429Handling(t *testing.T) { // required for group create util.MockPostGroup( - util.GenerateGroupRequestModel("group_uid", "", ""), + util.GenerateGroupRequestModel("group_id", "", ""), util.StructToMap( - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), ), 1, ) util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 1, ) // required for sensor group assignment create - mock429 = gock.New("https://test.api.capenetworks.com"). + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). Post("/networking-uxi/v1alpha1/sensor-group-assignments"). - Reply(429). + Reply(http.StatusTooManyRequests). SetHeaders(util.RateLimitingHeaders) util.MockPostSensorGroupAssignment( util.GenerateSensorGroupAssignmentRequest( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", "", ), util.GenerateSensorGroupAssignmentResponse( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", "", ), 1, ) util.MockGetSensorGroupAssignment( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateSensorGroupAssignmentResponse( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", "", ), }, @@ -412,7 +413,7 @@ func TestSensorGroupAssignmentResource429Handling(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" } resource "uxi_sensor" "my_sensor" { @@ -424,7 +425,7 @@ func TestSensorGroupAssignmentResource429Handling(t *testing.T) { import { to = uxi_sensor.my_sensor - id = "sensor_uid" + id = "sensor_id" } resource "uxi_sensor_group_assignment" "my_sensor_group_assignment" { @@ -435,10 +436,10 @@ func TestSensorGroupAssignmentResource429Handling(t *testing.T) { resource.TestCheckResourceAttr( "uxi_sensor_group_assignment.my_sensor_group_assignment", "id", - "sensor_group_assignment_uid", + "sensor_group_assignment_id", ), func(s *terraform.State) error { - st.Assert(t, mock429.Mock.Request().Counter, 0) + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) return nil }, ), @@ -447,20 +448,20 @@ func TestSensorGroupAssignmentResource429Handling(t *testing.T) { { PreConfig: func() { util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 1, ) util.MockGetSensorGroupAssignment( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateSensorGroupAssignmentResponse( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", "", ), }, @@ -468,12 +469,12 @@ func TestSensorGroupAssignmentResource429Handling(t *testing.T) { 1, ) - util.MockDeleteGroup("group_uid", 1) - mock429 = gock.New("https://test.api.capenetworks.com"). - Delete("/networking-uxi/v1alpha1/sensor-group-assignments/sensor_group_assignment_uid"). - Reply(429). + util.MockDeleteGroup("group_id", 1) + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). + Delete("/networking-uxi/v1alpha1/sensor-group-assignments/sensor_group_assignment_id"). + Reply(http.StatusTooManyRequests). SetHeaders(util.RateLimitingHeaders) - util.MockDeleteSensorGroupAssignment("sensor_group_assignment_uid", 1) + util.MockDeleteSensorGroupAssignment("sensor_group_assignment_id", 1) }, Config: provider.ProviderConfig + ` removed { @@ -493,7 +494,7 @@ func TestSensorGroupAssignmentResource429Handling(t *testing.T) { }`, Check: resource.ComposeAggregateTestCheckFunc( func(s *terraform.State) error { - st.Assert(t, mock429.Mock.Request().Counter, 0) + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) return nil }, ), @@ -515,9 +516,9 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { // required for sensor import - util.MockGetSensor("sensor_uid", util.GeneratePaginatedResponse( + util.MockGetSensor("sensor_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateSensorResponseModel("sensor_uid", ""), + util.GenerateSensorResponseModel("sensor_id", ""), }, ), 1, @@ -525,17 +526,17 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // required for group create util.MockPostGroup( - util.GenerateGroupRequestModel("group_uid", "", ""), + util.GenerateGroupRequestModel("group_id", "", ""), util.StructToMap( - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), ), 1, ) util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 1, @@ -544,9 +545,9 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // required for sensor group assignment create gock.New("https://test.api.capenetworks.com"). Post("/networking-uxi/v1alpha1/sensor-group-assignments"). - Reply(400). + Reply(http.StatusBadRequest). JSON(map[string]interface{}{ - "httpStatusCode": 400, + "httpStatusCode": http.StatusBadRequest, "errorCode": "HPE_GL_ERROR_BAD_REQUEST", "message": "Validation error - bad request", "debugId": "12312-123123-123123-1231212", @@ -556,7 +557,7 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" } resource "uxi_sensor" "my_sensor" { @@ -568,7 +569,7 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { import { to = uxi_sensor.my_sensor - id = "sensor_uid" + id = "sensor_id" } resource "uxi_sensor_group_assignment" "my_sensor_group_assignment" { @@ -583,9 +584,9 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { // required for sensor import - util.MockGetSensor("sensor_uid", util.GeneratePaginatedResponse( + util.MockGetSensor("sensor_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateSensorResponseModel("sensor_uid", ""), + util.GenerateSensorResponseModel("sensor_id", ""), }, ), 1, @@ -593,17 +594,17 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // required for group create util.MockPostGroup( - util.GenerateGroupRequestModel("group_uid", "", ""), + util.GenerateGroupRequestModel("group_id", "", ""), util.StructToMap( - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), ), 1, ) util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 1, @@ -611,7 +612,7 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // sensor group assignment create util.MockGetSensorGroupAssignment( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", util.GeneratePaginatedResponse([]map[string]interface{}{}), 1, ) @@ -619,7 +620,7 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" } resource "uxi_sensor" "my_sensor" { @@ -631,7 +632,7 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { import { to = uxi_sensor.my_sensor - id = "sensor_uid" + id = "sensor_id" } resource "uxi_sensor_group_assignment" "my_sensor_group_assignment" { @@ -641,7 +642,7 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { import { to = uxi_sensor_group_assignment.my_sensor_group_assignment - id = "sensor_group_assignment_uid" + id = "sensor_group_assignment_id" } `, ExpectError: regexp.MustCompile(`Could not find specified resource`), @@ -650,9 +651,9 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { // required for sensor import - util.MockGetSensor("sensor_uid", util.GeneratePaginatedResponse( + util.MockGetSensor("sensor_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateSensorResponseModel("sensor_uid", ""), + util.GenerateSensorResponseModel("sensor_id", ""), }, ), 1, @@ -660,17 +661,17 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // required for group create util.MockPostGroup( - util.GenerateGroupRequestModel("group_uid", "", ""), + util.GenerateGroupRequestModel("group_id", "", ""), util.StructToMap( - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), ), 1, ) util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 1, @@ -679,9 +680,9 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // required for sensor group assignment read gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/sensor-group-assignments"). - Reply(500). + Reply(http.StatusInternalServerError). JSON(map[string]interface{}{ - "httpStatusCode": 500, + "httpStatusCode": http.StatusInternalServerError, "errorCode": "HPE_GL_ERROR_INTERNAL_SERVER_ERROR", "message": "Current request cannot be processed due to unknown issue", "debugId": "12312-123123-123123-1231212", @@ -690,7 +691,7 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" } resource "uxi_sensor" "my_sensor" { @@ -702,7 +703,7 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { import { to = uxi_sensor.my_sensor - id = "sensor_uid" + id = "sensor_id" } resource "uxi_sensor_group_assignment" "my_sensor_group_assignment" { @@ -712,7 +713,7 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { import { to = uxi_sensor_group_assignment.my_sensor_group_assignment - id = "sensor_group_assignment_uid" + id = "sensor_group_assignment_id" } `, @@ -724,9 +725,9 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { // required for sensor import - util.MockGetSensor("sensor_uid", util.GeneratePaginatedResponse( + util.MockGetSensor("sensor_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateSensorResponseModel("sensor_uid", ""), + util.GenerateSensorResponseModel("sensor_id", ""), }, ), 2, @@ -734,17 +735,17 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // required for group create util.MockPostGroup( - util.GenerateGroupRequestModel("group_uid", "", ""), + util.GenerateGroupRequestModel("group_id", "", ""), util.StructToMap( - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), ), 1, ) util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 1, @@ -753,21 +754,21 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // required for sensor group assignment create util.MockPostSensorGroupAssignment( util.GenerateSensorGroupAssignmentRequest( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", "", ), util.GenerateSensorGroupAssignmentResponse( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", "", ), 1, ) util.MockGetSensorGroupAssignment( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateSensorGroupAssignmentResponse( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", "", ), }, @@ -779,7 +780,7 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" } resource "uxi_sensor" "my_sensor" { @@ -791,7 +792,7 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { import { to = uxi_sensor.my_sensor - id = "sensor_uid" + id = "sensor_id" } resource "uxi_sensor_group_assignment" "my_sensor_group_assignment" { @@ -802,7 +803,7 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { resource.TestCheckResourceAttr( "uxi_sensor_group_assignment.my_sensor_group_assignment", "id", - "sensor_group_assignment_uid", + "sensor_group_assignment_id", ), ), }, @@ -810,20 +811,20 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 1, ) util.MockGetSensorGroupAssignment( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateSensorGroupAssignmentResponse( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", "", ), }, @@ -832,10 +833,10 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { ) gock.New("https://test.api.capenetworks.com"). - Delete("/networking-uxi/v1alpha1/sensor-group-assignments/sensor_group_assignment_uid"). - Reply(400). + Delete("/networking-uxi/v1alpha1/sensor-group-assignments/sensor_group_assignment_id"). + Reply(http.StatusBadRequest). JSON(map[string]interface{}{ - "httpStatusCode": 400, + "httpStatusCode": http.StatusBadRequest, "errorCode": "HPE_GL_ERROR_BAD_REQUEST", "message": "Validation error - bad request", "debugId": "12312-123123-123123-1231212", @@ -865,28 +866,28 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 1, ) util.MockGetSensorGroupAssignment( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", util.GeneratePaginatedResponse( []map[string]interface{}{ util.GenerateSensorGroupAssignmentResponse( - "sensor_group_assignment_uid", + "sensor_group_assignment_id", "", ), }, ), 1, ) - util.MockDeleteGroup("group_uid", 1) - util.MockDeleteSensorGroupAssignment("sensor_group_assignment_uid", 1) + util.MockDeleteGroup("group_id", 1) + util.MockDeleteSensorGroupAssignment("sensor_group_assignment_id", 1) }, Config: provider.ProviderConfig + ` removed { diff --git a/test/mocked/resources/sensor_test.go b/test/mocked/resources/sensor_test.go index ba90ae16..9dd373c1 100644 --- a/test/mocked/resources/sensor_test.go +++ b/test/mocked/resources/sensor_test.go @@ -1,12 +1,13 @@ package resource_test import ( - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/resources" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" + "net/http" "regexp" "testing" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/util" + "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -42,8 +43,8 @@ func TestSensorResource(t *testing.T) { // Importing a sensor { PreConfig: func() { - util.MockGetSensor("uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateSensorResponseModel("uid", "")}), + util.MockGetSensor("id", util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateSensorResponseModel("id", "")}), 2, ) }, @@ -57,7 +58,7 @@ func TestSensorResource(t *testing.T) { import { to = uxi_sensor.my_sensor - id = "uid" + id = "id" }`, Check: resource.ComposeAggregateTestCheckFunc( @@ -69,14 +70,14 @@ func TestSensorResource(t *testing.T) { ), resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "notes", "notes"), resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "pcap_mode", "light"), - resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "id", "uid"), + resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "id", "id"), ), }, // ImportState testing { PreConfig: func() { - util.MockGetSensor("uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateSensorResponseModel("uid", "")}), + util.MockGetSensor("id", util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateSensorResponseModel("id", "")}), 1, ) }, @@ -88,16 +89,19 @@ func TestSensorResource(t *testing.T) { { PreConfig: func() { // existing sensor - util.MockGetSensor("uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateSensorResponseModel("uid", "")}), + util.MockGetSensor("id", util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateSensorResponseModel("id", "")}), + 1, + ) + util.MockUpdateSensor( + "id", + util.GenerateSensorRequestUpdateModel("_2"), + util.GenerateSensorResponseModel("id", "_2"), 1, ) - resources.UpdateSensor = func(request resources.SensorUpdateRequestModel) resources.SensorResponseModel { - return util.GenerateMockedSensorResponseModel("uid", "_2") - } // updated sensor - util.MockGetSensor("uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateSensorResponseModel("uid", "_2")}), + util.MockGetSensor("id", util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateSensorResponseModel("id", "_2")}), 1, ) }, @@ -117,14 +121,14 @@ func TestSensorResource(t *testing.T) { ), resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "notes", "notes_2"), resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "pcap_mode", "light_2"), - resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "id", "uid"), + resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "id", "id"), ), }, // Deleting a sensor is not allowed { PreConfig: func() { - util.MockGetSensor("uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateSensorResponseModel("uid", "_2")}), + util.MockGetSensor("id", util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateSensorResponseModel("id", "_2")}), 1, ) }, @@ -150,10 +154,10 @@ func TestSensorResource(t *testing.T) { mockOAuth.Mock.Disable() } -func TestSensorResource429Handling(t *testing.T) { +func TestSensorResourceTooManyRequestsHandling(t *testing.T) { defer gock.Off() mockOAuth := util.MockOAuth() - var request429 *gock.Response + var mockTooManyRequests *gock.Response resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -165,12 +169,12 @@ func TestSensorResource429Handling(t *testing.T) { // Importing a sensor { PreConfig: func() { - request429 = gock.New("https://test.api.capenetworks.com"). + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/sensors"). - Reply(429). + Reply(http.StatusTooManyRequests). SetHeaders(util.RateLimitingHeaders) - util.MockGetSensor("uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateSensorResponseModel("uid", "")}), + util.MockGetSensor("id", util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateSensorResponseModel("id", "")}), 2, ) }, @@ -184,13 +188,52 @@ func TestSensorResource429Handling(t *testing.T) { import { to = uxi_sensor.my_sensor - id = "uid" + id = "id" }`, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "id", "uid"), + resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "id", "id"), func(s *terraform.State) error { - st.Assert(t, request429.Mock.Request().Counter, 0) + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) + return nil + }, + ), + }, + // Update and Read testing + { + PreConfig: func() { + // existing sensor + util.MockGetSensor("id", util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateSensorResponseModel("id", "")}), + 1, + ) + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). + Patch("/networking-uxi/v1alpha1/sensors/id"). + Reply(http.StatusTooManyRequests). + SetHeaders(util.RateLimitingHeaders) + util.MockUpdateSensor( + "id", + util.GenerateSensorRequestUpdateModel("_2"), + util.GenerateSensorResponseModel("id", "_2"), + 1, + ) + // updated sensor + util.MockGetSensor("id", util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateSensorResponseModel("id", "_2")}), + 1, + ) + }, + Config: provider.ProviderConfig + ` + resource "uxi_sensor" "my_sensor" { + name = "name_2" + address_note = "address_note_2" + notes = "notes_2" + pcap_mode = "light_2" + }`, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "name", "name_2"), + func(s *terraform.State) error { + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) return nil }, ), @@ -228,9 +271,9 @@ func TestSensorResourceHttpErrorHandling(t *testing.T) { PreConfig: func() { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/sensors"). - Reply(500). + Reply(http.StatusInternalServerError). JSON(map[string]interface{}{ - "httpStatusCode": 500, + "httpStatusCode": http.StatusInternalServerError, "errorCode": "HPE_GL_ERROR_INTERNAL_SERVER_ERROR", "message": "Current request cannot be processed due to unknown issue", "debugId": "12312-123123-123123-1231212", @@ -246,7 +289,7 @@ func TestSensorResourceHttpErrorHandling(t *testing.T) { import { to = uxi_sensor.my_sensor - id = "uid" + id = "id" }`, ExpectError: regexp.MustCompile( @@ -257,7 +300,7 @@ func TestSensorResourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetSensor( - "uid", + "id", util.GeneratePaginatedResponse([]map[string]interface{}{}), 1, ) @@ -272,11 +315,86 @@ func TestSensorResourceHttpErrorHandling(t *testing.T) { import { to = uxi_sensor.my_sensor - id = "uid" + id = "id" }`, ExpectError: regexp.MustCompile(`Error: Cannot import non-existent remote object`), }, + // Actually import a sensor for subsequent testing + { + PreConfig: func() { + util.MockGetSensor("id", util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateSensorResponseModel("id", "")}), + 2, + ) + }, + Config: provider.ProviderConfig + ` + resource "uxi_sensor" "my_sensor" { + name = "name" + address_note = "address_note" + notes = "notes" + pcap_mode = "light" + } + + import { + to = uxi_sensor.my_sensor + id = "id" + }`, + + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "name", "name"), + resource.TestCheckResourceAttr( + "uxi_sensor.my_sensor", + "address_note", + "address_note", + ), + resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "notes", "notes"), + resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "pcap_mode", "light"), + resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "id", "id"), + ), + }, + // Update 4xx + { + PreConfig: func() { + // existing sensor + util.MockGetSensor("id", util.GeneratePaginatedResponse( + []map[string]interface{}{util.GenerateSensorResponseModel("id", "")}), + 1, + ) + // patch sensor - with error + gock.New("https://test.api.capenetworks.com"). + Patch("/networking-uxi/v1alpha1/sensors/id"). + Reply(http.StatusUnprocessableEntity). + JSON(map[string]interface{}{ + "httpStatusCode": http.StatusUnprocessableEntity, + "errorCode": "HPE_GL_UXI_INVALID_PCAP_MODE_ERROR", + "message": "Unable to update sensor - pcap_mode must be one the following ['light', 'full', 'off'].", + "debugId": "12312-123123-123123-1231212", + "type": "hpe.greenlake.uxi.invalid_pcap_mode", + }) + }, + Config: provider.ProviderConfig + ` + resource "uxi_sensor" "my_sensor" { + name = "name_2" + address_note = "address_note_2" + notes = "notes_2" + pcap_mode = "light_2" + }`, + ExpectError: regexp.MustCompile( + `(?s)Unable to update sensor - pcap_mode must be one the following \['light',\s*'full', 'off'\].\s*DebugID: 12312-123123-123123-1231212`, + ), + }, + // Remove sensor from state + { + Config: provider.ProviderConfig + ` + removed { + from = uxi_sensor.my_sensor + + lifecycle { + destroy = false + } + }`, + }, }, }) diff --git a/test/mocked/resources/service_test.go b/test/mocked/resources/service_test.go index bc71b385..dca1c52c 100644 --- a/test/mocked/resources/service_test.go +++ b/test/mocked/resources/service_test.go @@ -1,8 +1,8 @@ package resource_test import ( - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/util" "regexp" "testing" @@ -37,10 +37,10 @@ func TestServiceTestResource(t *testing.T) { { PreConfig: func() { util.MockGetServiceTest( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateServiceTestResponseModel("uid", ""), + util.GenerateServiceTestResponseModel("id", ""), }, ), 2, @@ -53,7 +53,7 @@ func TestServiceTestResource(t *testing.T) { import { to = uxi_service_test.my_service_test - id = "uid" + id = "id" }`, Check: resource.ComposeAggregateTestCheckFunc( @@ -62,17 +62,17 @@ func TestServiceTestResource(t *testing.T) { "name", "name", ), - resource.TestCheckResourceAttr("uxi_service_test.my_service_test", "id", "uid"), + resource.TestCheckResourceAttr("uxi_service_test.my_service_test", "id", "id"), ), }, // ImportState testing { PreConfig: func() { util.MockGetServiceTest( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateServiceTestResponseModel("uid", ""), + util.GenerateServiceTestResponseModel("id", ""), }, ), 1, @@ -86,10 +86,10 @@ func TestServiceTestResource(t *testing.T) { { PreConfig: func() { util.MockGetServiceTest( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateServiceTestResponseModel("uid", ""), + util.GenerateServiceTestResponseModel("id", ""), }, ), 1, @@ -107,10 +107,10 @@ func TestServiceTestResource(t *testing.T) { { PreConfig: func() { util.MockGetServiceTest( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateServiceTestResponseModel("uid", ""), + util.GenerateServiceTestResponseModel("id", ""), }, ), 1, diff --git a/test/mocked/resources/service_test_group_assignment_test.go b/test/mocked/resources/service_test_group_assignment_test.go index e75d9387..42762e24 100644 --- a/test/mocked/resources/service_test_group_assignment_test.go +++ b/test/mocked/resources/service_test_group_assignment_test.go @@ -1,11 +1,12 @@ package resource_test import ( + "net/http" "regexp" "testing" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/util" "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -25,25 +26,25 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { PreConfig: func() { // required for serviceTest import util.MockGetServiceTest( - "service_test_uid", + "service_test_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateServiceTestResponseModel("service_test_uid", ""), + util.GenerateServiceTestResponseModel("service_test_id", ""), }, ), 2, ) // required for group create util.MockPostGroup( - util.GenerateGroupRequestModel("group_uid", "", ""), - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateGroupRequestModel("group_id", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), 1, ) util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 1, @@ -51,20 +52,20 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { // required for serviceTest group assignment create util.MockPostServiceTestGroupAssignment( util.GenerateServiceTestGroupAssignmentRequest( - "service_test_group_assignment_uid", + "service_test_group_assignment_id", "", ), util.GenerateServiceTestGroupAssignmentResponse( - "service_test_group_assignment_uid", + "service_test_group_assignment_id", "", ), 1, ) util.MockGetServiceTestGroupAssignment( - "service_test_group_assignment_uid", + "service_test_group_assignment_id", util.GeneratePaginatedResponse([]map[string]interface{}{ util.GenerateServiceTestGroupAssignmentResponse( - "service_test_group_assignment_uid", "", + "service_test_group_assignment_id", "", )}, ), 1, @@ -74,7 +75,7 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" } resource "uxi_service_test" "my_service_test" { @@ -83,7 +84,7 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { import { to = uxi_service_test.my_service_test - id = "service_test_uid" + id = "service_test_id" } resource "uxi_service_test_group_assignment" "my_service_test_group_assignment" { @@ -94,17 +95,17 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { resource.TestCheckResourceAttr( "uxi_service_test_group_assignment.my_service_test_group_assignment", "service_test_id", - "service_test_uid", + "service_test_id", ), resource.TestCheckResourceAttr( "uxi_service_test_group_assignment.my_service_test_group_assignment", "group_id", - "group_uid", + "group_id", ), resource.TestCheckResourceAttr( "uxi_service_test_group_assignment.my_service_test_group_assignment", "id", - "service_test_group_assignment_uid", + "service_test_group_assignment_id", ), ), }, @@ -112,10 +113,10 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { { PreConfig: func() { util.MockGetServiceTestGroupAssignment( - "service_test_group_assignment_uid", + "service_test_group_assignment_id", util.GeneratePaginatedResponse([]map[string]interface{}{ util.GenerateServiceTestGroupAssignmentResponse( - "service_test_group_assignment_uid", "", + "service_test_group_assignment_id", "", )}, ), 1, @@ -129,37 +130,37 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { { PreConfig: func() { util.MockGetServiceTest( - "service_test_uid_2", + "service_test_id_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateServiceTestResponseModel("service_test_uid_2", "_2"), + util.GenerateServiceTestResponseModel("service_test_id_2", "_2"), }, ), 2, ) util.MockGetServiceTest( - "service_test_uid", + "service_test_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateServiceTestResponseModel("service_test_uid", ""), + util.GenerateServiceTestResponseModel("service_test_id", ""), }, ), 2, ) util.MockGetGroup( - "group_uid_2", + "group_id_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_id_2", "_2", "_2"), }, ), 1, ) util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 3, @@ -170,37 +171,37 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { // required for creating another group util.MockPostGroup( - util.GenerateGroupRequestModel("group_uid_2", "_2", "_2"), - util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateGroupRequestModel("group_id_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_id_2", "_2", "_2"), 1, ) // required for serviceTest group assignment create util.MockGetServiceTestGroupAssignment( - "service_test_group_assignment_uid_2", + "service_test_group_assignment_id_2", util.GeneratePaginatedResponse([]map[string]interface{}{ util.GenerateServiceTestGroupAssignmentResponse( - "service_test_group_assignment_uid_2", "_2", + "service_test_group_assignment_id_2", "_2", )}, ), 2, ) util.MockGetServiceTestGroupAssignment( - "service_test_group_assignment_uid", + "service_test_group_assignment_id", util.GeneratePaginatedResponse([]map[string]interface{}{ util.GenerateServiceTestGroupAssignmentResponse( - "service_test_group_assignment_uid", "", + "service_test_group_assignment_id", "", )}, ), 1, ) util.MockPostServiceTestGroupAssignment( util.GenerateServiceTestGroupAssignmentRequest( - "service_test_group_assignment_uid_2", + "service_test_group_assignment_id_2", "_2", ), util.GenerateServiceTestGroupAssignmentResponse( - "service_test_group_assignment_uid_2", + "service_test_group_assignment_id_2", "_2", ), 1, @@ -210,7 +211,7 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { // the original resources resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" } resource "uxi_service_test" "my_service_test" { @@ -219,13 +220,13 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { import { to = uxi_service_test.my_service_test - id = "service_test_uid" + id = "service_test_id" } // the new resources we wanna update the assignment to resource "uxi_group" "my_group_2" { name = "name_2" - parent_group_id = "parent_uid_2" + parent_group_id = "parent_id_2" } resource "uxi_service_test" "my_service_test_2" { @@ -234,7 +235,7 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { import { to = uxi_service_test.my_service_test_2 - id = "service_test_uid_2" + id = "service_test_id_2" } // the assignment update, updated from service_test/group to service_test_2/group_2 @@ -246,17 +247,17 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { resource.TestCheckResourceAttr( "uxi_service_test_group_assignment.my_service_test_group_assignment", "service_test_id", - "service_test_uid_2", + "service_test_id_2", ), resource.TestCheckResourceAttr( "uxi_service_test_group_assignment.my_service_test_group_assignment", "group_id", - "group_uid_2", + "group_id_2", ), resource.TestCheckResourceAttr( "uxi_service_test_group_assignment.my_service_test_group_assignment", "id", - "service_test_group_assignment_uid_2", + "service_test_group_assignment_id_2", ), ), }, @@ -264,28 +265,28 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { { PreConfig: func() { util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 1, ) util.MockGetGroup( - "group_uid_2", + "group_id_2", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid_2", "_2", "_2"), + util.GenerateNonRootGroupResponseModel("group_id_2", "_2", "_2"), }, ), 1, ) - util.MockDeleteGroup("group_uid", 1) - util.MockDeleteGroup("group_uid_2", 1) + util.MockDeleteGroup("group_id", 1) + util.MockDeleteGroup("group_id_2", 1) util.MockDeleteServiceTestGroupAssignment( - "service_test_group_assignment_uid_2", + "service_test_group_assignment_id_2", 1, ) }, @@ -312,10 +313,10 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { mockOAuth.Mock.Disable() } -func TestServiceTestGroupAssignmentResource429Handling(t *testing.T) { +func TestServiceTestGroupAssignmentResourceTooManyRequestsHandling(t *testing.T) { defer gock.Off() mockOAuth := util.MockOAuth() - var mock429 *gock.Response + var mockTooManyRequests *gock.Response resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, @@ -325,10 +326,10 @@ func TestServiceTestGroupAssignmentResource429Handling(t *testing.T) { PreConfig: func() { // required for serviceTest import util.MockGetServiceTest( - "service_test_uid", + "service_test_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateServiceTestResponseModel("service_test_uid", ""), + util.GenerateServiceTestResponseModel("service_test_id", ""), }, ), 2, @@ -336,42 +337,42 @@ func TestServiceTestGroupAssignmentResource429Handling(t *testing.T) { // required for group create util.MockPostGroup( - util.GenerateGroupRequestModel("group_uid", "", ""), - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateGroupRequestModel("group_id", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), 1, ) util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 1, ) // required for serviceTest group assignment create - mock429 = gock.New("https://test.api.capenetworks.com"). + mockTooManyRequests = gock.New("https://test.api.capenetworks.com"). Post("/networking-uxi/v1alpha1/service-test-group-assignments"). - Reply(429). + Reply(http.StatusTooManyRequests). SetHeaders(util.RateLimitingHeaders) util.MockPostServiceTestGroupAssignment( util.GenerateServiceTestGroupAssignmentRequest( - "service_test_group_assignment_uid", + "service_test_group_assignment_id", "", ), util.GenerateServiceTestGroupAssignmentResponse( - "service_test_group_assignment_uid", + "service_test_group_assignment_id", "", ), 1, ) util.MockGetServiceTestGroupAssignment( - "service_test_group_assignment_uid", + "service_test_group_assignment_id", util.GeneratePaginatedResponse([]map[string]interface{}{ util.GenerateServiceTestGroupAssignmentResponse( - "service_test_group_assignment_uid", "", + "service_test_group_assignment_id", "", )}, ), 1, @@ -381,7 +382,7 @@ func TestServiceTestGroupAssignmentResource429Handling(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" } resource "uxi_service_test" "my_service_test" { @@ -390,7 +391,7 @@ func TestServiceTestGroupAssignmentResource429Handling(t *testing.T) { import { to = uxi_service_test.my_service_test - id = "service_test_uid" + id = "service_test_id" } resource "uxi_service_test_group_assignment" "my_service_test_group_assignment" { @@ -401,10 +402,10 @@ func TestServiceTestGroupAssignmentResource429Handling(t *testing.T) { resource.TestCheckResourceAttr( "uxi_service_test_group_assignment.my_service_test_group_assignment", "id", - "service_test_group_assignment_uid", + "service_test_group_assignment_id", ), func(s *terraform.State) error { - st.Assert(t, mock429.Mock.Request().Counter, 0) + st.Assert(t, mockTooManyRequests.Mock.Request().Counter, 0) return nil }, ), @@ -413,27 +414,27 @@ func TestServiceTestGroupAssignmentResource429Handling(t *testing.T) { { PreConfig: func() { util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 1, ) util.MockGetServiceTestGroupAssignment( - "service_test_group_assignment_uid", + "service_test_group_assignment_id", util.GeneratePaginatedResponse([]map[string]interface{}{ util.GenerateServiceTestGroupAssignmentResponse( - "service_test_group_assignment_uid", "", + "service_test_group_assignment_id", "", )}, ), 1, ) - util.MockDeleteGroup("group_uid", 1) + util.MockDeleteGroup("group_id", 1) util.MockDeleteServiceTestGroupAssignment( - "service_test_group_assignment_uid", + "service_test_group_assignment_id", 1, ) }, @@ -464,10 +465,10 @@ func TestServiceTestGroupAssignmentResourceHttpErrorHandling(t *testing.T) { PreConfig: func() { // required for serviceTest import util.MockGetServiceTest( - "service_test_uid", + "service_test_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateServiceTestResponseModel("service_test_uid", ""), + util.GenerateServiceTestResponseModel("service_test_id", ""), }, ), 1, @@ -475,15 +476,15 @@ func TestServiceTestGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // required for group create util.MockPostGroup( - util.GenerateGroupRequestModel("group_uid", "", ""), - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateGroupRequestModel("group_id", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), 1, ) util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 1, @@ -492,9 +493,9 @@ func TestServiceTestGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // required for serviceTest group assignment create gock.New("https://test.api.capenetworks.com"). Post("/networking-uxi/v1alpha1/service-test-group-assignments"). - Reply(400). + Reply(http.StatusBadRequest). JSON(map[string]interface{}{ - "httpStatusCode": 400, + "httpStatusCode": http.StatusBadRequest, "errorCode": "HPE_GL_ERROR_BAD_REQUEST", "message": "Validation error - bad request", "debugId": "12312-123123-123123-1231212", @@ -504,7 +505,7 @@ func TestServiceTestGroupAssignmentResourceHttpErrorHandling(t *testing.T) { Config: provider.ProviderConfig + ` resource "uxi_group" "my_group" { name = "name" - parent_group_id = "parent_uid" + parent_group_id = "parent_id" } resource "uxi_service_test" "my_service_test" { @@ -513,7 +514,7 @@ func TestServiceTestGroupAssignmentResourceHttpErrorHandling(t *testing.T) { import { to = uxi_service_test.my_service_test - id = "service_test_uid" + id = "service_test_id" } resource "uxi_service_test_group_assignment" "my_service_test_group_assignment" { @@ -528,16 +529,16 @@ func TestServiceTestGroupAssignmentResourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetGroup( - "group_uid", + "group_id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateNonRootGroupResponseModel("group_uid", "", ""), + util.GenerateNonRootGroupResponseModel("group_id", "", ""), }, ), 1, ) - util.MockDeleteGroup("group_uid", 1) + util.MockDeleteGroup("group_id", 1) }, Config: provider.ProviderConfig + ` removed { diff --git a/test/mocked/resources/wired_network_test.go b/test/mocked/resources/wired_network_test.go index 35231125..d7a6984b 100644 --- a/test/mocked/resources/wired_network_test.go +++ b/test/mocked/resources/wired_network_test.go @@ -1,11 +1,13 @@ package resource_test import ( - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" + "net/http" "regexp" "testing" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/util" + "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/tfversion" @@ -37,9 +39,9 @@ func TestWiredNetworkResource(t *testing.T) { { PreConfig: func() { util.MockGetWiredNetwork( - "uid", + "id", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}, + []map[string]interface{}{util.GenerateWiredNetworkResponse("id", "")}, ), 2, ) @@ -51,7 +53,7 @@ func TestWiredNetworkResource(t *testing.T) { import { to = uxi_wired_network.my_wired_network - id = "uid" + id = "id" }`, Check: resource.ComposeAggregateTestCheckFunc( @@ -63,7 +65,7 @@ func TestWiredNetworkResource(t *testing.T) { resource.TestCheckResourceAttr( "uxi_wired_network.my_wired_network", "id", - "uid", + "id", ), ), }, @@ -71,9 +73,9 @@ func TestWiredNetworkResource(t *testing.T) { { PreConfig: func() { util.MockGetWiredNetwork( - "uid", + "id", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}, + []map[string]interface{}{util.GenerateWiredNetworkResponse("id", "")}, ), 1, ) @@ -86,9 +88,9 @@ func TestWiredNetworkResource(t *testing.T) { { PreConfig: func() { util.MockGetWiredNetwork( - "uid", + "id", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}, + []map[string]interface{}{util.GenerateWiredNetworkResponse("id", "")}, ), 1, ) @@ -105,9 +107,9 @@ func TestWiredNetworkResource(t *testing.T) { { PreConfig: func() { util.MockGetWiredNetwork( - "uid", + "id", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}, + []map[string]interface{}{util.GenerateWiredNetworkResponse("id", "")}, ), 2, ) @@ -148,7 +150,7 @@ func TestWiredNetworkResourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetWiredNetwork( - "uid", + "id", util.GeneratePaginatedResponse([]map[string]interface{}{}), 1, ) @@ -160,7 +162,7 @@ func TestWiredNetworkResourceHttpErrorHandling(t *testing.T) { import { to = uxi_wired_network.my_wired_network - id = "uid" + id = "id" }`, ExpectError: regexp.MustCompile(`Error: Cannot import non-existent remote object`), }, @@ -168,9 +170,9 @@ func TestWiredNetworkResourceHttpErrorHandling(t *testing.T) { PreConfig: func() { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/wired-networks"). - Reply(500). + Reply(http.StatusInternalServerError). JSON(map[string]interface{}{ - "httpStatusCode": 500, + "httpStatusCode": http.StatusInternalServerError, "errorCode": "HPE_GL_ERROR_INTERNAL_SERVER_ERROR", "message": "Current request cannot be processed due to unknown issue", "debugId": "12312-123123-123123-1231212", @@ -183,7 +185,7 @@ func TestWiredNetworkResourceHttpErrorHandling(t *testing.T) { import { to = uxi_wired_network.my_wired_network - id = "uid" + id = "id" }`, ExpectError: regexp.MustCompile( `(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`, diff --git a/test/mocked/resources/wireless_network_test.go b/test/mocked/resources/wireless_network_test.go index a803aaf9..eefee9a8 100644 --- a/test/mocked/resources/wireless_network_test.go +++ b/test/mocked/resources/wireless_network_test.go @@ -1,11 +1,13 @@ package resource_test import ( - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" - "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" + "net/http" "regexp" "testing" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/provider" + "github.com/aruba-uxi/terraform-provider-hpeuxi/test/mocked/util" + "github.com/h2non/gock" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/tfversion" @@ -37,10 +39,10 @@ func TestWirelessNetworkResource(t *testing.T) { { PreConfig: func() { util.MockGetWirelessNetwork( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWirelessNetworkResponse("uid", ""), + util.GenerateWirelessNetworkResponse("id", ""), }, ), 2, @@ -53,7 +55,7 @@ func TestWirelessNetworkResource(t *testing.T) { import { to = uxi_wireless_network.my_wireless_network - id = "uid" + id = "id" }`, Check: resource.ComposeAggregateTestCheckFunc( @@ -65,7 +67,7 @@ func TestWirelessNetworkResource(t *testing.T) { resource.TestCheckResourceAttr( "uxi_wireless_network.my_wireless_network", "id", - "uid", + "id", ), ), }, @@ -73,10 +75,10 @@ func TestWirelessNetworkResource(t *testing.T) { { PreConfig: func() { util.MockGetWirelessNetwork( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWirelessNetworkResponse("uid", ""), + util.GenerateWirelessNetworkResponse("id", ""), }, ), 1, @@ -90,10 +92,10 @@ func TestWirelessNetworkResource(t *testing.T) { { PreConfig: func() { util.MockGetWirelessNetwork( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWirelessNetworkResponse("uid", ""), + util.GenerateWirelessNetworkResponse("id", ""), }, ), 1, @@ -111,10 +113,10 @@ func TestWirelessNetworkResource(t *testing.T) { { PreConfig: func() { util.MockGetWirelessNetwork( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWirelessNetworkResponse("uid", ""), + util.GenerateWirelessNetworkResponse("id", ""), }, ), 1, @@ -129,10 +131,10 @@ func TestWirelessNetworkResource(t *testing.T) { { PreConfig: func() { util.MockGetWirelessNetwork( - "uid", + "id", util.GeneratePaginatedResponse( []map[string]interface{}{ - util.GenerateWirelessNetworkResponse("uid", ""), + util.GenerateWirelessNetworkResponse("id", ""), }, ), 1, @@ -167,7 +169,7 @@ func TestWirelessNetworkResourceHttpErrorHandling(t *testing.T) { { PreConfig: func() { util.MockGetWirelessNetwork( - "uid", + "id", util.GeneratePaginatedResponse([]map[string]interface{}{}), 1, ) @@ -179,7 +181,7 @@ func TestWirelessNetworkResourceHttpErrorHandling(t *testing.T) { import { to = uxi_wireless_network.my_wireless_network - id = "uid" + id = "id" }`, ExpectError: regexp.MustCompile(`Error: Cannot import non-existent remote object`), }, @@ -187,9 +189,9 @@ func TestWirelessNetworkResourceHttpErrorHandling(t *testing.T) { PreConfig: func() { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/wireless-networks"). - Reply(500). + Reply(http.StatusInternalServerError). JSON(map[string]interface{}{ - "httpStatusCode": 500, + "httpStatusCode": http.StatusInternalServerError, "errorCode": "HPE_GL_ERROR_INTERNAL_SERVER_ERROR", "message": "Current request cannot be processed due to unknown issue", "debugId": "12312-123123-123123-1231212", @@ -202,7 +204,7 @@ func TestWirelessNetworkResourceHttpErrorHandling(t *testing.T) { import { to = uxi_wireless_network.my_wireless_network - id = "uid" + id = "id" }`, ExpectError: regexp.MustCompile( `(?s)Current request cannot be processed due to unknown issue\s*DebugID: 12312-123123-123123-1231212`, diff --git a/test/mocked/util/utils.go b/test/mocked/util/utils.go index ed30959a..9e2b1eff 100644 --- a/test/mocked/util/utils.go +++ b/test/mocked/util/utils.go @@ -2,14 +2,14 @@ package util import ( "encoding/json" + "net/http" - "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/resources" "github.com/h2non/gock" ) -func GenerateSensorResponseModel(uid string, postfix string) map[string]interface{} { +func GenerateSensorResponseModel(id string, postfix string) map[string]interface{} { return map[string]interface{}{ - "id": uid, + "id": id, "serial": "serial" + postfix, "name": "name" + postfix, "modelNumber": "model_number" + postfix, @@ -24,25 +24,26 @@ func GenerateSensorResponseModel(uid string, postfix string) map[string]interfac } } -func GenerateMockedSensorResponseModel(uid string, postfix string) resources.SensorResponseModel { - return resources.SensorResponseModel{ - UID: uid, - Serial: "serial" + postfix, - Name: "name" + postfix, - ModelNumber: "model_number" + postfix, - WifiMacAddress: "wifi_mac_address" + postfix, - EthernetMacAddress: "ethernet_mac_address" + postfix, - AddressNote: "address_note" + postfix, - Longitude: 0.0, - Latitude: 0.0, - Notes: "notes" + postfix, - PCapMode: "light" + postfix, +func GenerateSensorRequestUpdateModel(postfix string) map[string]interface{} { + return map[string]interface{}{ + "name": "name" + postfix, + "addressNote": "address_note" + postfix, + "notes": "notes" + postfix, + "pcapMode": "light" + postfix, + } +} + +func GenerateAgentRequestUpdateModel(postfix string) map[string]interface{} { + return map[string]interface{}{ + "name": "name" + postfix, + "notes": "notes" + postfix, + "pcapMode": "light" + postfix, } } -func GenerateAgentResponseModel(uid string, postfix string) map[string]interface{} { +func GenerateAgentResponseModel(id string, postfix string) map[string]interface{} { return map[string]interface{}{ - "id": uid, + "id": id, "serial": "serial" + postfix, "name": "name" + postfix, "modelNumber": "model_number" + postfix, @@ -54,43 +55,30 @@ func GenerateAgentResponseModel(uid string, postfix string) map[string]interface } } -func GenerateMockedAgentResponseModel(uid string, postfix string) resources.AgentResponseModel { - return resources.AgentResponseModel{ - UID: uid, - Serial: "serial" + postfix, - Name: "name" + postfix, - ModelNumber: "model_number" + postfix, - WifiMacAddress: "wifi_mac_address" + postfix, - EthernetMacAddress: "ethernet_mac_address" + postfix, - Notes: "notes" + postfix, - PCapMode: "light" + postfix, - } -} - func GenerateNonRootGroupResponseModel( - uid string, + id string, nonReplacementFieldPostfix string, replacementFieldPostfix string, ) map[string]interface{} { - parentId := "parent_uid" + replacementFieldPostfix + parentId := "parent_id" + replacementFieldPostfix return map[string]interface{}{ - "id": uid, + "id": id, "name": "name" + nonReplacementFieldPostfix, "parent": map[string]string{"id": parentId}, - "path": parentId + "." + uid, + "path": parentId + "." + id, "type": "networking-uxi/group", } } func GenerateGroupRequestModel( - uid string, + id string, nonReplacementFieldPostfix string, replacementFieldPostfix string, ) map[string]interface{} { return map[string]interface{}{ "name": "name" + nonReplacementFieldPostfix, - "parentId": "parent_uid" + replacementFieldPostfix, + "parentId": "parent_id" + replacementFieldPostfix, } } @@ -103,11 +91,11 @@ func GeneratePaginatedResponse(items []map[string]interface{}) map[string]interf } func GenerateServiceTestResponseModel( - uid string, + id string, postfix string, ) map[string]interface{} { return map[string]interface{}{ - "id": uid, + "id": id, "category": "external" + postfix, "name": "name" + postfix, "target": "target" + postfix, @@ -117,9 +105,9 @@ func GenerateServiceTestResponseModel( } } -func GenerateWiredNetworkResponse(uid string, postfix string) map[string]interface{} { +func GenerateWiredNetworkResponse(id string, postfix string) map[string]interface{} { return map[string]interface{}{ - "id": uid, + "id": id, "name": "name" + postfix, "createdAt": "2024-09-11T12:00:00.000Z", "updatedAt": "2024-09-11T12:00:00.000Z", @@ -134,9 +122,9 @@ func GenerateWiredNetworkResponse(uid string, postfix string) map[string]interfa } } -func GenerateWirelessNetworkResponse(uid string, postfix string) map[string]interface{} { +func GenerateWirelessNetworkResponse(id string, postfix string) map[string]interface{} { return map[string]interface{}{ - "id": uid, + "id": id, "ssid": "ssid" + postfix, "createdAt": "2024-09-11T12:00:00.000Z", "updatedAt": "2024-09-11T12:00:00.000Z", @@ -153,78 +141,67 @@ func GenerateWirelessNetworkResponse(uid string, postfix string) map[string]inte } } -func GenerateSensorGroupAssignmentResponse(uid string, postfix string) map[string]interface{} { +func GenerateSensorGroupAssignmentResponse(id string, postfix string) map[string]interface{} { return map[string]interface{}{ - "id": uid, - "group": map[string]string{"id": "group_uid" + postfix}, - "sensor": map[string]string{"id": "sensor_uid" + postfix}, + "id": id, + "group": map[string]string{"id": "group_id" + postfix}, + "sensor": map[string]string{"id": "sensor_id" + postfix}, "type": "networking-uxi/sensor-group-assignment", } } -func GenerateSensorGroupAssignmentRequest(uid string, postfix string) map[string]interface{} { +func GenerateSensorGroupAssignmentRequest(id string, postfix string) map[string]interface{} { return map[string]interface{}{ - "groupId": "group_uid" + postfix, - "sensorId": "sensor_uid" + postfix, + "groupId": "group_id" + postfix, + "sensorId": "sensor_id" + postfix, } } -func GenerateAgentGroupAssignmentRequest(uid string, postfix string) map[string]interface{} { +func GenerateAgentGroupAssignmentRequest(id string, postfix string) map[string]interface{} { return map[string]interface{}{ - "groupId": "group_uid" + postfix, - "agentId": "agent_uid" + postfix, + "groupId": "group_id" + postfix, + "agentId": "agent_id" + postfix, } } -func GenerateAgentGroupAssignmentResponse(uid string, postfix string) map[string]interface{} { +func GenerateAgentGroupAssignmentResponse(id string, postfix string) map[string]interface{} { return map[string]interface{}{ - "id": uid, - "group": map[string]string{"id": "group_uid" + postfix}, - "agent": map[string]string{"id": "agent_uid" + postfix}, + "id": id, + "group": map[string]string{"id": "group_id" + postfix}, + "agent": map[string]string{"id": "agent_id" + postfix}, "type": "networking-uxi/agent-group-assignment", } } -func GenerateAgentGroupAssignmentResponseMockedModel( - uid string, - postfix string, -) resources.AgentGroupAssignmentResponseModel { - return resources.AgentGroupAssignmentResponseModel{ - UID: uid, - GroupUID: "group_uid" + postfix, - AgentUID: "agent_uid" + postfix, - } -} - -func GenerateNetworkGroupAssignmentResponse(uid string, postfix string) map[string]interface{} { +func GenerateNetworkGroupAssignmentResponse(id string, postfix string) map[string]interface{} { return map[string]interface{}{ - "id": uid, - "group": map[string]string{"id": "group_uid" + postfix}, - "network": map[string]string{"id": "network_uid" + postfix}, + "id": id, + "group": map[string]string{"id": "group_id" + postfix}, + "network": map[string]string{"id": "network_id" + postfix}, "type": "networking-uxi/network-group-assignment", } } -func GenerateNetworkGroupAssignmentRequest(uid string, postfix string) map[string]interface{} { +func GenerateNetworkGroupAssignmentRequest(id string, postfix string) map[string]interface{} { return map[string]interface{}{ - "groupId": "group_uid" + postfix, - "networkId": "network_uid" + postfix, + "groupId": "group_id" + postfix, + "networkId": "network_id" + postfix, } } -func GenerateServiceTestGroupAssignmentResponse(uid string, postfix string) map[string]interface{} { +func GenerateServiceTestGroupAssignmentResponse(id string, postfix string) map[string]interface{} { return map[string]interface{}{ - "id": uid, - "group": map[string]string{"id": "group_uid" + postfix}, - "serviceTest": map[string]string{"id": "service_test_uid" + postfix}, + "id": id, + "group": map[string]string{"id": "group_id" + postfix}, + "serviceTest": map[string]string{"id": "service_test_id" + postfix}, "type": "networking-uxi/service-test-group-assignment", } } -func GenerateServiceTestGroupAssignmentRequest(uid string, postfix string) map[string]interface{} { +func GenerateServiceTestGroupAssignmentRequest(id string, postfix string) map[string]interface{} { return map[string]interface{}{ - "groupId": "group_uid" + postfix, - "serviceTestId": "service_test_uid" + postfix, + "groupId": "group_id" + postfix, + "serviceTestId": "service_test_id" + postfix, } } @@ -243,7 +220,7 @@ func MockOAuth() *gock.Response { Post("/as/token.oauth2"). MatchHeader("Content-Type", "application/x-www-form-urlencoded"). Persist(). - Reply(200). + Reply(http.StatusOK). JSON(map[string]interface{}{ "access_token": "mock_token", "token_type": "bearer", @@ -252,22 +229,38 @@ func MockOAuth() *gock.Response { } -func MockGetAgent(uid string, response map[string]interface{}, times int) { +func MockGetAgent(id string, response map[string]interface{}, times int) { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/agents"). MatchHeader("Authorization", "mock_token"). - MatchParam("id", uid). + MatchParam("id", id). Times(times). - Reply(200). + Reply(http.StatusOK). JSON(response) } -func MockDeleteAgent(uid string, times int) { +func MockDeleteAgent(id string, times int) { gock.New("https://test.api.capenetworks.com"). - Delete("/networking-uxi/v1alpha1/agents/"+uid). + Delete("/networking-uxi/v1alpha1/agents/"+id). MatchHeader("Authorization", "mock_token"). Times(times). - Reply(204) + Reply(http.StatusNoContent) +} + +func MockUpdateAgent( + id string, + request map[string]interface{}, + response map[string]interface{}, + times int, +) { + gock.New("https://test.api.capenetworks.com"). + Patch("/networking-uxi/v1alpha1/agents/"+id). + MatchHeader("Content-Type", "application/merge-patch+json"). + MatchHeader("Authorization", "mock_token"). + JSON(request). + Times(times). + Reply(http.StatusOK). + JSON(response) } func MockPostGroup(request map[string]interface{}, response map[string]interface{}, times int) { @@ -277,92 +270,108 @@ func MockPostGroup(request map[string]interface{}, response map[string]interface MatchHeader("Authorization", "mock_token"). Times(times). JSON(request). - Reply(200). + Reply(http.StatusOK). JSON(response) } -func MockGetGroup(uid string, response map[string]interface{}, times int) { +func MockGetGroup(id string, response map[string]interface{}, times int) { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/groups"). MatchHeader("Authorization", "mock_token"). - MatchParam("id", uid). + MatchParam("id", id). Times(times). - Reply(200). + Reply(http.StatusOK). JSON(response) } func MockUpdateGroup( - uid string, + id string, request map[string]interface{}, response map[string]interface{}, times int, ) { body, _ := json.Marshal(request) gock.New("https://test.api.capenetworks.com"). - Patch("/networking-uxi/v1alpha1/groups/"+uid). + Patch("/networking-uxi/v1alpha1/groups/"+id). MatchHeader("Authorization", "mock_token"). MatchHeader("Content-Type", "application/merge-patch+json"). BodyString(string(body)). Times(times). - Reply(200). + Reply(http.StatusOK). JSON(response) } -func MockDeleteGroup(uid string, times int) { +func MockDeleteGroup(id string, times int) { gock.New("https://test.api.capenetworks.com"). - Delete("/networking-uxi/v1alpha1/groups/"+uid). + Delete("/networking-uxi/v1alpha1/groups/"+id). MatchHeader("Authorization", "mock_token"). Times(times). - Reply(204) + Reply(http.StatusNoContent) } -func MockGetSensor(uid string, response map[string]interface{}, times int) { +func MockGetSensor(id string, response map[string]interface{}, times int) { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/sensors"). MatchHeader("Authorization", "mock_token"). - MatchParam("id", uid). + MatchParam("id", id). + Times(times). + Reply(http.StatusOK). + JSON(response) +} + +func MockUpdateSensor( + id string, + request map[string]interface{}, + response map[string]interface{}, + times int, +) { + gock.New("https://test.api.capenetworks.com"). + Patch("/networking-uxi/v1alpha1/sensors/"+id). + MatchHeader("Content-Type", "application/merge-patch+json"). + MatchHeader("Authorization", "mock_token"). + JSON(request). Times(times). - Reply(200). + Reply(http.StatusOK). JSON(response) } -func MockGetWiredNetwork(uid string, response map[string]interface{}, times int) { +func MockGetWiredNetwork(id string, response map[string]interface{}, times int) { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/wired-networks"). MatchHeader("Authorization", "mock_token"). - MatchParam("id", uid). + MatchParam("id", id). Times(times). - Reply(200). + Reply(http.StatusOK). JSON(response) } -func MockGetWirelessNetwork(uid string, response map[string]interface{}, times int) { +func MockGetWirelessNetwork(id string, response map[string]interface{}, times int) { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/wireless-networks"). MatchHeader("Authorization", "mock_token"). - MatchParam("id", uid). + MatchParam("id", id). Times(times). - Reply(200). + Reply(http.StatusOK). JSON(response) } -func MockGetServiceTest(uid string, response map[string]interface{}, times int) { +func MockGetServiceTest(id string, response map[string]interface{}, times int) { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/service-tests"). MatchHeader("Authorization", "mock_token"). - MatchParam("id", uid). + MatchParam("id", id). Times(times). - Reply(200). + Reply(http.StatusOK). JSON(response) } -func MockGetAgentGroupAssignment(uid string, response map[string]interface{}, times int) { +func MockGetAgentGroupAssignment(id string, response map[string]interface{}, times int) { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/agent-group-assignments"). MatchHeader("Authorization", "mock_token"). - MatchParam("id", uid). + MatchParam("id", id). Times(times). - Reply(200). + Reply(http.StatusOK). JSON(response) } @@ -377,17 +386,25 @@ func MockPostAgentGroupAssignment( MatchHeader("Authorization", "mock_token"). Times(times). JSON(request). - Reply(200). + Reply(http.StatusOK). JSON(response) } -func MockGetSensorGroupAssignment(uid string, response map[string]interface{}, times int) { +func MockDeleteAgentGroupAssignment(id string, times int) { + gock.New("https://test.api.capenetworks.com"). + Delete("/networking-uxi/v1alpha1/agent-group-assignments/"+id). + MatchHeader("Authorization", "mock_token"). + Times(times). + Reply(http.StatusNoContent) +} + +func MockGetSensorGroupAssignment(id string, response map[string]interface{}, times int) { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/sensor-group-assignments"). MatchHeader("Authorization", "mock_token"). - MatchParam("id", uid). + MatchParam("id", id). Times(times). - Reply(200). + Reply(http.StatusOK). JSON(response) } @@ -402,25 +419,25 @@ func MockPostSensorGroupAssignment( MatchHeader("Authorization", "mock_token"). Times(times). JSON(request). - Reply(200). + Reply(http.StatusOK). JSON(response) } -func MockDeleteSensorGroupAssignment(uid string, times int) { +func MockDeleteSensorGroupAssignment(id string, times int) { gock.New("https://test.api.capenetworks.com"). - Delete("/networking-uxi/v1alpha1/sensor-group-assignments/"+uid). + Delete("/networking-uxi/v1alpha1/sensor-group-assignments/"+id). MatchHeader("Authorization", "mock_token"). Times(times). - Reply(204) + Reply(http.StatusNoContent) } -func MockGetNetworkGroupAssignment(uid string, response map[string]interface{}, times int) { +func MockGetNetworkGroupAssignment(id string, response map[string]interface{}, times int) { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/network-group-assignments"). MatchHeader("Authorization", "mock_token"). - MatchParam("id", uid). + MatchParam("id", id). Times(times). - Reply(200). + Reply(http.StatusOK). JSON(response) } @@ -435,25 +452,25 @@ func MockPostNetworkGroupAssignment( MatchHeader("Authorization", "mock_token"). Times(times). JSON(request). - Reply(200). + Reply(http.StatusOK). JSON(response) } -func MockDeleteNetworkGroupAssignment(uid string, times int) { +func MockDeleteNetworkGroupAssignment(id string, times int) { gock.New("https://test.api.capenetworks.com"). - Delete("/networking-uxi/v1alpha1/network-group-assignments/"+uid). + Delete("/networking-uxi/v1alpha1/network-group-assignments/"+id). MatchHeader("Authorization", "mock_token"). Times(times). - Reply(204) + Reply(http.StatusNoContent) } -func MockGetServiceTestGroupAssignment(uid string, response map[string]interface{}, times int) { +func MockGetServiceTestGroupAssignment(id string, response map[string]interface{}, times int) { gock.New("https://test.api.capenetworks.com"). Get("/networking-uxi/v1alpha1/service-test-group-assignments"). MatchHeader("Authorization", "mock_token"). - MatchParam("id", uid). + MatchParam("id", id). Times(times). - Reply(200). + Reply(http.StatusOK). JSON(response) } @@ -468,16 +485,16 @@ func MockPostServiceTestGroupAssignment( MatchHeader("Authorization", "mock_token"). Times(times). JSON(request). - Reply(200). + Reply(http.StatusOK). JSON(response) } -func MockDeleteServiceTestGroupAssignment(uid string, times int) { +func MockDeleteServiceTestGroupAssignment(id string, times int) { gock.New("https://test.api.capenetworks.com"). - Delete("/networking-uxi/v1alpha1/service-test-group-assignments/"+uid). + Delete("/networking-uxi/v1alpha1/service-test-group-assignments/"+id). MatchHeader("Authorization", "mock_token"). Times(times). - Reply(204) + Reply(http.StatusNoContent) } var RateLimitingHeaders = map[string]string{