Skip to content

Commit 314b14f

Browse files
b0bbywanclaude
andcommitted
test: cover api.ui.admin and the header admin link
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015M9wLCvRaA5jj8cCZN6wFg
1 parent 15cf492 commit 314b14f

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

config/config_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,36 @@ func TestNew_UIConfig(t *testing.T) {
111111
}
112112
}
113113

114+
func TestNew_UIAdmin(t *testing.T) {
115+
tests := []struct {
116+
name string
117+
set any
118+
admin string
119+
}{
120+
{"unset by default", nil, ""},
121+
{"port-only form", ":8021", ":8021"},
122+
{"full URL", "https://admin.example.com", "https://admin.example.com"},
123+
}
124+
125+
for _, tt := range tests {
126+
t.Run(tt.name, func(t *testing.T) {
127+
viper.Reset()
128+
if tt.set != nil {
129+
viper.Set("api.ui.admin", tt.set)
130+
}
131+
t.Setenv("HOME", t.TempDir())
132+
133+
cfg, err := New(nil)
134+
if err != nil {
135+
t.Fatalf("New(nil) returned error: %v", err)
136+
}
137+
if cfg.Api.UI.Admin != tt.admin {
138+
t.Errorf("Api.UI.Admin = %q, want %q", cfg.Api.UI.Admin, tt.admin)
139+
}
140+
})
141+
}
142+
}
143+
114144
func TestNew_UIEnabledByDefault(t *testing.T) {
115145
viper.Reset()
116146
t.Setenv("HOME", t.TempDir())

ui/handler_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,44 @@ func TestSystemdUnitTemplate_URLLink(t *testing.T) {
801801
}
802802
}
803803

804+
func TestDashboardTemplate_AdminLink(t *testing.T) {
805+
tmpl := LoadTemplates()
806+
807+
tests := []struct {
808+
name string
809+
admin string
810+
wantSub string
811+
denySub string
812+
}{
813+
{
814+
name: "admin set renders link",
815+
admin: ":8021",
816+
wantSub: `onclick="openServiceUrl(':8021'); return false;"`,
817+
},
818+
{
819+
name: "admin unset renders no link",
820+
denySub: "openServiceUrl",
821+
},
822+
}
823+
824+
for _, tt := range tests {
825+
t.Run(tt.name, func(t *testing.T) {
826+
var buf bytes.Buffer
827+
view := DashboardView{Title: "Odio", ServerInfo: &ServerInfo{}, Admin: tt.admin}
828+
if err := tmpl.ExecuteTemplate(&buf, "dashboard", view); err != nil {
829+
t.Fatalf("ExecuteTemplate: %v", err)
830+
}
831+
out := buf.String()
832+
if tt.wantSub != "" && !strings.Contains(out, tt.wantSub) {
833+
t.Errorf("expected %q in output, got:\n%s", tt.wantSub, out)
834+
}
835+
if tt.denySub != "" && strings.Contains(out, tt.denySub) {
836+
t.Errorf("did not expect %q in output, got:\n%s", tt.denySub, out)
837+
}
838+
})
839+
}
840+
}
841+
804842
// TestConvertServices verifies service conversion logic
805843
func TestConvertServices(t *testing.T) {
806844
tests := []struct {

0 commit comments

Comments
 (0)