aboutsummaryrefslogtreecommitdiff
path: root/objectstore/loose/read_test.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-04 08:26:56 +0800
committerGravatar Runxi Yu2026-03-04 08:59:53 +0800
commitab7501be34032fb9e5c48726a68ae90a917af9eb (patch)
tree20d005647569befea8133e953c3270e8fd2a2a5b /objectstore/loose/read_test.go
parent*: gofumpt (diff)
*: Lint
Diffstat (limited to 'objectstore/loose/read_test.go')
-rw-r--r--objectstore/loose/read_test.go43
1 files changed, 34 insertions, 9 deletions
diff --git a/objectstore/loose/read_test.go b/objectstore/loose/read_test.go
index d8166c9e..1efc1682 100644
--- a/objectstore/loose/read_test.go
+++ b/objectstore/loose/read_test.go
@@ -41,6 +41,7 @@ func TestLooseStoreReadAgainstGit(t *testing.T) {
if err != nil {
t.Fatalf("ReadBytesFull: %v", err)
}
+
if !bytes.Equal(gotRaw, wantRaw) {
t.Fatalf("ReadBytesFull mismatch")
}
@@ -49,9 +50,11 @@ func TestLooseStoreReadAgainstGit(t *testing.T) {
if err != nil {
t.Fatalf("ReadBytesContent: %v", err)
}
+
if gotType != wantType {
t.Fatalf("ReadBytesContent type = %v, want %v", gotType, wantType)
}
+
if !bytes.Equal(gotBody, wantBody) {
t.Fatalf("ReadBytesContent body mismatch")
}
@@ -60,9 +63,11 @@ func TestLooseStoreReadAgainstGit(t *testing.T) {
if err != nil {
t.Fatalf("ReadHeader: %v", err)
}
+
if headType != wantType {
t.Fatalf("ReadHeader type = %v, want %v", headType, wantType)
}
+
if headSize != int64(len(wantBody)) {
t.Fatalf("ReadHeader size = %d, want %d", headSize, len(wantBody))
}
@@ -71,7 +76,9 @@ func TestLooseStoreReadAgainstGit(t *testing.T) {
if err != nil {
t.Fatalf("ReadReaderFull: %v", err)
}
- if got := mustReadAllAndClose(t, fullReader); !bytes.Equal(got, wantRaw) {
+
+ got := mustReadAllAndClose(t, fullReader)
+ if !bytes.Equal(got, wantRaw) {
t.Fatalf("ReadReaderFull stream mismatch")
}
@@ -79,13 +86,17 @@ func TestLooseStoreReadAgainstGit(t *testing.T) {
if err != nil {
t.Fatalf("ReadReaderContent: %v", err)
}
+
if contentType != wantType {
t.Fatalf("ReadReaderContent type = %v, want %v", contentType, wantType)
}
+
if contentSize != int64(len(wantBody)) {
t.Fatalf("ReadReaderContent size = %d, want %d", contentSize, len(wantBody))
}
- if got := mustReadAllAndClose(t, contentReader); !bytes.Equal(got, wantBody) {
+
+ got = mustReadAllAndClose(t, contentReader)
+ if !bytes.Equal(got, wantBody) {
t.Fatalf("ReadReaderContent stream mismatch")
}
})
@@ -104,19 +115,28 @@ func TestLooseStoreErrors(t *testing.T) {
t.Fatalf("ParseHex(notFoundID): %v", err)
}
- if _, err := store.ReadBytesFull(notFoundID); !errors.Is(err, objectstore.ErrObjectNotFound) {
+ _, err = store.ReadBytesFull(notFoundID)
+ if !errors.Is(err, objectstore.ErrObjectNotFound) {
t.Fatalf("ReadBytesFull not-found error = %v", err)
}
- if _, _, err := store.ReadBytesContent(notFoundID); !errors.Is(err, objectstore.ErrObjectNotFound) {
+
+ _, _, err = store.ReadBytesContent(notFoundID)
+ if !errors.Is(err, objectstore.ErrObjectNotFound) {
t.Fatalf("ReadBytesContent not-found error = %v", err)
}
- if _, err := store.ReadReaderFull(notFoundID); !errors.Is(err, objectstore.ErrObjectNotFound) {
+
+ _, err = store.ReadReaderFull(notFoundID)
+ if !errors.Is(err, objectstore.ErrObjectNotFound) {
t.Fatalf("ReadReaderFull not-found error = %v", err)
}
- if _, _, _, err := store.ReadReaderContent(notFoundID); !errors.Is(err, objectstore.ErrObjectNotFound) {
+
+ _, _, _, err = store.ReadReaderContent(notFoundID)
+ if !errors.Is(err, objectstore.ErrObjectNotFound) {
t.Fatalf("ReadReaderContent not-found error = %v", err)
}
- if _, _, err := store.ReadHeader(notFoundID); !errors.Is(err, objectstore.ErrObjectNotFound) {
+
+ _, _, err = store.ReadHeader(notFoundID)
+ if !errors.Is(err, objectstore.ErrObjectNotFound) {
t.Fatalf("ReadHeader not-found error = %v", err)
}
@@ -126,12 +146,14 @@ func TestLooseStoreErrors(t *testing.T) {
} else {
otherAlgo = objectid.AlgorithmSHA1
}
+
otherID, err := objectid.ParseHex(otherAlgo, strings.Repeat("1", otherAlgo.HexLen()))
if err != nil {
t.Fatalf("ParseHex(otherID): %v", err)
}
- if _, err := store.ReadBytesFull(otherID); err == nil || !strings.Contains(err.Error(), "algorithm mismatch") {
+ _, err = store.ReadBytesFull(otherID)
+ if err == nil || !strings.Contains(err.Error(), "algorithm mismatch") {
t.Fatalf("ReadBytesFull algorithm-mismatch error = %v", err)
}
})
@@ -139,13 +161,16 @@ func TestLooseStoreErrors(t *testing.T) {
func TestLooseStoreNewValidation(t *testing.T) {
t.Parallel()
+
root, err := os.OpenRoot(t.TempDir())
if err != nil {
t.Fatalf("OpenRoot: %v", err)
}
+
defer func() { _ = root.Close() }()
- if _, err := loose.New(root, objectid.AlgorithmUnknown); err == nil {
+ _, err = loose.New(root, objectid.AlgorithmUnknown)
+ if err == nil {
t.Fatalf("loose.New(root, unknown) expected error")
}
}