Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions internal/project/basestatus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,22 @@ func commitFile(t *testing.T, dir string, git func(args ...string) string, name,
}

func TestBaseStatusNoRemote(t *testing.T) {
t.Parallel()
repo, _ := initRepo(t)
if got := New(nil).BaseStatus(repo); got != nil {
t.Fatalf("want nil for a repository with no origin, got %+v", got)
}
}

func TestBaseStatusNotARepository(t *testing.T) {
t.Parallel()
if got := New(nil).BaseStatus(t.TempDir()); got != nil {
t.Fatalf("want nil outside a repository, got %+v", got)
}
}

func TestBaseStatusUpToDate(t *testing.T) {
t.Parallel()
clone, cloneGit, _ := initClone(t)
cloneGit("checkout", "-b", "feature")
commitFile(t, clone, cloneGit, "b.txt", "two\n", "add b")
Expand All @@ -103,6 +106,7 @@ func TestBaseStatusUpToDate(t *testing.T) {
}

func TestBaseStatusBehindWithoutConflict(t *testing.T) {
t.Parallel()
clone, cloneGit, originGit := initClone(t)
cloneGit("checkout", "-b", "feature")
commitFile(t, clone, cloneGit, "b.txt", "two\n", "add b")
Expand All @@ -125,6 +129,7 @@ func TestBaseStatusBehindWithoutConflict(t *testing.T) {
}

func TestBaseStatusConflict(t *testing.T) {
t.Parallel()
clone, cloneGit, originGit := initClone(t)
cloneGit("checkout", "-b", "feature")
commitFile(t, clone, cloneGit, "a.txt", "mine\n", "edit a")
Expand All @@ -147,6 +152,7 @@ func TestBaseStatusConflict(t *testing.T) {
// stale one pins the badge to a state the checkout has left, which is the only
// way this cache can be wrong. Both keys are moved, one at a time.
func TestBaseStatusRecomputes(t *testing.T) {
t.Parallel()
clone, cloneGit, originGit := initClone(t)
cloneGit("checkout", "-b", "feature")
commitFile(t, clone, cloneGit, "b.txt", "two\n", "add b")
Expand Down Expand Up @@ -175,6 +181,7 @@ func TestBaseStatusRecomputes(t *testing.T) {
// the parser's own idea of them: the tree OID, the conflicted paths, an empty
// entry, then the informational messages that must not be read as paths.
func TestConflictPaths(t *testing.T) {
t.Parallel()
tests := []struct {
name string
out string
Expand Down Expand Up @@ -210,6 +217,7 @@ func TestConflictPaths(t *testing.T) {
}

func TestClaimFetchThrottles(t *testing.T) {
t.Parallel()
var cache baseCache
now := time.Now()
if !cache.claimFetch("/repo/.git", now) {
Expand Down
10 changes: 10 additions & 0 deletions internal/project/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
const pngBytes = "\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR"

func TestBlobWorkTree(t *testing.T) {
t.Parallel()
repo, _ := initRepo(t)
write(t, repo, "img/logo.PNG", pngBytes)

Expand All @@ -34,6 +35,7 @@ func TestBlobWorkTree(t *testing.T) {
// The review's two sides: HEAD for a working-tree diff, a tree oid for a turn.
// Each reads its own revision while the working tree has moved on.
func TestBlobAtRevision(t *testing.T) {
t.Parallel()
repo, git := initRepo(t)
write(t, repo, "doc.pdf", "%PDF-old\x00")
git("add", "doc.pdf")
Expand All @@ -56,6 +58,7 @@ func TestBlobAtRevision(t *testing.T) {
// An added file has no old side and a deleted one no new side; both must read
// as absent, which the page draws as no column at all.
func TestBlobMissingSideIsNotExist(t *testing.T) {
t.Parallel()
repo, _ := initRepo(t)
svc := New(nil)
for _, ref := range []string{"", "HEAD"} {
Expand All @@ -66,6 +69,7 @@ func TestBlobMissingSideIsNotExist(t *testing.T) {
}

func TestBlobRefusals(t *testing.T) {
t.Parallel()
repo, git := initRepo(t)
write(t, repo, "assets/x.png", pngBytes)
write(t, repo, "notes.txt", "text\n")
Expand Down Expand Up @@ -93,6 +97,7 @@ func TestBlobRefusals(t *testing.T) {
}

func TestBlobDirectoryNamedLikeAnImage(t *testing.T) {
t.Parallel()
repo, git := initRepo(t)
write(t, repo, "shots.png/a.txt", "x\n")
git("add", ".")
Expand All @@ -109,6 +114,7 @@ func TestBlobDirectoryNamedLikeAnImage(t *testing.T) {
// The limit is pinned to a literal and probed on both sides, in the working
// tree and in git's object store, which are read by different code.
func TestBlobSizeLimit(t *testing.T) {
t.Parallel()
if maxPreviewBytes != 20<<20 {
t.Fatalf("maxPreviewBytes = %d, want 20 MiB", maxPreviewBytes)
}
Expand Down Expand Up @@ -141,6 +147,7 @@ func serveBlob(t *testing.T, method string, query url.Values, header http.Header
}

func TestServeBlob(t *testing.T) {
t.Parallel()
repo, _ := initRepo(t)
write(t, repo, "logo.png", pngBytes)

Expand All @@ -164,6 +171,7 @@ func TestServeBlob(t *testing.T) {

// Chromium's PDF viewer fetches a large document in ranges.
func TestServeBlobHonoursRange(t *testing.T) {
t.Parallel()
repo, _ := initRepo(t)
write(t, repo, "doc.pdf", "%PDF-1.4\x00rest")

Expand All @@ -175,6 +183,7 @@ func TestServeBlobHonoursRange(t *testing.T) {
}

func TestServeBlobStatuses(t *testing.T) {
t.Parallel()
repo, _ := initRepo(t)
write(t, repo, "big.png", strings.Repeat("\x00", maxPreviewBytes+1))

Expand Down Expand Up @@ -203,6 +212,7 @@ func TestServeBlobStatuses(t *testing.T) {

// The page prints these bodies verbatim, so their words are the contract.
func TestServeBlobRefusalWording(t *testing.T) {
t.Parallel()
repo, _ := initRepo(t)
write(t, repo, "big.png", strings.Repeat("\x00", maxPreviewBytes+1))

Expand Down
2 changes: 2 additions & 0 deletions internal/project/branchrules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
)

func TestParseBranchRules(t *testing.T) {
t.Parallel()
t.Run("a ruleset that narrows the merge methods", func(t *testing.T) {
out := []byte(`[
{"type":"deletion","parameters":null},
Expand Down Expand Up @@ -73,6 +74,7 @@ func TestParseBranchRules(t *testing.T) {
}

func TestBranchRulesFlow(t *testing.T) {
t.Parallel()
t.Run("the branch is addressed in the path, escaped", func(t *testing.T) {
gh := &fakeGH{out: []byte(`[]`)}
if _, err := withGH(gh).BranchRules("/repo", "feat/IMPEX-728"); err != nil {
Expand Down
6 changes: 6 additions & 0 deletions internal/project/carry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
// untracked file in a directory that does not exist in dst yet, and a binary
// change. What git ignores stays behind, and everything arrives unstaged.
func TestCarryUncommitted(t *testing.T) {
t.Parallel()
repo, git := initRepo(t)
write(t, repo, "mod.txt", "one\n")
write(t, repo, "del.txt", "gone\n")
Expand Down Expand Up @@ -60,6 +61,7 @@ func TestCarryUncommitted(t *testing.T) {
// TestCarryUncommittedClean proves a clean source is a no-op rather than an
// error — the fork of a committed checkout goes through the same call.
func TestCarryUncommittedClean(t *testing.T) {
t.Parallel()
repo, git := initRepo(t)
dst := filepath.Join(t.TempDir(), "fork")
git("worktree", "add", "-b", "fork", dst, "main")
Expand All @@ -75,6 +77,7 @@ func TestCarryUncommittedClean(t *testing.T) {
// TestCarryUncommittedNotRepo proves a source git cannot read is reported
// rather than silently carrying nothing.
func TestCarryUncommittedNotRepo(t *testing.T) {
t.Parallel()
if err := New(nil).CarryUncommitted(t.TempDir(), t.TempDir()); err == nil {
t.Fatal("CarryUncommitted accepted a directory that is not a checkout")
}
Expand All @@ -93,6 +96,7 @@ func read(t *testing.T, dir, name string) string {
// is stepped over rather than dereferenced or reported: the rest of the carry
// still lands.
func TestCarryUncommittedSkipsNonRegular(t *testing.T) {
t.Parallel()
repo, git := initRepo(t)
if err := os.Symlink("a.txt", filepath.Join(repo, "link.txt")); err != nil {
t.Skipf("symlinks unavailable: %v", err)
Expand All @@ -117,6 +121,7 @@ func TestCarryUncommittedSkipsNonRegular(t *testing.T) {
// the listing and the copy are two calls, and a build in the source checkout
// deletes its own scratch between them — is not a failure.
func TestCarryFileVanished(t *testing.T) {
t.Parallel()
dir := t.TempDir()
if err := carryFile(filepath.Join(dir, "gone.txt"), filepath.Join(dir, "copy.txt")); err != nil {
t.Fatalf("carryFile on a missing source: %v", err)
Expand All @@ -129,6 +134,7 @@ func TestCarryFileVanished(t *testing.T) {
// which Go maps onto fs.ErrNotExist — the same error a vanished source gives.
// Caught by the Windows runner after passing here (#616).
func TestCarryFileReportsRealFailure(t *testing.T) {
t.Parallel()
dir := t.TempDir()
write(t, dir, "from.txt", "data\n")
// The destination's parent is a file, so MkdirAll cannot make the directory.
Expand Down
6 changes: 6 additions & 0 deletions internal/project/difftext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
// TestDiffText proves tracked edits (staged and unstaged) and untracked files
// all land in one unified diff.
func TestDiffText(t *testing.T) {
t.Parallel()
repo, git := initRepo(t)
if err := os.WriteFile(filepath.Join(repo, "a.txt"), []byte("uno\n"), 0o644); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -41,6 +42,7 @@ func TestDiffText(t *testing.T) {
// TestDiffTextNoHead proves a repository without commits diffs staged and
// untracked files against the empty tree instead of erroring on HEAD.
func TestDiffTextNoHead(t *testing.T) {
t.Parallel()
repo := t.TempDir()
if out, err := exec.Command("git", "init", "-b", "main", repo).CombinedOutput(); err != nil {
t.Skipf("git init unavailable: %v (%s)", err, out)
Expand Down Expand Up @@ -69,6 +71,7 @@ func TestDiffTextNoHead(t *testing.T) {
// TestDiffTextClean proves a clean repository yields an empty diff, and a
// non-repository path an error.
func TestDiffTextClean(t *testing.T) {
t.Parallel()
repo, _ := initRepo(t)
out, err := New(nil).DiffText(repo)
if err != nil {
Expand All @@ -89,6 +92,7 @@ func TestDiffTextClean(t *testing.T) {
// itself cannot open it — the last one is the "any other failure" branch, which
// has to be told apart from git's exit 1 for "the files differ".
func TestUntrackedDiffYieldsNothingItCannotRender(t *testing.T) {
t.Parallel()
repo, _ := initRepo(t)

if got := untrackedDiff(repo, "vanished.txt"); got != "" {
Expand Down Expand Up @@ -119,6 +123,7 @@ func TestUntrackedDiffYieldsNothingItCannotRender(t *testing.T) {
// TestDiffTextBinaryUntracked proves an untracked binary shows up as git's
// "Binary files ... differ" stanza rather than a textual hunk.
func TestDiffTextBinaryUntracked(t *testing.T) {
t.Parallel()
repo, _ := initRepo(t)
if err := os.WriteFile(filepath.Join(repo, "blob.bin"), []byte{0, 1, 2, 0}, 0o644); err != nil {
t.Fatal(err)
Expand All @@ -136,6 +141,7 @@ func TestDiffTextBinaryUntracked(t *testing.T) {
// TestDiffTextDecodesLatin1 covers a file saved in ISO-8859-1 next to a UTF-8
// one: each line reaches the review as UTF-8 instead of U+FFFD.
func TestDiffTextDecodesLatin1(t *testing.T) {
t.Parallel()
repo, _ := initRepo(t)
if err := os.WriteFile(filepath.Join(repo, "latin.java"), []byte("// servi\xe7os padr\xe3o\n"), 0o644); err != nil {
t.Fatal(err)
Expand Down
3 changes: 3 additions & 0 deletions internal/project/discard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
// TestDiscardFileTracked proves a modified tracked file is restored to its
// HEAD content, staged or not.
func TestDiscardFileTracked(t *testing.T) {
t.Parallel()
repo, git := initRepo(t)
if err := os.WriteFile(filepath.Join(repo, "a.txt"), []byte("uno\n"), 0o644); err != nil {
t.Fatal(err)
Expand All @@ -33,6 +34,7 @@ func TestDiscardFileTracked(t *testing.T) {
// TestDiscardFileNew proves untracked and staged-new files are removed from
// disk and index.
func TestDiscardFileNew(t *testing.T) {
t.Parallel()
repo, git := initRepo(t)
if err := os.WriteFile(filepath.Join(repo, "staged.txt"), []byte("s\n"), 0o644); err != nil {
t.Fatal(err)
Expand All @@ -58,6 +60,7 @@ func TestDiscardFileNew(t *testing.T) {
// TestDiscardFileRejectsEscape proves traversal and absolute paths never reach
// the filesystem.
func TestDiscardFileRejectsEscape(t *testing.T) {
t.Parallel()
repo, _ := initRepo(t)
for _, rel := range []string{"../outside.txt", "/etc/passwd", "a/../../b"} {
if err := New(nil).DiscardFile(repo, rel); err == nil {
Expand Down
11 changes: 11 additions & 0 deletions internal/project/filelines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func numbered(n int) string {
}

func TestSliceLines(t *testing.T) {
t.Parallel()
text := "a\nb\nc\nd\n"
tests := []struct {
name string
Expand Down Expand Up @@ -46,6 +47,7 @@ func TestSliceLines(t *testing.T) {
// The cap is pinned to a literal and probed on both sides of it, so a change to
// maxExpandLines has to move this test rather than ride along with it.
func TestSliceLinesCap(t *testing.T) {
t.Parallel()
if maxExpandLines != 500 {
t.Fatalf("maxExpandLines = %d, want 500 — the wire contract moved", maxExpandLines)
}
Expand All @@ -67,6 +69,7 @@ func TestSliceLinesCap(t *testing.T) {
}

func TestIsOID(t *testing.T) {
t.Parallel()
valid := []string{"a4dbc1f", strings.Repeat("0", 40), "533f1af9fc740d2335cb3b4aae0e6481acfc5211"}
for _, ref := range valid {
if !isOID(ref) {
Expand All @@ -82,6 +85,7 @@ func TestIsOID(t *testing.T) {
}

func TestContentsPath(t *testing.T) {
t.Parallel()
got := contentsPath("internal/rpc/rpc go.md", "abcdef1234567890")
want := "repos/{owner}/{repo}/contents/internal/rpc/rpc%20go.md?ref=abcdef1234567890"
if got != want {
Expand All @@ -90,6 +94,7 @@ func TestContentsPath(t *testing.T) {
}

func TestFileLinesWorkTree(t *testing.T) {
t.Parallel()
repo, _ := initRepo(t)
write(t, repo, "src/app.ts", "one\ntwo\nthree\nfour\n")

Expand Down Expand Up @@ -120,6 +125,7 @@ func TestFileLinesWorkTree(t *testing.T) {
// A local object is read by git, and never costs a gh call — the turn diff's
// snapshot tree is the case, and it is the reason the local read comes first.
func TestFileLinesLocalObject(t *testing.T) {
t.Parallel()
repo, git := initRepo(t)
write(t, repo, "a.txt", "one\ntwo\nthree\n")
git("add", "a.txt")
Expand All @@ -146,6 +152,7 @@ func TestFileLinesLocalObject(t *testing.T) {
}

func TestFileLinesLocalObjectRejectsADirectory(t *testing.T) {
t.Parallel()
repo, git := initRepo(t)
write(t, repo, "src/a.txt", "one\n")
git("add", "src/a.txt")
Expand All @@ -162,6 +169,7 @@ func TestFileLinesLocalObjectRejectsADirectory(t *testing.T) {
}

func TestFileLinesLocalObjectRejectsBinary(t *testing.T) {
t.Parallel()
repo, git := initRepo(t)
write(t, repo, "blob.bin", "text\x00more")
git("add", "blob.bin")
Expand All @@ -176,6 +184,7 @@ func TestFileLinesLocalObjectRejectsBinary(t *testing.T) {
// An oid the clone does not have is a pull request's head: GitHub answers for
// it, through the contents API rather than through git.
func TestFileLinesMissingObjectAsksGitHub(t *testing.T) {
t.Parallel()
repo, _ := initRepo(t)
missing := strings.Repeat("b", 40)

Expand All @@ -197,6 +206,7 @@ func TestFileLinesMissingObjectAsksGitHub(t *testing.T) {
}

func TestFileLinesGitHubRejectsOversize(t *testing.T) {
t.Parallel()
repo, _ := initRepo(t)
gh := &fakeGH{out: []byte(strings.Repeat("x", maxReadFileSize+1))}

Expand All @@ -206,6 +216,7 @@ func TestFileLinesGitHubRejectsOversize(t *testing.T) {
}

func TestFileLinesGitHubFailureSurfaces(t *testing.T) {
t.Parallel()
repo, _ := initRepo(t)
gh := &fakeGH{err: errors.New("gh: not found")}
if _, err := withGH(gh).FileLines(repo, "a.txt", strings.Repeat("c", 40), 1, 5); err == nil {
Expand Down
Loading
Loading