Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test case for the EOF error with ReadAt #7

Merged
merged 1 commit into from
Sep 2, 2023
Merged
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
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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: remove :)

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
Loading