create basic controller
This commit is contained in:
+14
-20
@@ -6,35 +6,33 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/iliadenisov/galaxy/pkg/util"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewFileStorageSuccess(t *testing.T) {
|
||||
root, cleanup := createWorkDir(t)
|
||||
root, cleanup := util.CreateWorkDir(t)
|
||||
defer cleanup()
|
||||
_, err := NewFileStorage(root)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestLock(t *testing.T) {
|
||||
root, cleanup := createWorkDir(t)
|
||||
root, cleanup := util.CreateWorkDir(t)
|
||||
defer cleanup()
|
||||
fs, err := NewFileStorage(root)
|
||||
assert.NoError(t, err, "create file storage")
|
||||
unlock, err := fs.Lock()
|
||||
assert.NoError(t, err, "acquire lock")
|
||||
exists, err := fileExists(filepath.Join(root, lockFile))
|
||||
assert.NoError(t, err, "check that the lock file should exist")
|
||||
assert.True(t, exists, "lock file must exists")
|
||||
lockPath := filepath.Join(root, lockFile)
|
||||
assert.FileExists(t, lockPath, "lock file should be created")
|
||||
err = unlock()
|
||||
assert.NoError(t, err, "unlocking existing lock")
|
||||
exists, err = fileExists(filepath.Join(root, lockFile))
|
||||
assert.NoError(t, err, "check that the lock file does not exist")
|
||||
assert.False(t, exists, "lock file must be removed")
|
||||
assert.NoFileExists(t, lockPath, "lock file must be removed")
|
||||
}
|
||||
|
||||
func TestExist(t *testing.T) {
|
||||
root, cleanup := createWorkDir(t)
|
||||
root, cleanup := util.CreateWorkDir(t)
|
||||
defer cleanup()
|
||||
|
||||
fileName := "some-file.ext"
|
||||
@@ -45,17 +43,17 @@ func TestExist(t *testing.T) {
|
||||
fs, err := NewFileStorage(root)
|
||||
assert.NoError(t, err, "create file storage")
|
||||
|
||||
exist, err := fs.Exist(fileName)
|
||||
exist, err := fs.Exists(fileName)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, exist)
|
||||
|
||||
exist, err = fs.Exist("random/path")
|
||||
exist, err = fs.Exists("random/path")
|
||||
assert.NoError(t, err)
|
||||
assert.False(t, exist)
|
||||
}
|
||||
|
||||
func TestWrite(t *testing.T) {
|
||||
root, cleanup := createWorkDir(t)
|
||||
root, cleanup := util.CreateWorkDir(t)
|
||||
defer cleanup()
|
||||
fs, err := NewFileStorage(root)
|
||||
assert.NoError(t, err, "create file storage: %s", err)
|
||||
@@ -85,9 +83,7 @@ func TestWrite(t *testing.T) {
|
||||
if err != nil {
|
||||
assert.Fail(t, "not expecting an error", "write to file %s: %s", tc.path, err)
|
||||
} else {
|
||||
exists, err := fileExists(filepath.Join(root, tc.path))
|
||||
assert.NoError(t, err, "check is written file exists")
|
||||
assert.True(t, exists, "the written file should exist")
|
||||
assert.FileExists(t, filepath.Join(root, tc.path), "the written file should exist")
|
||||
}
|
||||
} else if tc.err != "" {
|
||||
if err == nil {
|
||||
@@ -104,7 +100,7 @@ func TestWrite(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRead(t *testing.T) {
|
||||
root, cleanup := createWorkDir(t)
|
||||
root, cleanup := util.CreateWorkDir(t)
|
||||
defer cleanup()
|
||||
fs, err := NewFileStorage(root)
|
||||
assert.NoError(t, err, "create file storage: %s", err)
|
||||
@@ -150,9 +146,7 @@ func TestRead(t *testing.T) {
|
||||
if err != nil {
|
||||
assert.Fail(t, "read: not expecting an error, got: "+err.Error())
|
||||
} else {
|
||||
exists, err := fileExists(filepath.Join(root, tc.path))
|
||||
assert.NoError(t, err, "check is written file exists")
|
||||
assert.True(t, exists, "the written file should exist")
|
||||
assert.FileExists(t, filepath.Join(root, tc.path), "the written file should exist")
|
||||
}
|
||||
} else if tc.err != "" {
|
||||
if err == nil {
|
||||
@@ -166,7 +160,7 @@ func TestRead(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWriteErrorWithoutLock(t *testing.T) {
|
||||
root, cleanup := createWorkDir(t)
|
||||
root, cleanup := util.CreateWorkDir(t)
|
||||
defer cleanup()
|
||||
fs, err := NewFileStorage(root)
|
||||
assert.NoError(t, err, "create file storage")
|
||||
|
||||
Reference in New Issue
Block a user