Files
lijiaoqiao/supply-api/internal/sms/config_example_test.go
Your Name 5ea6750cf3 test(supply-api): validate shipped config samples
Add regression tests for the shipped development and SMS sample configs, and fix the SMS example to match the runtime flat Config schema instead of nested provider blocks. Verified with fresh go test runs for ./internal/config and ./internal/sms before commit.
2026-04-11 11:31:05 +08:00

46 lines
1.1 KiB
Go

package sms
import (
"os"
"path/filepath"
"testing"
"gopkg.in/yaml.v3"
)
type smsExampleRoot struct {
SMS Config `yaml:"sms"`
}
func TestSMSExampleYAML_MatchesRuntimeConfigShape(t *testing.T) {
path := filepath.Join("..", "..", "config", "sms.example.yaml")
content, err := os.ReadFile(path)
if err != nil {
t.Fatalf("failed to read sms example config: %v", err)
}
var root smsExampleRoot
if err := yaml.Unmarshal(content, &root); err != nil {
t.Fatalf("failed to parse sms example config: %v", err)
}
if root.SMS.Provider != ProviderTencent {
t.Fatalf("expected provider %q, got %q", ProviderTencent, root.SMS.Provider)
}
if root.SMS.CodeLength != 6 {
t.Fatalf("expected code length 6, got %d", root.SMS.CodeLength)
}
if root.SMS.CodeExpireMins != 5 {
t.Fatalf("expected code expiry 5, got %d", root.SMS.CodeExpireMins)
}
if root.SMS.SignName == "" {
t.Fatal("expected sign_name to be populated in example config")
}
if root.SMS.TemplateCode == "" {
t.Fatal("expected template_code to be populated in example config")
}
if root.SMS.Region == "" {
t.Fatal("expected region to be populated in example config")
}
}