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/internal/provider/datasources/agent.go b/internal/provider/datasources/agent.go index 04784ba0..3fe5f954 100644 --- a/internal/provider/datasources/agent.go +++ b/internal/provider/datasources/agent.go @@ -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, }, @@ -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/sensor.go b/internal/provider/datasources/sensor.go index b1437fa4..5bfff81e 100644 --- a/internal/provider/datasources/sensor.go +++ b/internal/provider/datasources/sensor.go @@ -137,6 +137,7 @@ 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()) diff --git a/test/live/config/config.go b/test/live/config/config.go index ddd9a23e..784605d7 100644 --- a/test/live/config/config.go +++ b/test/live/config/config.go @@ -1,5 +1,10 @@ package config +// 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 AgentUid = "8260f349-5c73-394a-b786-57985d001763" const WiredNetworkUid = "ethernet-0ee5b46c2ef0" const WiredNetworkName = "tf-provider-acceptance-tests-ethernet-0" const WirelessNetworkUid = "ssid-bf704ff37dc0" diff --git a/test/live/data-sources/agent_test.go b/test/live/data-sources/agent_test.go new file mode 100644 index 00000000..e757dfa8 --- /dev/null +++ b/test/live/data-sources/agent_test.go @@ -0,0 +1,168 @@ +package data_source_test + +import ( + "context" + "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/hashicorp/terraform-plugin-testing/helper/resource" + + "github.com/nbio/st" +) + +type agentProperties struct { + id string + serial string + name string + model_number *string + wifi_mac_address *string + ethernet_mac_address *string + notes *string + pcapMode *string +} + +func TestAgentDataSource(t *testing.T) { + agent := getAgentProperties(config.AgentUid) + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: provider.ProviderConfig + ` + data "uxi_agent" "my_agent" { + filter = { + agent_id = "` + config.AgentUid + `" + } + } + `, + Check: checkStateAgainstAgent(t, agent), + }, + }, + }) +} + +func checkStateAgainstAgent(t st.Fatalf, agent agentProperties) resource.TestCheckFunc { + return resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("data.uxi_agent.my_agent", "id", config.AgentUid), + resource.TestCheckResourceAttr("data.uxi_agent.my_agent", "serial", agent.serial), + func() resource.TestCheckFunc { + if agent.wifi_mac_address == nil { + return resource.TestCheckNoResourceAttr( + "data.uxi_agent.my_agent", + "model_number", + ) + } else { + return resource.TestCheckResourceAttrWith( + "data.uxi_agent.my_agent", + "model_number", + func(value string) error { + st.Assert(t, value, agent.model_number) + return nil + }, + ) + } + }(), + resource.TestCheckResourceAttrWith( + "data.uxi_agent.my_agent", + "name", + func(value string) error { + st.Assert(t, value, agent.name) + return nil + }, + ), + func() resource.TestCheckFunc { + if agent.wifi_mac_address == nil { + return resource.TestCheckNoResourceAttr( + "data.uxi_agent.my_agent", + "wifi_mac_address", + ) + } else { + return resource.TestCheckResourceAttrWith( + "data.uxi_agent.my_agent", + "wifi_mac_address", + func(value string) error { + st.Assert(t, value, agent.wifi_mac_address) + return nil + }, + ) + } + }(), + func() resource.TestCheckFunc { + if agent.wifi_mac_address == nil { + return resource.TestCheckNoResourceAttr( + "data.uxi_agent.my_agent", + "ethernet_mac_address", + ) + } else { + return resource.TestCheckResourceAttrWith( + "data.uxi_agent.my_agent", + "ethernet_mac_address", + func(value string) error { + st.Assert(t, value, agent.ethernet_mac_address) + return nil + }, + ) + } + }(), + func() resource.TestCheckFunc { + if agent.wifi_mac_address == nil { + return resource.TestCheckNoResourceAttr( + "data.uxi_agent.my_agent", + "notes", + ) + } else { + return resource.TestCheckResourceAttrWith( + "data.uxi_agent.my_agent", + "notes", + func(value string) error { + st.Assert(t, value, agent.notes) + return nil + }, + ) + } + }(), + func() resource.TestCheckFunc { + if agent.pcapMode == nil { + return resource.TestCheckNoResourceAttr( + "data.uxi_agent.my_agent", + "pcap_mode", + ) + } else { + return resource.TestCheckResourceAttrWith( + "data.uxi_agent.my_agent", + "pcap_mode", + func(value string) error { + st.Assert(t, value, agent.pcapMode) + return nil + }, + ) + } + }(), + ) +} + +func getAgentProperties(id string) agentProperties { + result, _, err := util.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") + } + agent := result.Items[0] + // Read these in, as they may not be always constant with the acceptance test customer + return agentProperties{ + id: agent.Id, + serial: agent.Serial, + name: agent.Name, + model_number: agent.ModelNumber.Get(), + wifi_mac_address: agent.WifiMacAddress.Get(), + ethernet_mac_address: agent.EthernetMacAddress.Get(), + notes: agent.Notes.Get(), + pcapMode: agent.PcapMode.Get(), + } +} diff --git a/test/mocked/data-sources/agent_test.go b/test/mocked/data-sources/agent_test.go index 062cd6b0..a903b99b 100644 --- a/test/mocked/data-sources/agent_test.go +++ b/test/mocked/data-sources/agent_test.go @@ -39,6 +39,25 @@ func TestAgentDataSource(t *testing.T) { `, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.uxi_agent.my_agent", "id", "uid"), + 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"), ), }, }, diff --git a/test/mocked/data-sources/sensor_test.go b/test/mocked/data-sources/sensor_test.go index 4c2e0f0c..19fb0033 100644 --- a/test/mocked/data-sources/sensor_test.go +++ b/test/mocked/data-sources/sensor_test.go @@ -39,6 +39,36 @@ func TestSensorDataSource(t *testing.T) { `, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.uxi_sensor.my_sensor", "id", "uid"), + 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", + ), ), }, },