Skip to content

Commit

Permalink
Merge branch 'main' into ay/feat/acceptance-tests/sensor-group-assign…
Browse files Browse the repository at this point in the history
…ment
  • Loading branch information
1riatsila1 authored Nov 11, 2024
2 parents 08f7e41 + 1ab084c commit 5e191a4
Show file tree
Hide file tree
Showing 7 changed files with 228 additions and 23 deletions.
3 changes: 0 additions & 3 deletions docs/data-sources/agent.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 9 additions & 20 deletions internal/provider/datasources/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions internal/provider/datasources/sensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions test/live/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package config
// 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"
Expand Down
168 changes: 168 additions & 0 deletions test/live/data-sources/agent_test.go
Original file line number Diff line number Diff line change
@@ -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(),
}
}
19 changes: 19 additions & 0 deletions test/mocked/data-sources/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
},
Expand Down
30 changes: 30 additions & 0 deletions test/mocked/data-sources/sensor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
),
},
},
Expand Down

0 comments on commit 5e191a4

Please sign in to comment.