Skip to content

Commit

Permalink
Add test to see if we get the size back for the file
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatskaari committed Nov 15, 2023
1 parent a8789a7 commit 503560e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/remote/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ type dir struct {
*info
}

// ReadDir is a slightly incorrect implementation of ReadDir. It deviates slightly as it will report all files have 0
// size. This seems to work for our limited purposes though.
// ReadDir implements listing the contents of a directory stored in the CAS. This is entirely based off the original
// data from the Tree proto so doesn't do any additional fetching.
func (p *dir) ReadDir(n int) ([]iofs.DirEntry, error) {
dirSize := n
if n <= 0 {
Expand Down
10 changes: 7 additions & 3 deletions src/remote/fs/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/stretchr/testify/require"
)

var fooContent = "wibble wibble wibble"

type fakeClient struct {
results map[digest.Digest][]byte
}
Expand All @@ -39,8 +41,7 @@ func newDigest(str string) digest.Digest {
// |- badlink (a symlink to ../../foo which is root/.. i.e. invalid)
func getTree(t *testing.T) (*fakeClient, *pb.Tree) {
t.Helper()

fooDigest := newDigest("foo")
fooDigest := newDigest(fooContent)

foo := &pb.FileNode{
Name: "foo",
Expand Down Expand Up @@ -120,7 +121,7 @@ func getTree(t *testing.T) (*fakeClient, *pb.Tree) {

fc := &fakeClient{
results: map[digest.Digest][]byte{
fooDigest: []byte("wibble wibble wibble"),
fooDigest: []byte(fooContent),
},
}
tree := &pb.Tree{
Expand All @@ -146,6 +147,9 @@ func TestReadDir(t *testing.T) {
require.NoError(t, err)
// We set them all to 0777 above
assert.Equal(t, iofs.FileMode(0777), i.Mode(), "%v mode was wrong", e.Name())
if e.Name() == "foo" {
assert.Equal(t, len([]byte(fooContent)), int(i.Size()))
}
}

entries, err = iofs.ReadDir(fs, ".")
Expand Down

0 comments on commit 503560e

Please sign in to comment.