|
|
@ -2,16 +2,14 @@ package dataswamp
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"bytes"
|
|
|
|
"caj-larsson/bog/dataswamp/namespace"
|
|
|
|
|
|
|
|
"caj-larsson/bog/dataswamp/swampfile"
|
|
|
|
"caj-larsson/bog/dataswamp/swampfile"
|
|
|
|
m_namespace "caj-larsson/bog/infrastructure/memory/namespace"
|
|
|
|
|
|
|
|
m_swampfile "caj-larsson/bog/infrastructure/memory/swampfile"
|
|
|
|
|
|
|
|
"caj-larsson/bog/infrastructure/system_time"
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/matryer/is"
|
|
|
|
"github.com/matryer/is"
|
|
|
|
"github.com/spf13/afero"
|
|
|
|
"github.com/spf13/afero"
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
// "caj-larsson/bog/dataswamp/namespace"
|
|
|
|
|
|
|
|
m_namespace "caj-larsson/bog/infrastructure/memory/namespace"
|
|
|
|
|
|
|
|
m_swampfile "caj-larsson/bog/infrastructure/memory/swampfile"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type TestLogger struct{}
|
|
|
|
type TestLogger struct{}
|
|
|
@ -24,25 +22,15 @@ var file_ref1 = swampfile.FileReference{"/path1", "ns1"}
|
|
|
|
var file_ref2 = swampfile.FileReference{"/path1", "ns2"}
|
|
|
|
var file_ref2 = swampfile.FileReference{"/path1", "ns2"}
|
|
|
|
var file_ref3 = swampfile.FileReference{"/path2", "ns1"}
|
|
|
|
var file_ref3 = swampfile.FileReference{"/path2", "ns1"}
|
|
|
|
|
|
|
|
|
|
|
|
func NewTestDataSwampService() DataSwampService {
|
|
|
|
func NewTestSwampFileService() SwampFileService {
|
|
|
|
file_repo := m_swampfile.NewRepository()
|
|
|
|
file_repo := m_swampfile.NewRepository()
|
|
|
|
ns_repo := m_namespace.NewRepository()
|
|
|
|
ns_repo := m_namespace.NewRepository()
|
|
|
|
|
|
|
|
return NewSwampFileService(ns_repo, file_repo, 1024, time.Hour, TestLogger{})
|
|
|
|
logger := TestLogger{}
|
|
|
|
|
|
|
|
ns_svc := namespace.NewNamespaceService(
|
|
|
|
|
|
|
|
ns_repo,
|
|
|
|
|
|
|
|
logger,
|
|
|
|
|
|
|
|
system_time.Clock{},
|
|
|
|
|
|
|
|
time.Hour,
|
|
|
|
|
|
|
|
1024,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return *NewDataSwampService(*ns_svc, file_repo, logger)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestFileDontExist(t *testing.T) {
|
|
|
|
func TestFileDontExist(t *testing.T) {
|
|
|
|
is := is.New(t)
|
|
|
|
is := is.New(t)
|
|
|
|
s := NewTestDataSwampService()
|
|
|
|
s := NewTestSwampFileService()
|
|
|
|
outfile, err := s.OpenOutFile(file_ref1)
|
|
|
|
outfile, err := s.OpenOutFile(file_ref1)
|
|
|
|
|
|
|
|
|
|
|
|
is.True(err == swampfile.ErrNotExists)
|
|
|
|
is.True(err == swampfile.ErrNotExists)
|
|
|
@ -51,7 +39,7 @@ func TestFileDontExist(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestFileIsStored(t *testing.T) {
|
|
|
|
func TestFileIsStored(t *testing.T) {
|
|
|
|
is := is.New(t)
|
|
|
|
is := is.New(t)
|
|
|
|
s := NewTestDataSwampService()
|
|
|
|
s := NewTestSwampFileService()
|
|
|
|
|
|
|
|
|
|
|
|
fakefile := bytes.NewBufferString("My bog data")
|
|
|
|
fakefile := bytes.NewBufferString("My bog data")
|
|
|
|
|
|
|
|
|
|
|
@ -72,7 +60,7 @@ func TestFileIsStored(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestFileIsReadBack(t *testing.T) {
|
|
|
|
func TestFileIsReadBack(t *testing.T) {
|
|
|
|
is := is.New(t)
|
|
|
|
is := is.New(t)
|
|
|
|
s := NewTestDataSwampService()
|
|
|
|
s := NewTestSwampFileService()
|
|
|
|
|
|
|
|
|
|
|
|
infile := bytes.NewBufferString("My bog data")
|
|
|
|
infile := bytes.NewBufferString("My bog data")
|
|
|
|
|
|
|
|
|
|
|
@ -88,7 +76,7 @@ func TestFileIsReadBack(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestNSIsolation(t *testing.T) {
|
|
|
|
func TestNSIsolation(t *testing.T) {
|
|
|
|
is := is.New(t)
|
|
|
|
is := is.New(t)
|
|
|
|
s := NewTestDataSwampService()
|
|
|
|
s := NewTestSwampFileService()
|
|
|
|
|
|
|
|
|
|
|
|
ns1_file := bytes.NewBufferString("My bog data ns1")
|
|
|
|
ns1_file := bytes.NewBufferString("My bog data ns1")
|
|
|
|
ns2_file := bytes.NewBufferString("My bog data ns2")
|
|
|
|
ns2_file := bytes.NewBufferString("My bog data ns2")
|
|
|
@ -106,7 +94,7 @@ func TestNSIsolation(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestPathStrictMode(t *testing.T) {
|
|
|
|
func TestPathStrictMode(t *testing.T) {
|
|
|
|
is := is.New(t)
|
|
|
|
is := is.New(t)
|
|
|
|
s := NewTestDataSwampService()
|
|
|
|
s := NewTestSwampFileService()
|
|
|
|
|
|
|
|
|
|
|
|
ns_file := bytes.NewBufferString("My bog data ns1")
|
|
|
|
ns_file := bytes.NewBufferString("My bog data ns1")
|
|
|
|
|
|
|
|
|
|
|
@ -126,7 +114,7 @@ func TestPathStrictMode(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestQuotaWithContenSizeLieOver(t *testing.T) {
|
|
|
|
func TestQuotaWithContenSizeLieOver(t *testing.T) {
|
|
|
|
is := is.New(t)
|
|
|
|
is := is.New(t)
|
|
|
|
s := NewTestDataSwampService()
|
|
|
|
s := NewTestSwampFileService()
|
|
|
|
|
|
|
|
|
|
|
|
largefakefile := bytes.NewBufferString("")
|
|
|
|
largefakefile := bytes.NewBufferString("")
|
|
|
|
|
|
|
|
|
|
|
@ -141,7 +129,7 @@ func TestQuotaWithContenSizeLieOver(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestQuotaWithContenSizeLieUnder(t *testing.T) {
|
|
|
|
func TestQuotaWithContenSizeLieUnder(t *testing.T) {
|
|
|
|
is := is.New(t)
|
|
|
|
is := is.New(t)
|
|
|
|
s := NewTestDataSwampService()
|
|
|
|
s := NewTestSwampFileService()
|
|
|
|
|
|
|
|
|
|
|
|
largefakefile := bytes.NewBufferString("small")
|
|
|
|
largefakefile := bytes.NewBufferString("small")
|
|
|
|
|
|
|
|
|
|
|
@ -156,32 +144,22 @@ func TestCleanUpExpired(t *testing.T) {
|
|
|
|
fs := afero.NewMemMapFs()
|
|
|
|
fs := afero.NewMemMapFs()
|
|
|
|
file_repo := m_swampfile.Repository{fs}
|
|
|
|
file_repo := m_swampfile.Repository{fs}
|
|
|
|
ns_repo := m_namespace.NewRepository()
|
|
|
|
ns_repo := m_namespace.NewRepository()
|
|
|
|
logger := TestLogger{}
|
|
|
|
s := NewSwampFileService(ns_repo, file_repo, 1024, time.Hour, TestLogger{})
|
|
|
|
ns_svc := namespace.NewNamespaceService(
|
|
|
|
|
|
|
|
ns_repo,
|
|
|
|
|
|
|
|
logger,
|
|
|
|
|
|
|
|
system_time.Clock{},
|
|
|
|
|
|
|
|
time.Hour,
|
|
|
|
|
|
|
|
1024,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
s := NewDataSwampService(*ns_svc, file_repo, logger)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fakefile := bytes.NewBufferString("My bog")
|
|
|
|
fakefile := bytes.NewBufferString("My bog data")
|
|
|
|
err := s.SaveFile(file_ref1, fakefile, int64(fakefile.Len()))
|
|
|
|
err := s.SaveFile(file_ref1, fakefile, int64(fakefile.Len()))
|
|
|
|
is.NoErr(err)
|
|
|
|
is.NoErr(err)
|
|
|
|
|
|
|
|
|
|
|
|
fakefile = bytes.NewBufferString("My bog")
|
|
|
|
fakefile = bytes.NewBufferString("My bog data")
|
|
|
|
err = s.SaveFile(file_ref3, fakefile, int64(fakefile.Len()))
|
|
|
|
err = s.SaveFile(file_ref3, fakefile, int64(fakefile.Len()))
|
|
|
|
is.NoErr(err)
|
|
|
|
is.NoErr(err)
|
|
|
|
|
|
|
|
|
|
|
|
err = fs.Chtimes("1/path1", time.Now(), time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC))
|
|
|
|
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())
|
|
|
|
is.NoErr(s.CleanUpExpiredFiles())
|
|
|
|
|
|
|
|
|
|
|
|
ns, err := ns_repo.GetByName("ns1")
|
|
|
|
ns, err := ns_repo.GetByName("ns1")
|
|
|
|
fmt.Printf("file final usage %v\n", ns.FileQuota)
|
|
|
|
|
|
|
|
is.NoErr(err)
|
|
|
|
is.NoErr(err)
|
|
|
|
fmt.Printf("file\n")
|
|
|
|
|
|
|
|
is.Equal(ns.FileQuota.CurrentUsage, int64(len("My bog")))
|
|
|
|
is.Equal(ns.FileQuota.CurrentUsage, int64(len("My bog data")))
|
|
|
|
}
|
|
|
|
}
|
|
|
|