Skip to content

Commit

Permalink
Merge pull request #114 from unpoller/faker-fix-for-temps
Browse files Browse the repository at this point in the history
Faker Fixes + Dependabot
  • Loading branch information
platinummonkey committed Apr 3, 2024
2 parents 7496eff + d4587ba commit 07338b4
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 158 deletions.
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ updates:
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
test:
strategy:
matrix:
go: ["1.21"]
go: ["stable"]
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -33,7 +33,7 @@ jobs:
lint:
strategy:
matrix:
go: ["1.21"]
go: ["stable"]
os: [ubuntu-latest]
name: lint
runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- run: git fetch --force --tags
- uses: actions/setup-go@v5
with:
go-version: '>=1.21.0'
go-version: 'stable'
cache: true
- uses: goreleaser/goreleaser-action@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type Client struct {
LastSeenByUSW FlexInt `json:"_last_seen_by_usw"`
LatestAssocTime FlexInt `json:"latest_assoc_time"`
Mac string `fake:"{macaddress}" json:"mac"`
Name string `json:"name"`
Name string `fake:"{randomstring:[client-1,client-2,client-3]}" json:"name"`
Network string `json:"network"`
NetworkID string `fake:"{uuid}" json:"network_id"`
Noise FlexInt `json:"noise"`
Expand Down
64 changes: 32 additions & 32 deletions pdu.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ type PDU struct {
Mac string `fake:"{macaddress}" json:"mac"`
ManufacturerID FlexInt `json:"manufacturer_id"`
MinIfnromIntervalSeconds FlexInt `json:"min_inform_interval_seconds"`
Model string `json:"model"`
Model string `fake:"{randomstring:[model-1,model-2,model-3]}" json:"model"`
ModelIncompatible FlexBool `json:"model_incompatible"`
ModelInEOL FlexBool `json:"model_in_eol"`
ModelInLTS FlexBool `json:"model_in_lts"`
Name string `json:"name"`
Name string `fake:"{randomstring:[pdu-1,pdu-2]}" json:"name"`
NextInterval FlexInt `json:"next_interval"`
NumSta FlexInt `json:"num_sta"`
OutletACPowerBudget FlexInt `json:"outlet_ac_power_budget"`
Expand All @@ -76,51 +76,51 @@ type PDU struct {
RollUpgrade FlexBool `json:"rollupgrade"`
RxBytes FlexInt `json:"rx_bytes"`
Satisfaction FlexInt `json:"satisfaction"`
Serial string `json:"serial"`
Serial string `fake:"{uuid}" json:"serial"`
SetupID string `fake:"{uuid}" json:"setup_id"`
site *Site
SiteID string `fake:"{uuid}" json:"site_id"`
SiteName string `json:"site_name"`
SourceName string `json:"source_name"`
StartConnectedMillis FlexInt `json:"start_connected_millis"`
StartDisconnectedMillis FlexInt `json:"start_disconnected_millis"`
StartupTimestamp FlexInt `json:"startup_timestamp"`
Stat PDUStat `json:"stat"`
State FlexInt `json:"state"`
StpPriority FlexInt `json:"stp_priority"`
StpVersion string `fake:"{appversion}" json:"stp_version"`
SwitchCaps *SwitchCaps `json:"switch_caps"`
SysErrorCaps FlexInt `json:"sys_error_caps"`
SyslogKey string `json:"syslog_key"`
SysStats SysStats `json:"sys_stats"`
SystemStats SystemStats `json:"system-stats"`
TotalMaxPower FlexInt `json:"total_max_power"`
TwoPhaseAdopt FlexBool `json:"two_phase_adopt"`
TxBytes FlexInt `json:"tx_bytes"`
Type string `fake:"{lexify:pdu}" json:"type"`
Unsupported FlexBool `json:"unsupported"`
UnsupportedReason FlexInt `json:"unsupported_reason"`
Upgradeable FlexBool `json:"upgradable"`
Uplink Uplink `json:"uplink"`
UplinkDepth FlexBool `json:"uplink_depth"`
Uptime FlexInt `json:"uptime"`
UserNumSta FlexInt `json:"user-num_sta"`
Version string `fake:"{appversion}" json:"version"`
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 PDUStat `json:"stat"`
State FlexInt `json:"state"`
StpPriority FlexInt `json:"stp_priority"`
StpVersion string `fake:"{appversion}" json:"stp_version"`
SwitchCaps *SwitchCaps `json:"switch_caps"`
SysErrorCaps FlexInt `json:"sys_error_caps"`
SyslogKey string `fake:"{animal}" json:"syslog_key"`
SysStats SysStats `json:"sys_stats"`
SystemStats SystemStats `json:"system-stats"`
TotalMaxPower FlexInt `json:"total_max_power"`
TwoPhaseAdopt FlexBool `json:"two_phase_adopt"`
TxBytes FlexInt `json:"tx_bytes"`
Type string `fake:"{lexify:pdu}" json:"type"`
Unsupported FlexBool `json:"unsupported"`
UnsupportedReason FlexInt `json:"unsupported_reason"`
Upgradeable FlexBool `json:"upgradable"`
Uplink Uplink `json:"uplink"`
UplinkDepth FlexBool `json:"uplink_depth"`
Uptime FlexInt `json:"uptime"`
UserNumSta FlexInt `json:"user-num_sta"`
Version string `fake:"{appversion}" json:"version"`
}

// OutletOverride hold the PDU outlet override data.
type OutletOverride struct {
CycleEnabled FlexBool `json:"cycle_enabled"`
Index FlexInt `json:"index"`
Name string `json:"name"`
Name string `fake:"{randomstring:[override-1,override-2]}" json:"name"`
RelayState FlexBool `json:"relay_state"`
}

// OutletTable hold the PDU outlet data.
type OutletTable struct {
CycleEnabled FlexBool `json:"cycle_enabled"`
Index FlexInt `json:"index"`
Name string `json:"name"`
Name string `fake:"{randomstring:[table-1,table-2,table-3]]" json:"name"`
OutletCaps FlexInt `json:"outlet_caps"`
OutletCurrent FlexInt `json:"outlet_current"`
OutletPower FlexInt `json:"outlet_power"`
Expand Down
2 changes: 1 addition & 1 deletion site.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ type Site struct {
XputUp FlexInt `json:"xput_up,omitempty"`
} `fakesize:"5" json:"health"`
ID string `fake:"{uuid}" json:"_id"`
Name string `fake:"{company}" json:"name"`
Name string `fake:"{randomstring:[site-1,site-2]}" json:"name"`
NumNewAlarms FlexInt `json:"num_new_alarms"`
SiteName string `json:"-"`
SourceName string `json:"-"`
Expand Down
16 changes: 16 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ func init() {
return *NewFlexBool(l), nil
},
})

gofakeit.AddFuncLookup("tempStatusByName", gofakeit.Info{
Category: "custom",
Description: "Configured TempStatusByName",
Example: "TempStatusByName{...}",
Output: "TempStatusByName",
Generate: func(r *rand.Rand, m *gofakeit.MapParams, info *gofakeit.Info) (interface{}, error) {
return TempStatusByName{
"cpu": NewFlexTemp(float64(r.Int31n(100))),
"sys": NewFlexTemp(float64(r.Int31n(100))),
"probe": NewFlexTemp(float64(r.Int31n(100))),
"memory": NewFlexTemp(float64(r.Int31n(100))),
"network": NewFlexTemp(float64(r.Int31n(100))),
}, nil
},
})
}

