From 9638e52d26d568a6598ce599da2b6726b9f541b9 Mon Sep 17 00:00:00 2001 From: Shane C Date: Wed, 20 Nov 2024 12:27:45 -0500 Subject: [PATCH] move s3 and local test to their own files --- local_test.go | 83 +++++++++++++++++++++++++++++++++++ storage_test.go => s3_test.go | 75 ------------------------------- 2 files changed, 83 insertions(+), 75 deletions(-) create mode 100644 local_test.go rename storage_test.go => s3_test.go (52%) diff --git a/local_test.go b/local_test.go new file mode 100644 index 0000000..365af65 --- /dev/null +++ b/local_test.go @@ -0,0 +1,83 @@ +package fsys + +import ( + "github.com/stretchr/testify/assert" + "io" + "io/fs" + "testing" +) + +func TestStorageLocal(t *testing.T) { + + stor, err := New(Config{ + Type: "local", + Path: "./test/local", + }) + assert.NoError(t, err) + + t.Log("== Write ==") + + err = stor.Write("test.txt", []byte("hi"), WriteOptions{}) + assert.NoError(t, err) + + err = stor.Write("testing/1.txt", []byte("hi"), WriteOptions{}) + assert.NoError(t, err) + err = stor.Write("testing/2.txt", []byte("hi"), WriteOptions{}) + assert.NoError(t, err) + err = stor.Write("testing/test/2.txt", []byte("hi"), WriteOptions{}) + assert.NoError(t, err) + t.Log("== Stat ==") + fileInfo, err := stor.Stat("test.txt") + assert.NoError(t, err) + assert.Equal(t, "test.txt", fileInfo.Name) + assert.Equal(t, int64(len("hi")), fileInfo.Size) + assert.Equal(t, fs.FileMode(0600), fileInfo.Mode) + + t.Log("== Read ==") + fileContent, err := stor.Read("test.txt") + assert.NoError(t, err) + assert.Equal(t, []byte("hi"), fileContent) + + t.Log("== ReadDir ==") + + files, err := stor.ReadDir("testing") + assert.NoError(t, err) + assert.Equal(t, 3, len(files)) + + t.Log("== Copy ==") + err = stor.Copy("test.txt", "test2.txt") + assert.NoError(t, err) + + copyFileInfo, err := stor.Stat("test2.txt") + assert.NoError(t, err) + assert.Equal(t, fs.FileMode(0600), copyFileInfo.Mode) + assert.Equal(t, "test2.txt", copyFileInfo.Name) + assert.Equal(t, int64(len("hi")), copyFileInfo.Size) + + t.Log("== Move ==") + err = stor.Move("test2.txt", "test3.txt") + assert.NoError(t, err) + + moveFileInfo, err := stor.Stat("test3.txt") + assert.NoError(t, err) + assert.Equal(t, fs.FileMode(0600), moveFileInfo.Mode) + assert.Equal(t, "test3.txt", moveFileInfo.Name) + assert.Equal(t, int64(len("hi")), moveFileInfo.Size) + + t.Log("== Open ==") + file, err := stor.Open("test.txt") + assert.NoError(t, err) + assert.Equal(t, "test.txt", file.Name) + + fileContent, err = io.ReadAll(file) + assert.NoError(t, err) + assert.Equal(t, []byte("hi"), fileContent) + + err = file.Close() + assert.NoError(t, err) + + t.Log("== Delete ==") + err = stor.Delete("test.txt") + assert.NoError(t, err) + +} diff --git a/storage_test.go b/s3_test.go similarity index 52% rename from storage_test.go rename to s3_test.go index 58bf5c9..9935d64 100644 --- a/storage_test.go +++ b/s3_test.go @@ -7,81 +7,6 @@ import ( "testing" ) -func TestStorageLocal(t *testing.T) { - - stor, err := New(Config{ - Type: "local", - Path: "./test/local", - }) - assert.NoError(t, err) - - t.Log("== Write ==") - - err = stor.Write("test.txt", []byte("hi"), WriteOptions{}) - assert.NoError(t, err) - - err = stor.Write("testing/1.txt", []byte("hi"), WriteOptions{}) - assert.NoError(t, err) - err = stor.Write("testing/2.txt", []byte("hi"), WriteOptions{}) - assert.NoError(t, err) - err = stor.Write("testing/test/2.txt", []byte("hi"), WriteOptions{}) - assert.NoError(t, err) - t.Log("== Stat ==") - fileInfo, err := stor.Stat("test.txt") - assert.NoError(t, err) - assert.Equal(t, "test.txt", fileInfo.Name) - assert.Equal(t, int64(len("hi")), fileInfo.Size) - assert.Equal(t, fs.FileMode(0600), fileInfo.Mode) - - t.Log("== Read ==") - fileContent, err := stor.Read("test.txt") - assert.NoError(t, err) - assert.Equal(t, []byte("hi"), fileContent) - - t.Log("== ReadDir ==") - - files, err := stor.ReadDir("testing") - assert.NoError(t, err) - assert.Equal(t, 3, len(files)) - - t.Log("== Copy ==") - err = stor.Copy("test.txt", "test2.txt") - assert.NoError(t, err) - - copyFileInfo, err := stor.Stat("test2.txt") - assert.NoError(t, err) - assert.Equal(t, fs.FileMode(0600), copyFileInfo.Mode) - assert.Equal(t, "test2.txt", copyFileInfo.Name) - assert.Equal(t, int64(len("hi")), copyFileInfo.Size) - - t.Log("== Move ==") - err = stor.Move("test2.txt", "test3.txt") - assert.NoError(t, err) - - moveFileInfo, err := stor.Stat("test3.txt") - assert.NoError(t, err) - assert.Equal(t, fs.FileMode(0600), moveFileInfo.Mode) - assert.Equal(t, "test3.txt", moveFileInfo.Name) - assert.Equal(t, int64(len("hi")), moveFileInfo.Size) - - t.Log("== Open ==") - file, err := stor.Open("test.txt") - assert.NoError(t, err) - assert.Equal(t, "test.txt", file.Name) - - fileContent, err = io.ReadAll(file) - assert.NoError(t, err) - assert.Equal(t, []byte("hi"), fileContent) - - err = file.Close() - assert.NoError(t, err) - - t.Log("== Delete ==") - err = stor.Delete("test.txt") - assert.NoError(t, err) - -} - func TestStorageS3(t *testing.T) { stor, err := New(Config{