fix: use external test package for remote site helpers

golangci-lint testpackage requires tests in inputunifi_test.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Cody Lee
2026-08-31 14:01:11 -04:00
co-authored by Cursor
parent e4c2934bdc
commit 8a78355e12
2 changed files with 11 additions and 9 deletions
+6 -6
View File
@@ -177,7 +177,7 @@ func (u *InputUnifi) discoverRemoteControllers(apiKey string) ([]*Controller, er
// checkSites / getFilteredSites match against legacy Site.Name, which is
// RemoteSite.InternalReference, not the display Name. See unpoller/unpoller#986.
siteNames := remoteSitePollNames(sites)
siteNames := RemoteSitePollNames(sites)
// For Cloud Gateways, if the only site is "default", use the console name from hosts response
// as the default site name override. The console name is in reportedState.name
@@ -204,16 +204,16 @@ func (u *InputUnifi) discoverRemoteControllers(apiKey string) ([]*Controller, er
controller.ID = console.ID
controllers = append(controllers, controller)
u.Logf("Discovered console %s with %d site(s): %v", consoleName, len(sites), formatRemoteSites(sites))
u.Logf("Discovered console %s with %d site(s): %v", consoleName, len(sites), FormatRemoteSites(sites))
}
return controllers, nil
}
// remoteSitePollNames returns the legacy site identifiers used by checkSites
// RemoteSitePollNames returns the legacy site identifiers used by checkSites
// and getFilteredSites. Prefer InternalReference (OpenAPI Site overview);
// fall back to Name when the field is missing (older firmware).
func remoteSitePollNames(sites []unifi.RemoteSite) []string {
func RemoteSitePollNames(sites []unifi.RemoteSite) []string {
names := make([]string, 0, len(sites))
for _, site := range sites {
@@ -230,8 +230,8 @@ func remoteSitePollNames(sites []unifi.RemoteSite) []string {
return names
}
// formatRemoteSites logs display name plus legacy id when they differ.
func formatRemoteSites(sites []unifi.RemoteSite) []string {
// FormatRemoteSites logs display name plus legacy id when they differ.
func FormatRemoteSites(sites []unifi.RemoteSite) []string {
out := make([]string, 0, len(sites))
for _, site := range sites {
+5 -3
View File
@@ -1,10 +1,11 @@
package inputunifi
package inputunifi_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/unpoller/unifi/v6"
"github.com/unpoller/unpoller/pkg/inputunifi"
)
func TestRemoteSitePollNames(t *testing.T) {
@@ -48,7 +49,8 @@ func TestRemoteSitePollNames(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
assert.Equal(t, tt.want, remoteSitePollNames(tt.sites))
assert.Equal(t, tt.want, inputunifi.RemoteSitePollNames(tt.sites))
})
}
}
@@ -68,5 +70,5 @@ func TestFormatRemoteSites(t *testing.T) {
"Office (abc1def2)",
"only-id",
"legacy-name-only",
}, formatRemoteSites(sites))
}, inputunifi.FormatRemoteSites(sites))
}