var ErrCannotUnmarshalFlexInt = fmt.Errorf("cannot unmarshal to FlexInt")
Expand Down
2 changes: 1 addition & 1 deletion uap.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type UAP struct {
ModelInEOL FlexBool `json:"model_in_eol"`
ModelInLTS FlexBool `json:"model_in_lts"`
ModelIncompatible FlexBool `json:"model_incompatible"`
Name string `json:"name"`
Name string `fake:"{randomstring:[uap-1,uap-2]}" json:"name"`
NumSta FlexInt `json:"num_sta"`
OutdoorModeOverride string `json:"outdoor_mode_override"`
PortTable []Port `fakesize:"5" json:"port_table"`
Expand Down
58 changes: 23 additions & 35 deletions usg.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package unifi
import (
"encoding/json"
"time"

"github.com/brianvoe/gofakeit/v6"
)

// USG represents all the data from the Ubiquiti Controller for a Unifi Security Gateway.
Expand Down Expand Up @@ -48,28 +46,28 @@ type USG struct {
RxBytes FlexInt `json:"rx_bytes"`
Serial string `json:"serial"`
site *Site
SiteID string `fake:"{uuid}" json:"site_id"`
SiteName string `json:"-"`
SourceName string `json:"-"`
SpeedtestStatus SpeedtestStatus `json:"speedtest-status"`
SpeedtestStatusSaved FlexBool `json:"speedtest-status-saved"`
Stat USGStat `json:"stat"`
State FlexInt `json:"state"`
SysStats SysStats `json:"sys_stats"`
SystemStats SystemStats `json:"system-stats"`
Temperatures []Temperature `fakesize:"5" json:"temperatures,omitempty"`
TxBytes FlexInt `json:"tx_bytes"`
Type string `fake:"{lexify:usg}" json:"type"`
Unsupported FlexBool `json:"unsupported"`
UnsupportedReason FlexInt `json:"unsupported_reason"`
Upgradable FlexBool `json:"upgradable"`
Uplink Uplink `json:"uplink"`
Uptime FlexInt `json:"uptime"`
UserNumSta FlexInt `json:"user-num_sta"`
UsgCaps FlexInt `json:"usg_caps"`
Version string `fake:"{appversion}" json:"version"`
Wan1 Wan `json:"wan1"`
Wan2 Wan `json:"wan2"`
SiteID string `fake:"{uuid}" json:"site_id"`
SiteName string `json:"-"`
SourceName string `json:"-"`
SpeedtestStatus SpeedtestStatus `json:"speedtest-status"`
SpeedtestStatusSaved FlexBool `json:"speedtest-status-saved"`
Stat USGStat `json:"stat"`
State FlexInt `json:"state"`
SysStats SysStats `json:"sys_stats"`
SystemStats SystemStats `json:"system-stats"`
Temperatures []Temperature `fakesize:"5" json:"temperatures,omitempty"`
TxBytes FlexInt `json:"tx_bytes"`
Type string `fake:"{lexify:usg}" json:"type"`
Unsupported FlexBool `json:"unsupported"`
UnsupportedReason FlexInt `json:"unsupported_reason"`
Upgradable FlexBool `json:"upgradable"`
Uplink Uplink `json:"uplink"`
Uptime FlexInt `json:"uptime"`
UserNumSta FlexInt `json:"user-num_sta"`
UsgCaps FlexInt `json:"usg_caps"`
Version string `fake:"{appversion}" json:"version"`
Wan1 Wan `json:"wan1"`
Wan2 Wan `json:"wan2"`
}

// Uplink is the Internet connection (or uplink) on a UniFi device.
Expand Down Expand Up @@ -184,24 +182,14 @@ type SpeedtestServer struct {

type TempStatusByName map[string]*FlexTemp

func (t TempStatusByName) Fake(faker *gofakeit.Faker) interface{} {
return TempStatusByName{
"cpu": NewFlexTemp(float64(faker.Rand.Int63n(100))),
"sys": NewFlexTemp(float64(faker.Rand.Int63n(100))),
"probe": NewFlexTemp(float64(faker.Rand.Int63n(100))),
"memory": NewFlexTemp(float64(faker.Rand.Int63n(100))),
"network": NewFlexTemp(float64(faker.Rand.Int63n(100))),
}
}

// SystemStats is system info for a UDM, USG, USW.
type SystemStats struct {
CPU FlexInt `json:"cpu"`
Mem FlexInt `json:"mem"`
Uptime FlexInt `json:"uptime"`
// This exists on at least USG4, may others, maybe not.
// {"Board (CPU)":"51 C","Board (PHY)":"51 C","CPU":"72 C","PHY":"77 C"}
Temps TempStatusByName `json:"temps,omitempty"`
Temps TempStatusByName `fake:"{tempStatusByName}" json:"temps,omitempty"`
}

// SysStats is load info for a UDM, USG, USW.
Expand Down
4 changes: 2 additions & 2 deletions usw.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ type USW struct {
ModelInEOL FlexBool `json:"model_in_eol"`
ModelInLTS FlexBool `json:"model_in_lts"`
ModelIncompatible FlexBool `json:"model_incompatible"`
Name string `json:"name"`
Name string `fake:"{animal}" json:"name"`
NextInterval FlexInt `json:"next_interval"`
NumSta FlexInt `json:"num_sta"`
OutdoorModeOverride string `json:"outdoor_mode_override"`
Overheating FlexBool `json:"overheating"`
PortOverrides []struct {
Name string `json:"name,omitempty"`
Name string `fake:"{randomstring:[override-1,override-2]}" json:"name,omitempty"`
PoeMode string `json:"poe_mode,omitempty"`
PortIdx FlexInt `json:"port_idx"`
PortconfID string `json:"portconf_id"`
Expand Down
Loading

0 comments on commit 07338b4

Please sign in to comment.