c7e154d7cc
Motivation: 钉钉机器人的 webhook 前缀固定不变,要求用户填写完整 URL 冗余且容易出错。简化通道配置项,降低接入配置成本,同时保证存量配置不受影响。 Changes: * 钉钉通道配置改用 access_token,webhook 前缀由内部固定拼接 * 保留对旧 webhook_url 配置的兼容,access_token 存在时优先生效 * 新增 webhook 地址解析逻辑的单元测试,覆盖优先级与回退场景 * 同步更新 README、HTTP 请求示例及设计文档中的配置示例 * E2E 测试改用 E2E_DINGTALK_ACCESS_TOKEN 环境变量并按新格式创建通道
34 lines
941 B
Go
34 lines
941 B
Go
package adapter
|
|
|
|
import "testing"
|
|
|
|
func TestDingtalkConfigWebhookURL(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
cfg dingtalkConfig
|
|
wantURL string
|
|
}{
|
|
{
|
|
name: "access token only",
|
|
cfg: dingtalkConfig{AccessToken: "tok-abc"},
|
|
wantURL: "https://oapi.dingtalk.com/robot/send?access_token=tok-abc",
|
|
},
|
|
{
|
|
name: "access token takes precedence over legacy url",
|
|
cfg: dingtalkConfig{AccessToken: "tok-abc", WebhookURL: "https://legacy.example/webhook"},
|
|
wantURL: "https://oapi.dingtalk.com/robot/send?access_token=tok-abc",
|
|
},
|
|
{
|
|
name: "fallback to legacy url",
|
|
cfg: dingtalkConfig{WebhookURL: "https://legacy.example/webhook"},
|
|
wantURL: "https://legacy.example/webhook",
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := tt.cfg.webhookURL(); got != tt.wantURL {
|
|
t.Fatalf("webhookURL() = %q, want %q", got, tt.wantURL)
|
|
}
|
|
})
|
|
}
|
|
} |