init: web_hgcg_server 初始化提交
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user