測試改斷言具體結束碼數值,對照 README 規格(#10)

cli_test、dailyops_commands_test、login_test、exitcode_test 原以
int(ExitUsage)/int(ExitAPI)/int(ExitInternal) 常數互比,常數若再
與 README 脫鉤測試仍會綠。改為直接斷言 0/2/3(內部錯誤 1)。

常數本體已隨 #5(6951817)改為明確數值,未知命令實測回 2。
This commit is contained in:
2026-09-10 10:12:35 +08:00
parent c5d5c37eae
commit f481377b9a
4 changed files with 34 additions and 23 deletions
+12 -8
View File
@@ -145,8 +145,9 @@ func TestLoginAddRejected401NoWrite(t *testing.T) {
`)
_, stderr, code := run(append(prefix,
"--url", srv.URL, "login", "add", "--token", "bad-tok")...)
if code != int(ExitAPI) {
t.Fatalf("401 should exit 3, got %d (stderr %s)", code, stderr)
// 401 是 API 錯誤;對照 README「輸出與結束碼」=3(#10)。
if code != 3 {
t.Fatalf("401 should exit 3 (README api error), got %d (stderr %s)", code, stderr)
}
if !strings.Contains(stderr, "401") {
t.Fatalf("stderr should mention 401: %s", stderr)
@@ -250,8 +251,9 @@ func TestLoginRemoveAsksConfirmation(t *testing.T) {
func TestLoginUnknownSubcommandUsage(t *testing.T) {
prefix, _ := loginTestEnv(t, "")
_, stderr, code := run(append(prefix, "login", "bogus")...)
if code != int(ExitUsage) {
t.Fatalf("want exit 2, got %d", code)
// 對照 README「輸出與結束碼」:用法錯誤=2(#10)。
if code != 2 {
t.Fatalf("want exit 2 (README usage), got %d", code)
}
if !strings.Contains(stderr, "unknown login subcommand") {
t.Fatalf("stderr: %s", stderr)
@@ -261,8 +263,9 @@ func TestLoginUnknownSubcommandUsage(t *testing.T) {
func TestLoginNoSubcommandUsage(t *testing.T) {
prefix, _ := loginTestEnv(t, "")
_, stderr, code := run(append(prefix, "login")...)
if code != int(ExitUsage) {
t.Fatalf("want exit 2, got %d", code)
// 對照 README「輸出與結束碼」:用法錯誤=2(#10)。
if code != 2 {
t.Fatalf("want exit 2 (README usage), got %d", code)
}
if !strings.Contains(stderr, "subcommand") {
t.Fatalf("stderr: %s", stderr)
@@ -272,8 +275,9 @@ func TestLoginNoSubcommandUsage(t *testing.T) {
func TestLoginRemoveNotFound(t *testing.T) {
prefix, _ := loginTestEnv(t, "logins: []\n")
_, stderr, code := run(append(prefix, "login", "remove", "--yes", "ghost")...)
if code != int(ExitInternal) {
t.Fatalf("want exit 1, got %d", code)
// ExitInternal 不在 README 保證範圍;此處固定為 1(內部錯誤,#10)。
if code != 1 {
t.Fatalf("want exit 1 (internal), got %d", code)
}
if !strings.Contains(stderr, `login "ghost" not found`) {
t.Fatalf("stderr: %s", stderr)