Files
web_hgtv_server/app/service/appser/cache_test.go
T
rootandClaude Opus 5.5 7974a42301 Initial commit
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-23 11:07:42 +08:00

53 lines
1.1 KiB
Go

package appser
import (
"strings"
"testing"
"videoweb/pub/pubdef"
)
func TestAppendChannelCode(t *testing.T) {
t.Parallel()
tests := []struct {
name string
rawURL string
channelCode string
wantContain string
wantSkip bool
}{
{
name: "append custom channel",
rawURL: "https://example.com/app",
channelCode: "custom",
wantContain: "dc=custom",
},
{
name: "fallback default channel",
rawURL: "https://example.com/app",
channelCode: "",
wantContain: "dc=" + pubdef.DefaultChannelCode,
},
{
name: "skip existing dc",
rawURL: "https://example.com/app?dc=exists",
channelCode: "custom",
wantContain: "dc=exists",
wantSkip: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := appendChannelCode(tt.rawURL, tt.channelCode)
if !strings.Contains(got, tt.wantContain) {
t.Fatalf("appendChannelCode() = %q, want contain %q", got, tt.wantContain)
}
if tt.wantSkip && strings.Contains(got, "dc=custom") {
t.Fatalf("appendChannelCode() should keep existing dc: %q", got)
}
})
}
}