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

Generic Multipart reader/writer implementaion #53

Merged
merged 19 commits into from
Mar 11, 2024
Prev Previous commit
Next Next commit
update deps
  • Loading branch information
sverdlov93 committed Mar 10, 2024
commit f2deb38e19f95fc6b14d8f3567c56f9b9b110885
14 changes: 8 additions & 6 deletions http/filestream/filestream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ import (

var targetDir string

func TestReadFilesFromStream(t *testing.T) {
func TestWriteFilesToStreamAndReadFilesFromStream(t *testing.T) {
sourceDir := t.TempDir()

// Create 2 file to be transferred via our multipart stream
file1 := filepath.Join(sourceDir, "test1.txt")
file2 := filepath.Join(sourceDir, "test2.txt")
Expand All @@ -42,19 +41,22 @@ func TestReadFilesFromStream(t *testing.T) {
assert.NoError(t, ReadFilesFromStream(multipartReader, fileHandlerWithHashValidation))

// Validate file 1 transferred successfully
content, err := os.ReadFile(filepath.Join(targetDir, "test1.txt"))
file1 = filepath.Join(targetDir, "test1.txt")
assert.FileExists(t, file1)
content, err := os.ReadFile(file1)
assert.NoError(t, err)
assert.Equal(t, file1Content, content)

// Validate file 2 transferred successfully
content, err = os.ReadFile(filepath.Join(targetDir, "test2.txt"))
file2 = filepath.Join(targetDir, "test2.txt")
assert.FileExists(t, file2)
content, err = os.ReadFile(file2)
assert.NoError(t, err)
assert.Equal(t, file2Content, content)

}

func simpleFileHandler(fileName string) (fileWriter io.Writer, err error) {
return os.Create(filepath.Join(targetDir, fileName))
return os.OpenFile(filepath.Join(targetDir, fileName), os.O_RDWR|os.O_CREATE, 0777)
}

func fileHandlerWithHashValidation(fileName string) (fileWriter io.Writer, err error) {
Expand Down
Loading