Skip to content

Commit

Permalink
Add test case for the EOF error with ReadAt
Browse files Browse the repository at this point in the history
  • Loading branch information
0xff8 authored and dguerri committed Sep 2, 2023
1 parent a8da9a8 commit a3932df
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions cmd/satellite/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"fmt"
"io"
"io/fs"
"os"
"syscall"
Expand Down Expand Up @@ -705,10 +706,11 @@ func TestRead(t *testing.T) {
// *** Setup
dfFSOps := NewDockerFuseFSOps()
var (
mFS mockFS
mFile mockFile
reply rpccommon.ReadReply
err error
mFS mockFS
mFile mockFile
reply rpccommon.ReadReply
err error
offset int64
)
dfFS = &mFS // Set mock filesystem

Expand Down Expand Up @@ -763,6 +765,29 @@ func TestRead(t *testing.T) {
assert.NoError(t, err)
mFile.AssertExpectations(t)
assert.Equal(t, rpccommon.ReadReply{Data: []byte{3, 4, 5, 6, 7}}, reply)

// *** Testing small file on ReadAt
// size of the buffer > data we actually have in file
mFS = mockFS{}
mFile = mockFile{}
reply = rpccommon.ReadReply{}
offset = 0
mFile.On("ReadAt", make([]byte, 32), int64(offset)).Return(5, io.EOF).Run(
func(args mock.Arguments) {
data := args.Get(0).([]byte)
// num := args.Get(1).(int64)
for i := 0; i < 5; i++ { // our file is 5 bytes long
data[i] = byte(i + 1)
}
},
)
dfFSOps.fds = map[uintptr]file{29: &mFile}

err = dfFSOps.Read(rpccommon.ReadRequest{FD: 29, Offset: offset, Num: 32}, &reply)

assert.NoError(t, err)
mFile.AssertExpectations(t)
assert.Equal(t, rpccommon.ReadReply{Data: []byte{1, 2, 3, 4, 5}}, reply)
}

func TestSeek(t *testing.T) {
Expand Down

0 comments on commit a3932df

Please sign in to comment.