已合并
fix(api): remove third batch of dead api functions #612
aflyingto创建于 4 天前
fix(api): remove third batch of dead api functions #612
已合并
aflyingto创建于 4 天前
共 14 个文件变更+2-543
@@ -526,16 +526,3 @@ func decodeAPIError(respBody []byte, statusCode int, status string) error {
526 }526 }
527 return &APIError{StatusCode: statusCode, Message: status}527 return &APIError{StatusCode: statusCode, Message: status}
528}528}
529- 
530-// BuildURL builds a URL with path parameters
531-func BuildURL(base string, params map[string]string) string {
532- for k, v := range params {
533- base = replacePath(base, k, v)
534- }
535- return base
536-}
537- 
538-func replacePath(urlStr, key, value string) string {
539- placeholder := "{" + key + "}"
540- return strings.ReplaceAll(urlStr, placeholder, url.PathEscape(value))
541-}
@@ -13,55 +13,6 @@ import (
13 "gitcode.com/gitcode-cli/cli/pkg/testutil"13 "gitcode.com/gitcode-cli/cli/pkg/testutil"
14)14)
15 15 
16-func TestBuildURL(t *testing.T) {
17- tests := []struct {
18- name string
19- base string
20- params map[string]string
21- want string
22- }{
23- {
24- name: "no params",
25- base: "/repos/{owner}/{repo}/issues",
26- params: nil,
27- want: "/repos/{owner}/{repo}/issues",
28- },
29- {
30- name: "replace owner and repo",
31- base: "/repos/{owner}/{repo}/issues",
32- params: map[string]string{"owner": "octocat", "repo": "hello-world"},
33- want: "/repos/octocat/hello-world/issues",
34- },
35- {
36- name: "replace single param",
37- base: "/repos/owner/repo/issues/{number}",
38- params: map[string]string{"number": "42"},
39- want: "/repos/owner/repo/issues/42",
40- },
41- {
42- name: "encoded value",
43- base: "/repos/{owner}/{repo}",
44- params: map[string]string{"owner": "user/with"},
45- want: "/repos/user%2Fwith/{repo}",
46- },
47- {
48- name: "empty params map",
49- base: "/user",
50- params: map[string]string{},
51- want: "/user",
52- },
53- }
54- 
55- for _, tt := range tests {
56- t.Run(tt.name, func(t *testing.T) {
57- got := BuildURL(tt.base, tt.params)
58- if got != tt.want {
59- t.Errorf("BuildURL() = %q, want %q", got, tt.want)
60- }
61- })
62- }
63-}
64- 
65func TestAPIError(t *testing.T) {16func TestAPIError(t *testing.T) {
66 tests := []struct {17 tests := []struct {
67 name string18 name string
Mapi/http_client.go+0-10文件内容审核中,请稍后刷新重试
Mapi/http_client_test.go+0-16文件内容审核中,请稍后刷新重试
Mapi/issue_assignee_test.go+0-23文件内容审核中,请稍后刷新重试
Mapi/queries_actions_plugins.go+0-40文件内容审核中,请稍后刷新重试
@@ -1,7 +1,6 @@
1package api1package api
2 2 
3import (3import (
4- "encoding/json"
5 "errors"4 "errors"
6 "io"5 "io"
7 "net/http"6 "net/http"
@@ -194,56 +193,6 @@ func TestViewActionsPluginReturnsBody(t *testing.T) {
194 }193 }
195}194}
196 195 
197-func TestParseActionsPluginsListPlainArray(t *testing.T) {
198- raw := []byte(`[{"name":"checkout","display_name":"Checkout","description":"checkout repo","version":"v1.0"}]`)
199- plugins, err := ParseActionsPluginsList(raw)
200- if err != nil {
201- t.Fatalf("ParseActionsPluginsList() error = %v", err)
202- }
203- if len(plugins) != 1 {
204- t.Fatalf("len = %d, want 1", len(plugins))
205- }
206- if plugins[0].Name != "checkout" {
207- t.Fatalf("name = %q, want checkout", plugins[0].Name)
208- }
209- if plugins[0].Version != "v1.0" {
210- t.Fatalf("version = %q, want v1.0", plugins[0].Version)
211- }
212-}
213- 
214-func TestParseActionsPluginsListWrapper(t *testing.T) {
215- tests := []struct {
216- name string
217- raw string
218- want int
219- }{
220- {name: "plugins wrapper", raw: `{"plugins":[{"name":"a"}]}`, want: 1},
221- {name: "list wrapper", raw: `{"list":[{"name":"b"}]}`, want: 1},
222- {name: "data wrapper", raw: `{"data":[{"name":"c"}]}`, want: 1},
223- {name: "content wrapper", raw: `{"content":[{"name":"d"}]}`, want: 1},
224- {name: "empty array", raw: `[]`, want: 0},
225- {name: "empty wrapper", raw: `{"plugins":[]}`, want: 0},
226- }
227- for _, tt := range tests {
228- t.Run(tt.name, func(t *testing.T) {
229- plugins, err := ParseActionsPluginsList([]byte(tt.raw))
230- if err != nil {
231- t.Fatalf("ParseActionsPluginsList() error = %v", err)
232- }
233- if len(plugins) != tt.want {
234- t.Fatalf("len = %d, want %d", len(plugins), tt.want)
235- }
236- })
237- }
238-}
239- 
240-func TestParseActionsPluginsListUnrecognized(t *testing.T) {
241- _, err := ParseActionsPluginsList([]byte(`{"unrelated":"field"}`))
242- if err == nil {
243- t.Fatal("expected an error for an unrecognized response object")
244- }
245-}
246- 
247// TestParseActionsPluginsPageRejectsNonArrayField pins the error branch for a196// TestParseActionsPluginsPageRejectsNonArrayField pins the error branch for a
248// recognized wrapper field whose value is not an array: it must be reported197// recognized wrapper field whose value is not an array: it must be reported
249// rather than silently flattened into an empty list.198// rather than silently flattened into an empty list.
@@ -294,52 +243,6 @@ func TestParseActionsPluginsPageNullWrappers(t *testing.T) {
294 }243 }
295}244}
296 245 
297-func TestParseActionsPluginsListInvalid(t *testing.T) {
298- _, err := ParseActionsPluginsList([]byte(`{invalid json`))
299- if err == nil {
300- t.Fatal("expected error for invalid JSON")
301- }
302-}
303- 
304-func TestParseActionsPluginsListRawPreservesFields(t *testing.T) {
305- raw := []byte(`[{"name":"checkout","display_name":"Checkout","custom_field":"extra","version":"v1"}]`)
306- entries, err := ParseActionsPluginsListRaw(raw)
307- if err != nil {
308- t.Fatalf("ParseActionsPluginsListRaw() error = %v", err)
309- }
310- if len(entries) != 1 {
311- t.Fatalf("len = %d, want 1", len(entries))
312- }
313- var m map[string]interface{}
314- if err := json.Unmarshal(entries[0], &m); err != nil {
315- t.Fatalf("json.Unmarshal() error = %v", err)
316- }
317- if m["custom_field"] != "extra" {
318- t.Fatalf("custom_field = %v, want extra (full fields not preserved)", m["custom_field"])
319- }
320-}
321- 
322-func TestCountPluginsEntries(t *testing.T) {
323- tests := []struct {
324- name string
325- raw string
326- want int
327- }{
328- {name: "plain array 3", raw: `[{"name":"a"},{"name":"b"},{"name":"c"}]`, want: 3},
329- {name: "empty", raw: `[]`, want: 0},
330- {name: "wrapper", raw: `{"plugins":[{"name":"a"}]}`, want: 1},
331- {name: "content wrapper", raw: `{"content":[{"name":"a"}]}`, want: 1},
332- }
333- for _, tt := range tests {
334- t.Run(tt.name, func(t *testing.T) {
335- got := CountPluginsEntries([]byte(tt.raw))
336- if got != tt.want {
337- t.Fatalf("CountPluginsEntries() = %d, want %d", got, tt.want)
338- }
339- })
340- }
341-}
342- 
343func TestRawRESTToHostWhitelist(t *testing.T) {246func TestRawRESTToHostWhitelist(t *testing.T) {
344 tests := []struct {247 tests := []struct {
345 name string248 name string
@@ -150,29 +150,6 @@ func TestListCommentsForCommit(t *testing.T) {
150 t.Fatalf("ListCommentsForCommit() = %+v", comments)150 t.Fatalf("ListCommentsForCommit() = %+v", comments)
151 }151 }
152}152}
153- 
154-func TestCloseMilestone(t *testing.T) {
155- client := NewClientFromHTTP(testutil.NewTestHTTPClient(testutil.MockAPIHandler()))
156- m, err := CloseMilestone(client, "owner", "test-repo", 1)
157- if err != nil {
158- t.Fatalf("CloseMilestone() error = %v", err)
159- }
160- if m.State != "closed" {
161- t.Errorf("State = %q, want %q", m.State, "closed")
162- }
163-}
164- 
165-func TestOpenMilestone(t *testing.T) {
166- client := NewClientFromHTTP(testutil.NewTestHTTPClient(testutil.MockAPIHandler()))
167- m, err := OpenMilestone(client, "owner", "test-repo", 1)
168- if err != nil {
169- t.Fatalf("OpenMilestone() error = %v", err)
170- }
171- if m.State != "closed" {
172- t.Errorf("State = %q, want %q", m.State, "closed")
173- }
174-}
175- 
176func TestUpdateCommitComment(t *testing.T) {153func TestUpdateCommitComment(t *testing.T) {
177 client := NewClientFromHTTP(testutil.NewTestHTTPClient(testutil.MockAPIHandler()))154 client := NewClientFromHTTP(testutil.NewTestHTTPClient(testutil.MockAPIHandler()))
178 c, err := UpdateCommitComment(client, "owner", "test-repo", "1", "updated body")155 c, err := UpdateCommitComment(client, "owner", "test-repo", "1", "updated body")
@@ -231,18 +208,6 @@ func TestReopenPullRequest(t *testing.T) {
231 t.Logf("ReopenPullRequest state = %q", pr.State)208 t.Logf("ReopenPullRequest state = %q", pr.State)
232 }209 }
233}210}
234- 
235-func TestAddLabelsToIssue(t *testing.T) {
236- client := NewClientFromHTTP(testutil.NewTestHTTPClient(testutil.MockAPIHandler()))
237- labels, err := AddLabelsToIssue(client, "owner", "test-repo", 1, []string{"bug", "enhancement"})
238- if err != nil {
239- t.Fatalf("AddLabelsToIssue() error = %v", err)
240- }
241- if len(labels) != 1 || labels[0].Name != "bug" {
242- t.Fatalf("AddLabelsToIssue() = %+v", labels)
243- }
244-}
245- 
246func TestAddIssueLabels(t *testing.T) {211func TestAddIssueLabels(t *testing.T) {
247 client := NewClientFromHTTP(testutil.NewTestHTTPClient(testutil.MockAPIHandler()))212 client := NewClientFromHTTP(testutil.NewTestHTTPClient(testutil.MockAPIHandler()))
248 labels, err := AddIssueLabels(client, "owner", "test-repo", 1, []string{"bug"})213 labels, err := AddIssueLabels(client, "owner", "test-repo", 1, []string{"bug"})
Mapi/queries_label_milestone.go+0-28文件内容审核中,请稍后刷新重试
Mapi/queries_label_test.go+0-44文件内容审核中,请稍后刷新重试
Mapi/queries_release.go+1-63文件内容审核中,请稍后刷新重试
Mapi/queries_release_test.go+0-96文件内容审核中,请稍后刷新重试
Mapi/queries_user.go+0-25文件内容审核中,请稍后刷新重试
Mpkg/testutil/testutil.go+1-4文件内容审核中,请稍后刷新重试