42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
// openapi_sync_test.go Day 41(清债②):codes.go ↔ openapi.yaml x-isc-dict 双向锁定,
|
|
// 任一侧改动未同步即测试失败(再跑 go run ./tools/gen-dict 重生成前端字典)。
|
|
package errors
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
func TestOpenApiIscDictSync(t *testing.T) {
|
|
raw, err := os.ReadFile(filepath.Join("..", "..", "..", "api", "openapi.yaml"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var doc struct {
|
|
IscDict map[string]string `yaml:"x-isc-dict"`
|
|
}
|
|
if err := yaml.Unmarshal(raw, &doc); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(doc.IscDict) == 0 {
|
|
t.Fatal("openapi.yaml 缺 x-isc-dict")
|
|
}
|
|
all := All()
|
|
if len(all) != len(doc.IscDict) {
|
|
t.Fatalf("码表数量不一致: codes.go=%d openapi=%d(跑 go run ./tools/gen-dict 同步)", len(all), len(doc.IscDict))
|
|
}
|
|
for _, e := range all {
|
|
cn, ok := doc.IscDict[e.Code]
|
|
if !ok {
|
|
t.Errorf("codes.go 码 %s(%s) 未进 openapi x-isc-dict", e.Code, e.Msg)
|
|
continue
|
|
}
|
|
if cn != e.Msg {
|
|
t.Errorf("码 %s 中文不一致: codes.go=%q openapi=%q", e.Code, e.Msg, cn)
|
|
}
|
|
}
|
|
}
|