|
|
|
@ -4,6 +4,7 @@ import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"caj-larsson/bog/dataswamp/swampfile"
|
|
|
|
|
"github.com/matryer/is"
|
|
|
|
|
"github.com/spf13/afero"
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
// "caj-larsson/bog/dataswamp/namespace"
|
|
|
|
@ -11,7 +12,7 @@ import (
|
|
|
|
|
m_swampfile "caj-larsson/bog/infrastructure/memory/swampfile"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var file_ref1 = swampfile.FileReference{"/ptah1", "ns1"}
|
|
|
|
|
var file_ref1 = swampfile.FileReference{"/path1", "ns1"}
|
|
|
|
|
var file_ref2 = swampfile.FileReference{"/path1", "ns2"}
|
|
|
|
|
var file_ref3 = swampfile.FileReference{"/path2", "ns1"}
|
|
|
|
|
|
|
|
|
@ -85,7 +86,6 @@ func TestNSIsolation(t *testing.T) {
|
|
|
|
|
is.Equal(outfile.String(), "My bog data ns1")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestPathStrictMode(t *testing.T) {
|
|
|
|
|
is := is.New(t)
|
|
|
|
|
s := NewTestSwampFileService()
|
|
|
|
@ -106,7 +106,6 @@ func TestPathStrictMode(t *testing.T) {
|
|
|
|
|
is.Equal(err, swampfile.ErrUnacceptablePath)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestQuotaWithContenSizeLieOver(t *testing.T) {
|
|
|
|
|
is := is.New(t)
|
|
|
|
|
s := NewTestSwampFileService()
|
|
|
|
@ -122,7 +121,6 @@ func TestQuotaWithContenSizeLieOver(t *testing.T) {
|
|
|
|
|
is.Equal(err, swampfile.ErrContentSizeExceeded)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestQuotaWithContenSizeLieUnder(t *testing.T) {
|
|
|
|
|
is := is.New(t)
|
|
|
|
|
s := NewTestSwampFileService()
|
|
|
|
@ -133,3 +131,29 @@ func TestQuotaWithContenSizeLieUnder(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
is.Equal(err, swampfile.ErrContentSizeExaggerated)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestCleanUpExpired(t *testing.T) {
|
|
|
|
|
is := is.New(t)
|
|
|
|
|
|
|
|
|
|
fs := afero.NewMemMapFs()
|
|
|
|
|
file_repo := m_swampfile.Repository{fs}
|
|
|
|
|
ns_repo := m_namespace.NewRepository()
|
|
|
|
|
s := NewSwampFileService(ns_repo, file_repo, 1024, time.Hour)
|
|
|
|
|
|
|
|
|
|
fakefile := bytes.NewBufferString("My bog data")
|
|
|
|
|
err := s.SaveFile(file_ref1, fakefile, int64(fakefile.Len()))
|
|
|
|
|
is.NoErr(err)
|
|
|
|
|
|
|
|
|
|
fakefile = bytes.NewBufferString("My bog data")
|
|
|
|
|
err = s.SaveFile(file_ref3, fakefile, int64(fakefile.Len()))
|
|
|
|
|
is.NoErr(err)
|
|
|
|
|
|
|
|
|
|
err = fs.Chtimes("1/path1", time.Now(), time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC))
|
|
|
|
|
is.NoErr(err)
|
|
|
|
|
is.NoErr(s.CleanUpExpiredFiles())
|
|
|
|
|
|
|
|
|
|
ns, err := ns_repo.GetByName("ns1")
|
|
|
|
|
is.NoErr(err)
|
|
|
|
|
|
|
|
|
|
is.Equal(ns.FileQuota.CurrentUsage, int64(len("My bog data")))
|
|
|
|
|
}
|
|
|
|
|