[dev-loop] Add tests for GetTimelineReviewCommentIDForReview and GitHub GetAllFilesInPath
CI / test (push) Successful in 17s
CI / review (anthropic--claude-4.6-sonnet, sonnet, SONNET_REVIEW_TOKEN) (push) Has been skipped
CI / review (gpt-5, gpt, GPT_REVIEW_TOKEN) (push) Has been skipped
CI / review (gpt-5, security, ., rodin/security-patterns, SECURITY_REVIEW.md, SECURITY_REVIEW_TOKEN) (push) Has been skipped
CI / test (push) Successful in 17s
CI / review (anthropic--claude-4.6-sonnet, sonnet, SONNET_REVIEW_TOKEN) (push) Has been skipped
CI / review (gpt-5, gpt, GPT_REVIEW_TOKEN) (push) Has been skipped
CI / review (gpt-5, security, ., rodin/security-patterns, SECURITY_REVIEW.md, SECURITY_REVIEW_TOKEN) (push) Has been skipped
gitea: Add 4 tests for GetTimelineReviewCommentIDForReview (was 0% coverage): - Success: find review in timeline by user login + body prefix match - ReviewFetchError: 404 on review API - EmptyBody: review with empty body returns error - NotFoundInTimeline: body matches but user login doesn't github: Add 3 tests for GetAllFilesInPath (was 0% coverage): - DirectoryWithFiles: lists directory, fetches base64-encoded file content - 404FallsBackToFile: 404 on dir path returns error when file also 404s - DirectoryWithSubdir: recursive directory traversal Coverage changes: - gitea: 80.0% → 85.2% - github: 79.9% → 86.3%
This commit is contained in:
@@ -1130,3 +1130,98 @@ func TestEscapePath_SpecialChars(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAllFilesInPath_DirectoryWithFiles(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
case "/repos/owner/repo/contents/patterns":
|
||||
// Directory listing
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(`[{"name":"go.md","path":"patterns/go.md","type":"file"}]`))
|
||||
case "/repos/owner/repo/contents/patterns/go.md":
|
||||
// GitHub file response with base64 content
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(`{"name":"go.md","path":"patterns/go.md","type":"file","encoding":"base64","content":"IyBHbyBwYXR0ZXJucwo="}`))
|
||||
default:
|
||||
t.Errorf("unexpected path: %s", r.URL.Path)
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
c := NewClient("tok", srv.URL, AllowInsecureHTTPForTest())
|
||||
files, err := c.GetAllFilesInPath(context.Background(), "owner", "repo", "patterns")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if len(files) != 1 {
|
||||
t.Fatalf("len(files) = %d, want 1", len(files))
|
||||
}
|
||||
if files["patterns/go.md"] != "# Go patterns\n" {
|
||||
t.Errorf("unexpected content: %q", files["patterns/go.md"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAllFilesInPath_404FallsBackToFile(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
case "/repos/owner/repo/contents/README.md":
|
||||
// ListContents returns 404 for file paths
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
w.Write([]byte(`{"message":"Not Found"}`))
|
||||
default:
|
||||
t.Errorf("unexpected path: %s", r.URL.Path)
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
c := NewClient("tok", srv.URL, AllowInsecureHTTPForTest())
|
||||
// GetFileContent also goes to /contents/ — this will 404 too.
|
||||
// The function should return the path-not-found error.
|
||||
_, err := c.GetAllFilesInPath(context.Background(), "owner", "repo", "README.md")
|
||||
if err == nil {
|
||||
t.Fatal("expected error when both dir and file 404, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAllFilesInPath_DirectoryWithSubdir(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
case "/repos/owner/repo/contents/src":
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(`[
|
||||
{"name":"main.go","path":"src/main.go","type":"file"},
|
||||
{"name":"sub","path":"src/sub","type":"dir"}
|
||||
]`))
|
||||
case "/repos/owner/repo/contents/src/main.go":
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(`{"name":"main.go","path":"src/main.go","type":"file","encoding":"base64","content":"cGFja2FnZSBtYWluCg=="}`))
|
||||
case "/repos/owner/repo/contents/src/sub":
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(`[{"name":"util.go","path":"src/sub/util.go","type":"file"}]`))
|
||||
case "/repos/owner/repo/contents/src/sub/util.go":
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(`{"name":"util.go","path":"src/sub/util.go","type":"file","encoding":"base64","content":"cGFja2FnZSBzdWIK"}`))
|
||||
default:
|
||||
t.Errorf("unexpected path: %s", r.URL.Path)
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
c := NewClient("tok", srv.URL, AllowInsecureHTTPForTest())
|
||||
files, err := c.GetAllFilesInPath(context.Background(), "owner", "repo", "src")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if len(files) != 2 {
|
||||
t.Fatalf("len(files) = %d, want 2: %v", len(files), files)
|
||||
}
|
||||
if files["src/main.go"] != "package main\n" {
|
||||
t.Errorf("src/main.go content unexpected: %q", files["src/main.go"])
|
||||
}
|
||||
if files["src/sub/util.go"] != "package sub\n" {
|
||||
t.Errorf("src/sub/util.go content unexpected: %q", files["src/sub/util.go"])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user