a fe wmore tweaks to align outputs.a

This commit is contained in:
David Newhall II 2021-03-07 17:57:16 -08:00
parent 068ee31dfa
commit 8d9af25d47
4 changed files with 121 additions and 143 deletions

View File

@ -30,9 +30,11 @@ func TestUniReq(t *testing.T) {
a := assert.New(t) a := assert.New(t)
p := "/test/path" p := "/test/path"
u := "http://some.url:8443" u := "http://some.url:8443"
// Test empty parameters. // Test empty parameters.
authReq := &Unifi{Client: &http.Client{}, Config: &Config{URL: u, DebugLog: discardLogs}} authReq := &Unifi{Client: &http.Client{}, Config: &Config{URL: u, DebugLog: discardLogs}}
r, err := authReq.UniReq(p, "") r, err := authReq.UniReq(p, "")
a.Nil(err, "newrequest must not produce an error") a.Nil(err, "newrequest must not produce an error")
a.EqualValues(p, r.URL.Path, a.EqualValues(p, r.URL.Path,
"the provided apiPath was not added to http request") "the provided apiPath was not added to http request")
@ -45,11 +47,13 @@ func TestUniReq(t *testing.T) {
authReq = &Unifi{Client: &http.Client{}, Config: &Config{URL: "http://some.url:8443", DebugLog: discardLogs}} authReq = &Unifi{Client: &http.Client{}, Config: &Config{URL: "http://some.url:8443", DebugLog: discardLogs}}
r, err = authReq.UniReq(p, k) r, err = authReq.UniReq(p, k)
a.Nil(err, "newrequest must not produce an error") a.Nil(err, "newrequest must not produce an error")
a.EqualValues(p, r.URL.Path, a.EqualValues(p, r.URL.Path,
"the provided apiPath was not added to http request") "the provided apiPath was not added to http request")
a.EqualValues(u, r.URL.Scheme+"://"+r.URL.Host, "URL improperly encoded") a.EqualValues(u, r.URL.Scheme+"://"+r.URL.Host, "URL improperly encoded")
a.EqualValues("POST", r.Method, "with parameters the method must be POST") a.EqualValues("POST", r.Method, "with parameters the method must be POST")
a.EqualValues("application/json", r.Header.Get("Accept"), "Accept header must be set to application/json") a.EqualValues("application/json", r.Header.Get("Accept"), "Accept header must be set to application/json")
// Check the parameters. // Check the parameters.
d, err := ioutil.ReadAll(r.Body) d, err := ioutil.ReadAll(r.Body)
a.Nil(err, "problem reading request body, POST parameters may be malformed") a.Nil(err, "problem reading request body, POST parameters may be malformed")
@ -61,28 +65,31 @@ func TestUniReqPut(t *testing.T) {
a := assert.New(t) a := assert.New(t)
p := "/test/path" p := "/test/path"
u := "http://some.url:8443" u := "http://some.url:8443"
// Test empty parameters. // Test empty parameters.
authReq := &Unifi{Client: &http.Client{}, Config: &Config{URL: u, DebugLog: discardLogs}} authReq := &Unifi{Client: &http.Client{}, Config: &Config{URL: u, DebugLog: discardLogs}}
r, err := authReq.UniReqPut(p, "") _, err := authReq.UniReqPut(p, "")
a.NotNil(err, "empty params must produce an error") a.NotNil(err, "empty params must produce an error")
// Test with parameters // Test with parameters
k := "key1=value9&key2=value7" k := "key1=value9&key2=value7"
authReq = &Unifi{Client: &http.Client{}, Config: &Config{URL: "http://some.url:8443", DebugLog: discardLogs}} authReq = &Unifi{Client: &http.Client{}, Config: &Config{URL: "http://some.url:8443", DebugLog: discardLogs}}
r, err = authReq.UniReqPut(p, k) r, err := authReq.UniReqPut(p, k)
a.Nil(err, "newrequest must not produce an error") a.Nil(err, "newrequest must not produce an error")
a.EqualValues(p, r.URL.Path, a.EqualValues(p, r.URL.Path,
"the provided apiPath was not added to http request") "the provided apiPath was not added to http request")
a.EqualValues(u, r.URL.Scheme+"://"+r.URL.Host, "URL improperly encoded") a.EqualValues(u, r.URL.Scheme+"://"+r.URL.Host, "URL improperly encoded")
a.EqualValues("PUT", r.Method, "with parameters the method must be POST") a.EqualValues("PUT", r.Method, "with parameters the method must be POST")
a.EqualValues("application/json", r.Header.Get("Accept"), "Accept header must be set to application/json") a.EqualValues("application/json", r.Header.Get("Accept"), "Accept header must be set to application/json")
// Check the parameters. // Check the parameters.
d, err := ioutil.ReadAll(r.Body) d, err := ioutil.ReadAll(r.Body)
a.Nil(err, "problem reading request body, PUT parameters may be malformed") a.Nil(err, "problem reading request body, PUT parameters may be malformed")
a.EqualValues(k, string(d), "PUT parameters improperly encoded") a.EqualValues(k, string(d), "PUT parameters improperly encoded")
} }
/* NOT DONE: OPEN web server, check parameters posted, more. This test is incomplete. /* NOT DONE: OPEN web server, check parameters posted, more. These tests are incomplete.
a.EqualValues(`{"username": "user1","password": "pass2"}`, string(post_params), a.EqualValues(`{"username": "user1","password": "pass2"}`, string(post_params),
"user/pass json parameters improperly encoded") "user/pass json parameters improperly encoded")
*/ */

View File

@ -53,28 +53,7 @@ type USG struct {
SpeedtestStatusSaved FlexBool `json:"speedtest-status-saved"` SpeedtestStatusSaved FlexBool `json:"speedtest-status-saved"`
Wan1 Wan `json:"wan1"` Wan1 Wan `json:"wan1"`
Wan2 Wan `json:"wan2"` Wan2 Wan `json:"wan2"`
PortTable []struct { PortTable []*Port `json:"port_table"`
Name string `json:"name"`
Ifname string `json:"ifname"`
IP string `json:"ip"`
Netmask string `json:"netmask"`
Mac string `json:"mac"`
Up FlexBool `json:"up"`
Speed FlexInt `json:"speed"`
FullDuplex FlexBool `json:"full_duplex"`
RxBytes FlexInt `json:"rx_bytes"`
RxDropped FlexInt `json:"rx_dropped"`
RxErrors FlexInt `json:"rx_errors"`
RxPackets FlexInt `json:"rx_packets"`
TxBytes FlexInt `json:"tx_bytes"`
TxDropped FlexInt `json:"tx_dropped"`
TxErrors FlexInt `json:"tx_errors"`
TxPackets FlexInt `json:"tx_packets"`
RxMulticast FlexInt `json:"rx_multicast"`
Enable FlexBool `json:"enable"`
DNS []string `json:"dns,omitempty"`
Gateway string `json:"gateway,omitempty"`
} `json:"port_table"`
NetworkTable NetworkTable `json:"network_table"` NetworkTable NetworkTable `json:"network_table"`
Uplink Uplink `json:"uplink"` Uplink Uplink `json:"uplink"`
Stat USGStat `json:"stat"` Stat USGStat `json:"stat"`
@ -180,6 +159,7 @@ type SpeedtestStatus struct {
Runtime FlexInt `json:"runtime"` Runtime FlexInt `json:"runtime"`
ServerDesc string `json:"server_desc,omitempty"` ServerDesc string `json:"server_desc,omitempty"`
Server *SpeedtestServer `json:"server"` Server *SpeedtestServer `json:"server"`
SourceInterface string `json:"source_interface"`
StatusDownload FlexInt `json:"status_download"` StatusDownload FlexInt `json:"status_download"`
StatusPing FlexInt `json:"status_ping"` StatusPing FlexInt `json:"status_ping"`
StatusSummary FlexInt `json:"status_summary"` StatusSummary FlexInt `json:"status_summary"`

View File

@ -13,16 +13,9 @@ type USW struct {
Adopted FlexBool `json:"adopted"` Adopted FlexBool `json:"adopted"`
BoardRev FlexInt `json:"board_rev"` BoardRev FlexInt `json:"board_rev"`
Cfgversion string `json:"cfgversion"` Cfgversion string `json:"cfgversion"`
ConfigNetwork struct { ConfigNetwork *ConfigNetwork `json:"config_network"`
Type string `json:"type"`
IP string `json:"ip"`
} `json:"config_network"`
Dot1XPortctrlEnabled FlexBool `json:"dot1x_portctrl_enabled"` Dot1XPortctrlEnabled FlexBool `json:"dot1x_portctrl_enabled"`
EthernetTable []struct { EthernetTable []*EthernetTable `json:"ethernet_table"`
Mac string `json:"mac"`
NumPort FlexInt `json:"num_port,omitempty"`
Name string `json:"name"`
} `json:"ethernet_table"`
FlowctrlEnabled FlexBool `json:"flowctrl_enabled"` FlowctrlEnabled FlexBool `json:"flowctrl_enabled"`
FwCaps FlexInt `json:"fw_caps"` FwCaps FlexInt `json:"fw_caps"`
HasFan FlexBool `json:"has_fan"` HasFan FlexBool `json:"has_fan"`
@ -73,12 +66,7 @@ type USW struct {
GeneralTemperature FlexInt `json:"general_temperature"` GeneralTemperature FlexInt `json:"general_temperature"`
Overheating FlexBool `json:"overheating"` Overheating FlexBool `json:"overheating"`
TotalMaxPower FlexInt `json:"total_max_power"` TotalMaxPower FlexInt `json:"total_max_power"`
DownlinkTable []struct { DownlinkTable []*DownlinkTable `json:"downlink_table"`
PortIdx FlexInt `json:"port_idx"`
Speed FlexInt `json:"speed"`
FullDuplex FlexBool `json:"full_duplex"`
Mac string `json:"mac"`
} `json:"downlink_table"`
Uplink Uplink `json:"uplink"` Uplink Uplink `json:"uplink"`
LastUplink struct { LastUplink struct {
UplinkMac string `json:"uplink_mac"` UplinkMac string `json:"uplink_mac"`
@ -109,7 +97,8 @@ type MacTable struct {
Mac string `json:"mac"` Mac string `json:"mac"`
} }
// Port is a physical connection on a USW or UDM. // Port is a physical connection on a USW or Gateway.
// Not every port has the same capabilities.
type Port struct { type Port struct {
AggregatedBy FlexBool `json:"aggregated_by"` AggregatedBy FlexBool `json:"aggregated_by"`
Autoneg FlexBool `json:"autoneg,omitempty"` Autoneg FlexBool `json:"autoneg,omitempty"`

View File

@ -9,15 +9,15 @@ type UXG struct {
IP string `json:"ip"` IP string `json:"ip"`
Mac string `json:"mac"` Mac string `json:"mac"`
Model string `json:"model"` Model string `json:"model"`
ModelInLts bool `json:"model_in_lts"` ModelInLts FlexBool `json:"model_in_lts"`
ModelInEol bool `json:"model_in_eol"` ModelInEol FlexBool `json:"model_in_eol"`
Type string `json:"type"` Type string `json:"type"`
Version string `json:"version"` Version string `json:"version"`
Adopted bool `json:"adopted"` Adopted FlexBool `json:"adopted"`
SiteID string `json:"site_id"` SiteID string `json:"site_id"`
Cfgversion string `json:"cfgversion"` Cfgversion string `json:"cfgversion"`
SyslogKey string `json:"syslog_key"` SyslogKey string `json:"syslog_key"`
ConfigNetwork ConfigNetwork `json:"config_network"` ConfigNetwork *ConfigNetwork `json:"config_network"`
SetupID string `json:"setup_id"` SetupID string `json:"setup_id"`
LicenseState string `json:"license_state"` LicenseState string `json:"license_state"`
ConfigNetworkLan *ConfigNetworkLan `json:"config_network_lan"` ConfigNetworkLan *ConfigNetworkLan `json:"config_network_lan"`
@ -28,22 +28,22 @@ type UXG struct {
Architecture string `json:"architecture"` Architecture string `json:"architecture"`
BoardRev FlexInt `json:"board_rev"` BoardRev FlexInt `json:"board_rev"`
ManufacturerID FlexInt `json:"manufacturer_id"` ManufacturerID FlexInt `json:"manufacturer_id"`
Internet bool `json:"internet"` Internet FlexBool `json:"internet"`
ModelIncompatible bool `json:"model_incompatible"` ModelIncompatible FlexBool `json:"model_incompatible"`
EthernetTable []*EthernetTable `json:"ethernet_table"` EthernetTable []*EthernetTable `json:"ethernet_table"`
PortTable []*Port `json:"port_table"` PortTable []*Port `json:"port_table"`
EthernetOverrides []*EthernetOverrides `json:"ethernet_overrides"` EthernetOverrides []*EthernetOverrides `json:"ethernet_overrides"`
UsgCaps FlexInt `json:"usg_caps"` UsgCaps FlexInt `json:"usg_caps"`
HasSpeaker bool `json:"has_speaker"` HasSpeaker FlexBool `json:"has_speaker"`
HasEth1 bool `json:"has_eth1"` HasEth1 FlexBool `json:"has_eth1"`
FwCaps FlexInt `json:"fw_caps"` FwCaps FlexInt `json:"fw_caps"`
HwCaps FlexInt `json:"hw_caps"` HwCaps FlexInt `json:"hw_caps"`
WifiCaps FlexInt `json:"wifi_caps"` WifiCaps FlexInt `json:"wifi_caps"`
SwitchCaps *SwitchCaps `json:"switch_caps"` SwitchCaps *SwitchCaps `json:"switch_caps"`
HasFan bool `json:"has_fan"` HasFan FlexBool `json:"has_fan"`
HasTemperature bool `json:"has_temperature"` HasTemperature FlexBool `json:"has_temperature"`
Temperatures []*Temperature `json:"temperatures"` Temperatures []*Temperature `json:"temperatures"`
Storage []Storage `json:"storage"` Storage []*Storage `json:"storage"`
RulesetInterfaces interface{} `json:"ruleset_interfaces"` RulesetInterfaces interface{} `json:"ruleset_interfaces"`
ConnectedAt FlexInt `json:"connected_at"` ConnectedAt FlexInt `json:"connected_at"`
ProvisionedAt FlexInt `json:"provisioned_at"` ProvisionedAt FlexInt `json:"provisioned_at"`
@ -51,36 +51,36 @@ type UXG struct {
LedOverrideColor string `json:"led_override_color"` LedOverrideColor string `json:"led_override_color"`
LedOverrideColorBrightness FlexInt `json:"led_override_color_brightness"` LedOverrideColorBrightness FlexInt `json:"led_override_color_brightness"`
OutdoorModeOverride string `json:"outdoor_mode_override"` OutdoorModeOverride string `json:"outdoor_mode_override"`
LcmBrightnessOverride bool `json:"lcm_brightness_override"` LcmBrightnessOverride FlexBool `json:"lcm_brightness_override"`
LcmIdleTimeoutOverride bool `json:"lcm_idle_timeout_override"` LcmIdleTimeoutOverride FlexBool `json:"lcm_idle_timeout_override"`
Name string `json:"name"` Name string `json:"name"`
Unsupported bool `json:"unsupported"` Unsupported FlexBool `json:"unsupported"`
UnsupportedReason FlexInt `json:"unsupported_reason"` UnsupportedReason FlexInt `json:"unsupported_reason"`
Serial string `json:"serial"` Serial string `json:"serial"`
HashID string `json:"hash_id"` HashID string `json:"hash_id"`
TwoPhaseAdopt bool `json:"two_phase_adopt"` TwoPhaseAdopt FlexBool `json:"two_phase_adopt"`
DeviceID string `json:"device_id"` DeviceID string `json:"device_id"`
State FlexInt `json:"state"` State FlexInt `json:"state"`
StartDisconnectedMillis int64 `json:"start_disconnected_millis"` StartDisconnectedMillis FlexInt `json:"start_disconnected_millis"`
UpgradeState FlexInt `json:"upgrade_state"` UpgradeState FlexInt `json:"upgrade_state"`
StartConnectedMillis int64 `json:"start_connected_millis"` StartConnectedMillis FlexInt `json:"start_connected_millis"`
LastSeen FlexInt `json:"last_seen"` LastSeen FlexInt `json:"last_seen"`
Uptime FlexInt `json:"uptime"` Uptime FlexInt `json:"uptime"`
UnderscoreUptime FlexInt `json:"_uptime"` UnderscoreUptime FlexInt `json:"_uptime"`
Locating bool `json:"locating"` Locating FlexBool `json:"locating"`
SysStats *SysStats `json:"sys_stats"` SysStats *SysStats `json:"sys_stats"`
SystemStats *SystemStats `json:"system-stats"` SystemStats *SystemStats `json:"system-stats"`
GuestKicks FlexInt `json:"guest_kicks"` GuestKicks FlexInt `json:"guest_kicks"`
GuestToken string `json:"guest_token"` GuestToken string `json:"guest_token"`
UptimeStats map[string]*UptimeStats `json:"uptime_stats"` UptimeStats map[string]*UptimeStats `json:"uptime_stats"`
Overheating bool `json:"overheating"` Overheating FlexBool `json:"overheating"`
GeoInfo map[string]*GeoInfo `json:"geo_info"` GeoInfo map[string]*GeoInfo `json:"geo_info"`
LedState *LedState `json:"led_state"` LedState *LedState `json:"led_state"`
SpeedtestStatus *SpeedtestStatus `json:"speedtest-status"` SpeedtestStatus *SpeedtestStatus `json:"speedtest-status"`
SpeedtestStatusSaved bool `json:"speedtest-status-saved"` SpeedtestStatusSaved FlexBool `json:"speedtest-status-saved"`
Wan1 *Wan `json:"wan1"` Wan1 *Wan `json:"wan1"`
Wan2 *Wan `json:"wan2"` Wan2 *Wan `json:"wan2"`
Uplink Uplink `json:"uplink"` Uplink *Uplink `json:"uplink"`
DownlinkTable []*DownlinkTable `json:"downlink_table"` DownlinkTable []*DownlinkTable `json:"downlink_table"`
NetworkTable []*NetworkTable `json:"network_table"` NetworkTable []*NetworkTable `json:"network_table"`
KnownCfgversion string `json:"known_cfgversion"` KnownCfgversion string `json:"known_cfgversion"`
@ -91,8 +91,8 @@ type UXG struct {
ConsideredLostAt FlexInt `json:"considered_lost_at"` ConsideredLostAt FlexInt `json:"considered_lost_at"`
Stat *UXGStat `json:"stat"` Stat *UXGStat `json:"stat"`
TxBytes FlexInt `json:"tx_bytes"` TxBytes FlexInt `json:"tx_bytes"`
RxBytes int64 `json:"rx_bytes"` RxBytes FlexInt `json:"rx_bytes"`
Bytes int64 `json:"bytes"` Bytes FlexInt `json:"bytes"`
NumSta FlexInt `json:"num_sta"` NumSta FlexInt `json:"num_sta"`
WlanNumSta FlexInt `json:"wlan-num_sta"` WlanNumSta FlexInt `json:"wlan-num_sta"`
LanNumSta FlexInt `json:"lan-num_sta"` LanNumSta FlexInt `json:"lan-num_sta"`
@ -121,11 +121,13 @@ type DownlinkTable struct {
Mac string `json:"mac"` Mac string `json:"mac"`
} }
// LedState is incuded with newer devices.
type LedState struct { type LedState struct {
Pattern string `json:"pattern"` Pattern string `json:"pattern"`
Tempo FlexInt `json:"tempo"` Tempo FlexInt `json:"tempo"`
} }
// GeoInfo is incuded with certain devices.
type GeoInfo struct { type GeoInfo struct {
Accuracy FlexInt `json:"accuracy"` Accuracy FlexInt `json:"accuracy"`
Address string `json:"address"` Address string `json:"address"`
@ -141,14 +143,14 @@ type GeoInfo struct {
Timezone string `json:"timezone"` Timezone string `json:"timezone"`
} }
// UptimeStats is incuded with certain devices.
type UptimeStats struct { type UptimeStats struct {
Availability FlexInt `json:"availability"` Availability FlexInt `json:"availability"`
LatencyAverage FlexInt `json:"latency_average"` LatencyAverage FlexInt `json:"latency_average"`
TimePeriod FlexInt `json:"time_period"` TimePeriod FlexInt `json:"time_period"`
} }
// UDMStat holds the "stat" data for a dream machine. // UXGStat holds the "stat" data for a 10Gb gateway.
// A dream machine is a USG + USW + Controller.
type UXGStat struct { type UXGStat struct {
*Gw `json:"gw"` *Gw `json:"gw"`
*Sw `json:"sw"` *Sw `json:"sw"`