Skip to content

Commit

Permalink
B-22056 - more tests for memory and filesystem.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-mchugh committed Jan 17, 2025
1 parent 80cf552 commit 0f0f6d4
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
43 changes: 43 additions & 0 deletions pkg/storage/filesystem_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package storage

import (
"io"
"strings"
"testing"
)
Expand All @@ -23,6 +24,48 @@ func TestFilesystemPresignedURL(t *testing.T) {
}
}

func TestFilesystemReturnsSuccessful(t *testing.T) {
fsParams := FilesystemParams{
root: "./",
webRoot: "https://example.text/files",
}
filesystem := NewFilesystem(fsParams)
if filesystem == nil {
t.Fatal("could not create new filesystem")
}

storeValue := strings.NewReader("anyValue")
_, err := filesystem.Store("anyKey", storeValue, "", nil)
if err != nil {
t.Fatalf("could not store in filesystem: %s", err)
}

retReader, err := filesystem.Fetch("anyKey")
if err != nil {
t.Fatalf("could not fetch from filesystem: %s", err)
}

err = filesystem.Delete("anyKey")
if err != nil {
t.Fatalf("could not delete on filesystem: %s", err)
}

retValue, err := io.ReadAll(retReader)
if strings.Compare(string(retValue[:]), "anyValue") != 0 {
t.Fatalf("could not fetch from filesystem: %s", err)
}

fileSystem := filesystem.FileSystem()
if fileSystem == nil {
t.Fatal("could not retrieve filesystem from filesystem")
}

tempFileSystem := filesystem.TempFileSystem()
if tempFileSystem == nil {
t.Fatal("could not retrieve filesystem from filesystem")
}
}

func TestFilesystemTags(t *testing.T) {
fsParams := FilesystemParams{
root: "/home/username",
Expand Down
43 changes: 43 additions & 0 deletions pkg/storage/memory_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package storage

import (
"io"
"strings"
"testing"
)
Expand All @@ -23,6 +24,48 @@ func TestMemoryPresignedURL(t *testing.T) {
}
}

func TestMemoryReturnsSuccessful(t *testing.T) {
fsParams := MemoryParams{
root: "/home/username",
webRoot: "https://example.text/files",
}
memory := NewMemory(fsParams)
if memory == nil {
t.Fatal("could not create new memory")
}

storeValue := strings.NewReader("anyValue")
_, err := memory.Store("anyKey", storeValue, "", nil)
if err != nil {
t.Fatalf("could not store in memory: %s", err)
}

retReader, err := memory.Fetch("anyKey")
if err != nil {
t.Fatalf("could not fetch from memory: %s", err)
}

err = memory.Delete("anyKey")
if err != nil {
t.Fatalf("could not delete on memory: %s", err)
}

retValue, err := io.ReadAll(retReader)
if strings.Compare(string(retValue[:]), "anyValue") != 0 {
t.Fatalf("could not fetch from memory: %s", err)
}

fileSystem := memory.FileSystem()
if fileSystem == nil {
t.Fatal("could not retrieve filesystem from memory")
}

tempFileSystem := memory.TempFileSystem()
if tempFileSystem == nil {
t.Fatal("could not retrieve filesystem from memory")
}
}

func TestMemoryTags(t *testing.T) {
fsParams := MemoryParams{
root: "/home/username",
Expand Down

0 comments on commit 0f0f6d4

Please sign in to comment.