4fb1016977
iotlcm-sms:独立短信 HTTP/gRPC 服务,支持阿里云与腾讯云。 - Go module 迁移至 git.5iot.com/iotlcm-public/iotlcm-sms - 补 Apache-2.0 LICENSE,重写 README(特性/配置/接口/部署/目录/测试) - 配置改为 config.example.yaml + SMS_* 环境变量注入,仓库不含真实凭证 - 清理内部标识(私有镜像仓库 / 公司名 / 客户签名 / 真实模板ID / 真实手机号) - 统一 LF 行尾并加 .gitattributes
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package sms
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
type stubProvider struct{ called bool }
|
|
|
|
func (p *stubProvider) Send(context.Context, Config, Message) (Result, error) {
|
|
p.called = true
|
|
return Result{Code: 0, Message: "ok"}, nil
|
|
}
|
|
|
|
func TestRegistrySend(t *testing.T) {
|
|
provider := &stubProvider{}
|
|
registry := NewRegistry()
|
|
registry.Register(ServiceAliyun, provider)
|
|
config := Config{
|
|
ServiceType: ServiceAliyun, AccessKeyID: "id", AccessKeySecret: "secret",
|
|
SignName: "sign", TemplateID: "template",
|
|
}
|
|
result, err := registry.Send(context.Background(), config, Message{PhoneNumber: "138****8000"})
|
|
if err != nil || result.Code != 0 || !provider.called {
|
|
t.Fatalf("result=%+v err=%v called=%v", result, err, provider.called)
|
|
}
|
|
}
|
|
|
|
func TestRegistryValidatesBeforeProvider(t *testing.T) {
|
|
registry := NewRegistry()
|
|
_, err := registry.Send(context.Background(), Config{ServiceType: ServiceTencent}, Message{})
|
|
if !errors.Is(err, ErrInvalidRequest) {
|
|
t.Fatalf("err = %v, want ErrInvalidRequest", err)
|
|
}
|
|
}
|
|
|
|
func TestSplitAndTrim(t *testing.T) {
|
|
got := SplitAndTrim(" 138****8000, ,138****8000 ", ",")
|
|
if len(got) != 2 || got[0] != "138****8000" || got[1] != "138****8000" {
|
|
t.Fatalf("unexpected split result: %#v", got)
|
|
}
|
|
}
|