Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes ubb and uci fakes, adds test to check this in the future #140

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (u *Unifi) unmarshalDevice(dev string, data json.RawMessage, v interface{})

json, err := data.MarshalJSON()
u.DebugLog("Failed Payload: %s (marshal err: %v)", json, err)
u.DebugLog("The above payload can prove useful during torubleshooting when you open an Issue:")
u.DebugLog("The above payload can prove useful during troubleshooting when you open an Issue:")
u.DebugLog("==- https://github.com/unifi-poller/unifi/issues/new -==")
}

Expand Down
22 changes: 22 additions & 0 deletions devices_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package unifi_test

import (
"github.com/brianvoe/gofakeit/v6"
"github.com/stretchr/testify/require"
"github.com/unpoller/unifi/v5"
"testing"
)

func TestDevices(test *testing.T) {
d := unifi.Devices{}
err := gofakeit.Struct(&d)
require.NoError(test, err)
require.NotEmpty(test, d.UBBs)
require.NotEmpty(test, d.UCIs)
require.NotEmpty(test, d.PDUs)
require.NotEmpty(test, d.UAPs)
require.NotEmpty(test, d.USGs)
require.NotEmpty(test, d.UDMs)
require.NotEmpty(test, d.UXGs)
require.NotEmpty(test, d.USWs)
}
21 changes: 21 additions & 0 deletions mocks/mock_client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package mocks_test

import (
"github.com/stretchr/testify/require"
"github.com/unpoller/unifi/v5/mocks"
"testing"
)

func TestMockUnifiClient(t *testing.T) {
m := mocks.NewMockUnifi()
devices, err := m.GetDevices(nil)
require.NoError(t, err)
require.NotEmpty(t, devices.UAPs)
require.NotEmpty(t, devices.USGs)
require.NotEmpty(t, devices.UDMs)
require.NotEmpty(t, devices.USWs)
require.NotEmpty(t, devices.PDUs)
require.NotEmpty(t, devices.UCIs)
require.NotEmpty(t, devices.UXGs)
require.NotEmpty(t, devices.UBBs)
}
268 changes: 139 additions & 129 deletions ubb.go

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions ubb_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package unifi_test

import (
"github.com/brianvoe/gofakeit/v6"
"github.com/stretchr/testify/require"
"github.com/unpoller/unifi/v5"
"testing"
)

func TestUBB(test *testing.T) {
ubb := unifi.UBB{}
err := gofakeit.Struct(&ubb)
require.NoError(test, err)
require.NotEmpty(test, ubb.Name)
}
164 changes: 82 additions & 82 deletions uci.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,86 +34,86 @@ type CIStateTable struct {
}

