dailyops:list 命令 --state all 明確帶 state=all(#33)
issues/milestones 端點省略 state 時 API 預設 open,closed 項目漏列; pulls 端點省略時雖回全部,仍明確帶上避免依賴端點預設。三處同修並補 回歸測試(TestStateAllSendsExplicitParam)。
This commit is contained in:
@@ -220,6 +220,52 @@ func TestLabelsMilestonesReleasesList(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestStateAllSendsExplicitParam 是 #33 的回歸測試:issues/milestones
|
||||
// 端點省略 state 時 API 預設 open,closed 項目會漏列,因此 --state all
|
||||
// 必須明確帶 state=all;pulls 端點雖省略時也回全部,同樣明確帶上。
|
||||
func TestStateAllSendsExplicitParam(t *testing.T) {
|
||||
cases := []struct {
|
||||
args []string
|
||||
resp string
|
||||
wantOut string
|
||||
}{
|
||||
{
|
||||
args: []string{"issues", "list", "--repo", "a/b", "--state", "all"},
|
||||
resp: `[{"number":30,"title":"open","state":"open","user":{"login":"ceo"},"updated_at":"t"},{"number":12,"title":"closed","state":"closed","user":{"login":"ceo"},"updated_at":"t"}]`,
|
||||
wantOut: `"title":"closed"`,
|
||||
},
|
||||
{
|
||||
args: []string{"pulls", "list", "--repo", "a/b", "--state", "all"},
|
||||
resp: `[{"number":5,"title":"open PR","state":"open","user":{"login":"ceo"},"head":{"ref":"f"},"base":{"ref":"main"},"updated_at":"t"},{"number":2,"title":"closed PR","state":"closed","user":{"login":"ceo"},"head":{"ref":"f2"},"base":{"ref":"main"},"updated_at":"t"}]`,
|
||||
wantOut: `"title":"closed PR"`,
|
||||
},
|
||||
{
|
||||
args: []string{"milestones", "list", "--repo", "a/b", "--state", "all"},
|
||||
resp: `[{"title":"v2","state":"open","description":"","due_on":""},{"title":"v1","state":"closed","description":"","due_on":""}]`,
|
||||
wantOut: `"title":"v1"`,
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(strings.Join(tc.args, " "), func(t *testing.T) {
|
||||
var gotQuery string
|
||||
run := opsTestServer(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
gotQuery = r.URL.RawQuery
|
||||
fmt.Fprint(w, tc.resp)
|
||||
})
|
||||
stdout, _, code := run(tc.args...)
|
||||
if code != 0 {
|
||||
t.Fatalf("%v 應回 0,得到 %d", tc.args, code)
|
||||
}
|
||||
if !strings.Contains(gotQuery, "state=all") {
|
||||
t.Errorf("%v 應明確帶 state=all(省略時 issues/milestones 端點預設 open),得到查詢 %q", tc.args, gotQuery)
|
||||
}
|
||||
if !strings.Contains(stdout, tc.wantOut) {
|
||||
t.Errorf("%v 輸出應含 closed 項目 %s,得到:%s", tc.args, tc.wantOut, stdout)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestAPIDirectPassthrough 驗證 teai api 原樣輸出、GET 免 --yes、
|
||||
// POST 未帶 --yes 被擋。
|
||||
func TestAPIDirectPassthrough(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user