Skip to content

Commit

Permalink
Add unit test for file append
Browse files Browse the repository at this point in the history
  • Loading branch information
jfantinhardesty committed Nov 18, 2024
1 parent ea9d431 commit 6131e3a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/handlemap/handle_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ const InvalidHandleID HandleID = 0

// Flags represented in BitMap for various flags in the handle
const (
HandleFlagUnknown uint16 = iota
HandleFlagDirty // File has been modified with write operation or is a new file
HandleFlagFSynced // User has called fsync on the file explicitly
HandleFlagCached // File is cached in the local system by cloudfuse
HandleFlagUnknown uint16 = iota
HandleFlagDirty // File has been modified with write operation or is a new file
HandleFlagFSynced // User has called fsync on the file explicitly
HandleFlagCached // File is cached in the local system by cloudfuse
HandleOpenedAppend // File is opened for Append
)

// Structure to hold in memory cache for streaming layer
Expand Down
28 changes: 28 additions & 0 deletions test/e2e_tests/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,34 @@ func (suite *fileTestSuite) TestFileCreateLabel() {
suite.fileTestCleanup([]string{fileName})
}

func (suite *fileTestSuite) TestFileAppend() {
fileName := filepath.Join(suite.testPath, "append_test.txt")
initialContent := []byte("Initial content\n")
appendContent := []byte("Appended content\n")

// Create and write initial content to the file
srcFile, err := os.OpenFile(fileName, os.O_CREATE|os.O_WRONLY, 0777)
suite.NoError(err)
_, err = srcFile.Write(initialContent)
suite.NoError(err)
srcFile.Close()

// Open the file with O_APPEND and append new content
appendFile, err := os.OpenFile(fileName, os.O_APPEND|os.O_WRONLY, 0777)
suite.NoError(err)
_, err = appendFile.Write(appendContent)
suite.NoError(err)
appendFile.Close()

// Read the file and verify the content
data, err := os.ReadFile(fileName)
suite.NoError(err)
expectedContent := append(initialContent, appendContent...)
suite.Equal(expectedContent, data)

suite.fileTestCleanup([]string{fileName})
}

// # Write a small file
func (suite *fileTestSuite) TestFileWriteSmall() {
fileName := filepath.Join(suite.testPath, "small_write.txt")
Expand Down

0 comments on commit 6131e3a

Please sign in to comment.