type UCI struct {
SiteName string `json:"-"`
SourceName string `json:"-"`
site *Site
RequiredVersion string `json:"required_version"`
PortTable []*Port `json:"port_table"`
LicenseState string `json:"license_state"`
TwoPhaseAdopt FlexBool `json:"two_phase_adopt"`
ConnectedAt FlexInt `json:"connected_at"`
Type string `json:"type"`
InformIP string `json:"inform_ip"`
CfgVersion string `json:"cfgversion"`
BoardRev FlexInt `json:"board_rev"`
Mac string `json:"mac"`
SetupID string `json:"setup_id"`
ProvisionedAt FlexInt `json:"provisioned_at"`
HwCaps FlexInt `json:"hw_caps"`
InformURL string `json:"inform_url"`
RebootDuration FlexInt `json:"reboot_duration"`
UpgradeDuration FlexInt `json:"upgrade_duration"`
EthernetTable []*EthernetTable `json:"ethernet_table"`
ConfigNetwork *ConfigNetwork `json:"config_network"`
Unsupported FlexBool `json:"unsupported"`
BleCaps FlexInt `json:"ble_caps"`
SysErrorCaps FlexInt `json:"sys_error_caps"`
SyslogKey string `json:"syslog_key"`
Model string `json:"model"`
DisconnectedAt FlexInt `json:"disconnected_at"`
Architecture string `json:"architecture"`
ManufacturerID FlexInt `json:"manufacturer_id"`
ModelIncompatible FlexBool `json:"model_incompatible"`
IP string `json:"ip"`
ModelInEol FlexBool `json:"model_in_eol"`
Version string `json:"version"`
AdoptionCompleted FlexBool `json:"adoption_completed"`
UnsupportedReason FlexInt `json:"unsupported_reason"`
CiStateTable *CIStateTable `json:"ci_state_table"`
AnonID string `json:"anon_id"`
AdoptedByClient string `json:"adopted_by_client"`
ModelInLts FlexBool `json:"model_in_lts"`
KernelVersion string `json:"kernel_version"`
Serial string `json:"serial"`
SiteID string `json:"site_id"`
AdoptedAt FlexInt `json:"adopted_at"`
FwCaps FlexInt `json:"fw_caps"`
ID string `json:"_id"`
Adopted FlexBool `json:"adopted"`
Internet FlexBool `json:"internet"`
HashID string `json:"hash_id"`
DeviceID string `json:"device_id"`
State FlexInt `json:"state"`
StartDisconnectedMillis FlexInt `json:"start_disconnected_millis"`
UciConnectTo string `json:"uci_connect_to"`
WanPort string `json:"wan_port"`
WanNetworkGroup string `json:"wan_networkgroup"`
IspName string `json:"isp_name"`
LastSeen FlexInt `json:"last_seen"`
MinInformIntervalSeconds FlexInt `json:"min_inform_interval_seconds"`
Upgradable FlexBool `json:"upgradable"`
AdoptableWhenUpgraded FlexBool `json:"adoptable_when_upgraded"`
RollUpgrade FlexBool `json:"rollupgrade"`
KnownCfgVersion string `json:"known_cfgversion"`
Uptime FlexInt `json:"uptime"`
Uptime0 FlexInt `json:"_uptime"`
Locating FlexBool `json:"locating"`
StartConnectedMillis FlexInt `json:"start_connected_millis"`
NextInterval FlexInt `json:"next_interval"`
SysStats *SysStats `json:"sys_stats"`
SystemStats *SystemStats `json:"system_stats"`
LLDPTable []*LLDPTable `json:"lldp_table"`
DisplayableVersion string `json:"displayable_version"`
StartupTimestamp FlexInt `json:"startup_timestamp"`
IsAccessPoint FlexBool `json:"is_access_point"`
SafeForAutoUpgrade FlexBool `json:"safe_for_autoupgrade"`
DownlinkTable []*DownlinkTable `json:"downlink_table"`
PrevNonBusyState FlexInt `json:"prev_non_busy_state"`
Name string `json:"name"`
LcmBrightness FlexInt `json:"lcm_brightness"`
Stat *UCIStat `json:"stat"`
TxBytes FlexInt `json:"tx_bytes"`
RxBytes FlexInt `json:"rx_bytes"`
Bytes FlexInt `json:"bytes"`
NumSta FlexInt `json:"num_sta"`
AdoptableWhenUpgraded FlexBool `json:"adoptable_when_upgraded"`
Adopted FlexBool `json:"adopted"`
AdoptedAt FlexInt `json:"adopted_at"`
AdoptedByClient string `json:"adopted_by_client"`
AdoptionCompleted FlexBool `json:"adoption_completed"`
AnonID string `json:"anon_id"`
Architecture string `json:"architecture"`
BleCaps FlexInt `json:"ble_caps"`
BoardRev FlexInt `json:"board_rev"`
Bytes FlexInt `json:"bytes"`
CfgVersion string `json:"cfgversion"`
CiStateTable *CIStateTable `json:"ci_state_table"`
ConfigNetwork *ConfigNetwork `json:"config_network"`
ConnectedAt FlexInt `json:"connected_at"`
DeviceID string `json:"device_id"`
DisconnectedAt FlexInt `json:"disconnected_at"`
DisplayableVersion string `json:"displayable_version"`
DownlinkTable []DownlinkTable `fakesize:"1" json:"downlink_table"`
EthernetTable []EthernetTable `fakesize:"1" json:"ethernet_table"`
FwCaps FlexInt `json:"fw_caps"`
HashID string `json:"hash_id"`
HwCaps FlexInt `json:"hw_caps"`
ID string `json:"_id"`
IP string `json:"ip"`
InformIP string `json:"inform_ip"`
InformURL string `json:"inform_url"`
Internet FlexBool `json:"internet"`
IsAccessPoint FlexBool `json:"is_access_point"`
IspName string `json:"isp_name"`
KernelVersion string `json:"kernel_version"`
KnownCfgVersion string `json:"known_cfgversion"`
LLDPTable []LLDPTable `fakesize:"1" json:"lldp_table"`
LastSeen FlexInt `json:"last_seen"`
LcmBrightness FlexInt `json:"lcm_brightness"`
LicenseState string `json:"license_state"`
Locating FlexBool `json:"locating"`
Mac string `json:"mac"`
ManufacturerID FlexInt `json:"manufacturer_id"`
MinInformIntervalSeconds FlexInt `json:"min_inform_interval_seconds"`
Model string `json:"model"`
ModelInEol FlexBool `json:"model_in_eol"`
ModelInLts FlexBool `json:"model_in_lts"`
ModelIncompatible FlexBool `json:"model_incompatible"`
Name string `json:"name"`
NextInterval FlexInt `json:"next_interval"`
NumSta FlexInt `json:"num_sta"`
PortTable []Port `fakesize:"1" json:"port_table"`
PrevNonBusyState FlexInt `json:"prev_non_busy_state"`
ProvisionedAt FlexInt `json:"provisioned_at"`
RebootDuration FlexInt `json:"reboot_duration"`
RequiredVersion string `json:"required_version"`
RollUpgrade FlexBool `json:"rollupgrade"`
RxBytes FlexInt `json:"rx_bytes"`
SafeForAutoUpgrade FlexBool `json:"safe_for_autoupgrade"`
Serial string `json:"serial"`
SetupID string `json:"setup_id"`
SiteID string `fake:"{uuid}" json:"site_id"`
SiteName string `fake:"{company}" json:"site_name"`
SourceName string `fake:"{animal}" json:"source_name"`
StartConnectedMillis FlexInt `json:"start_connected_millis"`
StartDisconnectedMillis FlexInt `json:"start_disconnected_millis"`
StartupTimestamp FlexInt `json:"startup_timestamp"`
Stat *UCIStat `json:"stat"`
State FlexInt `json:"state"`
SysErrorCaps FlexInt `json:"sys_error_caps"`
SysStats *SysStats `json:"sys_stats"`
SyslogKey string `json:"syslog_key"`
SystemStats *SystemStats `json:"system_stats"`
TwoPhaseAdopt FlexBool `json:"two_phase_adopt"`
TxBytes FlexInt `json:"tx_bytes"`
Type string `fake:"{lexify:uci}" json:"type"`
UciConnectTo string `json:"uci_connect_to"`
Unsupported FlexBool `json:"unsupported"`
UnsupportedReason FlexInt `json:"unsupported_reason"`
Upgradable FlexBool `json:"upgradable"`
UpgradeDuration FlexInt `json:"upgrade_duration"`
Uptime FlexInt `json:"uptime"`
Uptime0 FlexInt `json:"_uptime"`
Version string `json:"version"`
WanNetworkGroup string `json:"wan_networkgroup"`
WanPort string `json:"wan_port"`
site *Site `fake:"-"`
}
15 changes: 15 additions & 0 deletions uci_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package unifi_test

import (
"github.com/brianvoe/gofakeit/v6"
"github.com/stretchr/testify/require"
"github.com/unpoller/unifi/v5"
"testing"
)

func TestUCI(test *testing.T) {
uci := unifi.UCI{}
err := gofakeit.Struct(&uci)
require.NoError(test, err)
require.NotEmpty(test, uci.Name)
}
Loading