package main import ( "flag" "strconv" "testing" ) // TestPort_Default 校验 taskService 默认 Dubbo 端口。 // // 取自 main.go 顶部 flag.Int("port", 20006, ...)(taskService 无 getEnvInt 包装)。 func TestPort_Default(t *testing.T) { const want = 20006 f := flag.Lookup("port") if f == nil { t.Fatal("port flag 未注册") } got, err := strconv.Atoi(f.DefValue) if err != nil { t.Fatalf("port DefValue=%q 解析失败: %v", f.DefValue, err) } if got != want { t.Errorf("taskService 默认端口=%d, 期望=%d", got, want) } }