Skip to content
Open
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
58 changes: 58 additions & 0 deletions internal/dashboard/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,64 @@ func TestSortItems_ByProvider(t *testing.T) {
}
}

func TestSortItems_ByDisplayLabel(t *testing.T) {
items := []pages.ProxyViewItem{
{Name: "stack-wizarr-1", Category: "NicFlix", Data: pages.ProxyData{Label: "Wizarr", TargetProvider: "local"}},
{Name: "plex", Category: "NicFlix", Data: pages.ProxyData{Label: "Plex", TargetProvider: "external"}},
{Name: "stack-portainer-1", Category: "NicFlix", Data: pages.ProxyData{Label: "Portainer"}},
{Name: "sync", Category: "NicFlix", Data: pages.ProxyData{Label: "Sync"}},
}
sortItems(items, "name", nil)
if items[0].Name != "plex" || items[1].Name != "stack-portainer-1" || items[2].Name != "sync" || items[3].Name != "stack-wizarr-1" {
t.Fatalf("expected Plex, Portainer, Sync, Wizarr, got %v", names(items))
}

groups := groupItems(items)
if len(groups) != 1 || groups[0].Name != "NicFlix" {
t.Fatalf("expected one NicFlix group, got %v", groupNames(groups))
}
got := names(groups[0].Items)
if got[0] != "plex" || got[1] != "stack-portainer-1" || got[2] != "sync" || got[3] != "stack-wizarr-1" {
t.Fatalf("expected NicFlix label order, got %v", got)
}
}

func TestSortItems_ByDisplayLabelCase(t *testing.T) {
items := []pages.ProxyViewItem{
{Name: "z-tautulli", Data: pages.ProxyData{Label: "tautulli"}},
{Name: "a-plex", Data: pages.ProxyData{Label: "Plex"}},
{Name: "m-tsdproxy", Data: pages.ProxyData{Label: "TSDProxy"}},
{Name: "b-portainer", Data: pages.ProxyData{Label: "portainer"}},
}
sortItems(items, "name", nil)
if items[0].Data.Label != "Plex" || items[1].Data.Label != "portainer" || items[2].Data.Label != "tautulli" || items[3].Data.Label != "TSDProxy" {
t.Fatalf("expected Plex, portainer, tautulli, TSDProxy, got %s %s %s %s",
items[0].Data.Label, items[1].Data.Label, items[2].Data.Label, items[3].Data.Label)
}
}

func TestSortItems_LabelTieBreakByName(t *testing.T) {
items := []pages.ProxyViewItem{
{Name: "b", Data: pages.ProxyData{Label: "App"}},
{Name: "a", Data: pages.ProxyData{Label: "App"}},
}
sortItems(items, "name", nil)
if items[0].Name != "a" || items[1].Name != "b" {
t.Fatalf("expected a,b, got %v", names(items))
}
}

func TestSortItems_PinnedDisplayLabelLast(t *testing.T) {
items := []pages.ProxyViewItem{
{Name: "a", Data: pages.ProxyData{Label: "Alpha"}},
{Name: "z", Data: pages.ProxyData{Label: "Zulu"}},
}
sortItems(items, "name", map[string]bool{"z": true})
if items[0].Name != "z" || items[1].Name != "a" {
t.Fatalf("expected pinned z first, got %v", names(items))
}
}

func names(items []pages.ProxyViewItem) []string {
out := make([]string, len(items))
for i, it := range items {
Expand Down
12 changes: 12 additions & 0 deletions internal/dashboard/viewmodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,23 @@ func sortItems(items []pages.ProxyViewItem, sortKey string, pinned map[string]bo
}
return items[i].Name < items[j].Name
default:
iLabel := strings.ToLower(displayLabel(items[i]))
jLabel := strings.ToLower(displayLabel(items[j]))
if iLabel != jLabel {
return iLabel < jLabel
}
return items[i].Name < items[j].Name
}
})
}

func displayLabel(item pages.ProxyViewItem) string {
if item.Data.Label != "" {
return item.Data.Label
}
return item.Name
}

func groupItems(items []pages.ProxyViewItem) []pages.DashboardGroup {
groups := make(map[string][]pages.ProxyViewItem)
order := make([]string, 0)
Expand Down
8 changes: 6 additions & 2 deletions internal/proxyproviders/tailscale/service_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ func TestServiceProxy_GetURL_MustNotBlockDuringStart(t *testing.T) {
}

close(mock.blockCh)
<-startDone
if err := <-startDone; err != nil {
t.Fatalf("unexpected error: %v", err)
}
}

func TestServiceProxy_GetListener_MustNotBlockDuringStart(t *testing.T) {
Expand Down Expand Up @@ -359,7 +361,9 @@ func TestServiceProxy_GetListener_MustNotBlockDuringStart(t *testing.T) {
}

close(mock.blockCh)
<-startDone
if err := <-startDone; err != nil {
t.Fatalf("unexpected error: %v", err)
}
}

func waitFor(t *testing.T, cond func() bool, msg string) {
Expand Down
4 changes: 2 additions & 2 deletions internal/targetproviders/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ func TestSignalDisconnect_CancelledContext(t *testing.T) {
c.signalDisconnect(ctx, errChan)

select {
case <-errChan:
t.Fatal("should not send error when context is canceled")
case err := <-errChan:
t.Fatalf("should not send error when context is canceled: %v", err)
default:
}
}
Expand Down
Loading