mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-04 22:23:21 -04:00
fix test suite
This commit is contained in:
@@ -200,6 +200,28 @@ func (idx *NonUnique) Remove(id string, v string) error {
|
||||
return &idxerrs.NotFoundErr{TypeName: idx.typeName, Key: idx.indexBy, Value: v}
|
||||
}
|
||||
|
||||
toStat := path.Join("/meta", idx.indexRootDir, v)
|
||||
lcResp, err := idx.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{
|
||||
Ref: &provider.Reference{
|
||||
Spec: &provider.Reference_Path{Path: toStat},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(lcResp.Infos) == 0 {
|
||||
deletePath = path.Join("/meta", idx.indexRootDir, v)
|
||||
_, err := idx.storageProvider.Delete(ctx, &provider.DeleteRequest{
|
||||
Ref: &provider.Reference{
|
||||
Spec: &provider.Reference_Path{Path: deletePath},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,41 @@
|
||||
package cs3
|
||||
|
||||
import (
|
||||
"github.com/owncloud/ocis/accounts/pkg/config"
|
||||
"github.com/owncloud/ocis/accounts/pkg/indexer/option"
|
||||
. "github.com/owncloud/ocis/accounts/pkg/indexer/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCS3NonUniqueIndex_FakeSymlink(t *testing.T) {
|
||||
dataDir := WriteIndexTestDataCS3(t, TestData, "Id")
|
||||
sut := NewNonUniqueIndex("User", "Name", "/meta", "index.cs3", &Config{
|
||||
ProviderAddr: "0.0.0.0:9215",
|
||||
DataURL: "http://localhost:9216",
|
||||
DataPrefix: "data",
|
||||
JWTSecret: "Pive-Fumkiu4",
|
||||
ServiceUserName: "",
|
||||
ServiceUserUUID: "",
|
||||
})
|
||||
cfg := config.Config{
|
||||
Repo: config.Repo{
|
||||
Disk: config.Disk{
|
||||
Path: "",
|
||||
},
|
||||
CS3: config.CS3{
|
||||
ProviderAddr: "0.0.0.0:9215",
|
||||
DataURL: "http://localhost:9216",
|
||||
DataPrefix: "data",
|
||||
JWTSecret: "Pive-Fumkiu4",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
sut := NewNonUniqueIndexWithOptions(
|
||||
option.WithTypeName("test.Users.Cs3"),
|
||||
option.WithIndexBy("UserName"),
|
||||
option.WithFilesDir(path.Join(cfg.Repo.Disk.Path, "/meta")),
|
||||
option.WithDataDir(cfg.Repo.Disk.Path),
|
||||
option.WithDataURL(cfg.Repo.CS3.DataURL),
|
||||
option.WithDataPrefix(cfg.Repo.CS3.DataPrefix),
|
||||
option.WithJWTSecret(cfg.Repo.CS3.JWTSecret),
|
||||
option.WithProviderAddr(cfg.Repo.CS3.ProviderAddr),
|
||||
)
|
||||
|
||||
err := sut.Init()
|
||||
assert.NoError(t, err)
|
||||
@@ -25,28 +44,22 @@ func TestCS3NonUniqueIndex_FakeSymlink(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
t.Log(res)
|
||||
|
||||
_, err = sut.Add("abcdefg-234", "mikey")
|
||||
resLookup, err := sut.Lookup("mikey")
|
||||
assert.NoError(t, err)
|
||||
t.Log(res)
|
||||
t.Log(resLookup)
|
||||
|
||||
_, err = sut.Add("soasdioahsfash", "milo")
|
||||
err = sut.Update("abcdefg-123", "mikey", "mickeyX")
|
||||
assert.NoError(t, err)
|
||||
t.Log(res)
|
||||
|
||||
_, err = sut.Add("asdasdsa", "jonas")
|
||||
searchRes, err := sut.Search("m*")
|
||||
assert.NoError(t, err)
|
||||
t.Log(res)
|
||||
assert.Len(t, searchRes, 1)
|
||||
assert.Equal(t, searchRes[0], "abcdefg-123")
|
||||
|
||||
lookupRes, err := sut.Lookup("mikey")
|
||||
assert.NoError(t, err)
|
||||
t.Log(lookupRes)
|
||||
|
||||
searchRes, err := sut.Search("mi*")
|
||||
assert.NoError(t, err)
|
||||
t.Log(searchRes)
|
||||
|
||||
err = sut.Update("abcdefg-234", "mikey", "jonas")
|
||||
resp, err := sut.Lookup("mikey")
|
||||
assert.Len(t, resp, 0)
|
||||
assert.NoError(t, err)
|
||||
|
||||
_ = os.RemoveAll(dataDir)
|
||||
|
||||
}
|
||||
|
||||
@@ -1,22 +1,41 @@
|
||||
package cs3
|
||||
|
||||
import (
|
||||
"github.com/owncloud/ocis/accounts/pkg/config"
|
||||
"github.com/owncloud/ocis/accounts/pkg/indexer/option"
|
||||
. "github.com/owncloud/ocis/accounts/pkg/indexer/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCS3UniqueIndex_FakeSymlink(t *testing.T) {
|
||||
dataDir := WriteIndexTestDataCS3(t, TestData, "Id")
|
||||
sut := NewUniqueIndex("User", "UserName", "/meta", "index.cs3", &Config{
|
||||
ProviderAddr: "0.0.0.0:9215",
|
||||
DataURL: "http://localhost:9216",
|
||||
DataPrefix: "data",
|
||||
JWTSecret: "Pive-Fumkiu4",
|
||||
ServiceUserName: "",
|
||||
ServiceUserUUID: "",
|
||||
})
|
||||
cfg := config.Config{
|
||||
Repo: config.Repo{
|
||||
Disk: config.Disk{
|
||||
Path: "",
|
||||
},
|
||||
CS3: config.CS3{
|
||||
ProviderAddr: "0.0.0.0:9215",
|
||||
DataURL: "http://localhost:9216",
|
||||
DataPrefix: "data",
|
||||
JWTSecret: "Pive-Fumkiu4",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
sut := NewUniqueIndexWithOptions(
|
||||
option.WithTypeName("test.Users.Cs3"),
|
||||
option.WithIndexBy("UserName"),
|
||||
option.WithFilesDir(path.Join(cfg.Repo.Disk.Path, "/meta")),
|
||||
option.WithDataDir(cfg.Repo.Disk.Path),
|
||||
option.WithDataURL(cfg.Repo.CS3.DataURL),
|
||||
option.WithDataPrefix(cfg.Repo.CS3.DataPrefix),
|
||||
option.WithJWTSecret(cfg.Repo.CS3.JWTSecret),
|
||||
option.WithProviderAddr(cfg.Repo.CS3.ProviderAddr),
|
||||
)
|
||||
|
||||
err := sut.Init()
|
||||
assert.NoError(t, err)
|
||||
@@ -32,26 +51,40 @@ func TestCS3UniqueIndex_FakeSymlink(t *testing.T) {
|
||||
err = sut.Update("abcdefg-123", "mikey", "mickeyX")
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = sut.Search("mi*")
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = sut.Remove("", "mikey")
|
||||
searchRes, err := sut.Search("m*")
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, searchRes, 1)
|
||||
assert.Equal(t, searchRes[0], "abcdefg-123")
|
||||
|
||||
_ = os.RemoveAll(dataDir)
|
||||
|
||||
}
|
||||
|
||||
func TestCS3UniqueIndexSearch(t *testing.T) {
|
||||
dataDir := WriteIndexTestDataCS3(t, TestData, "Id")
|
||||
sut := NewUniqueIndex("User", "UserName", "/meta", "index.cs3", &Config{
|
||||
ProviderAddr: "0.0.0.0:9215",
|
||||
DataURL: "http://localhost:9216",
|
||||
DataPrefix: "data",
|
||||
JWTSecret: "Pive-Fumkiu4",
|
||||
ServiceUserName: "",
|
||||
ServiceUserUUID: "",
|
||||
})
|
||||
cfg := config.Config{
|
||||
Repo: config.Repo{
|
||||
Disk: config.Disk{
|
||||
Path: "",
|
||||
},
|
||||
CS3: config.CS3{
|
||||
ProviderAddr: "0.0.0.0:9215",
|
||||
DataURL: "http://localhost:9216",
|
||||
DataPrefix: "data",
|
||||
JWTSecret: "Pive-Fumkiu4",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
sut := NewUniqueIndexWithOptions(
|
||||
option.WithTypeName("test.Users.Cs3"),
|
||||
option.WithIndexBy("UserName"),
|
||||
option.WithFilesDir(path.Join(cfg.Repo.Disk.Path, "/meta")),
|
||||
option.WithDataDir(cfg.Repo.Disk.Path),
|
||||
option.WithDataURL(cfg.Repo.CS3.DataURL),
|
||||
option.WithDataPrefix(cfg.Repo.CS3.DataPrefix),
|
||||
option.WithJWTSecret(cfg.Repo.CS3.JWTSecret),
|
||||
option.WithProviderAddr(cfg.Repo.CS3.ProviderAddr),
|
||||
)
|
||||
|
||||
err := sut.Init()
|
||||
assert.NoError(t, err)
|
||||
@@ -67,5 +100,4 @@ func TestCS3UniqueIndexSearch(t *testing.T) {
|
||||
t.Log(res)
|
||||
|
||||
_ = os.RemoveAll(dataDir)
|
||||
|
||||
}
|
||||
|
||||
@@ -44,12 +44,12 @@ func NewNonUniqueIndexWithOptions(o ...option.Option) index.Index {
|
||||
opt(opts)
|
||||
}
|
||||
|
||||
return NonUniqueIndex{
|
||||
return &NonUniqueIndex{
|
||||
indexBy: opts.IndexBy,
|
||||
typeName: opts.TypeName,
|
||||
filesDir: opts.FilesDir,
|
||||
indexBaseDir: opts.IndexBaseDir,
|
||||
indexRootDir: path.Join(opts.IndexBaseDir, strings.Join([]string{"unique", opts.TypeName, opts.IndexBy}, ".")),
|
||||
indexBaseDir: path.Join(opts.DataDir, "index.disk"),
|
||||
indexRootDir: path.Join(path.Join(opts.DataDir, "index.disk"), strings.Join([]string{"non_unique", opts.TypeName, opts.IndexBy}, ".")),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package disk
|
||||
|
||||
import (
|
||||
"github.com/owncloud/ocis/accounts/pkg/config"
|
||||
"github.com/owncloud/ocis/accounts/pkg/indexer/errors"
|
||||
"github.com/owncloud/ocis/accounts/pkg/indexer/index"
|
||||
"github.com/owncloud/ocis/accounts/pkg/indexer/option"
|
||||
. "github.com/owncloud/ocis/accounts/pkg/indexer/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"os"
|
||||
@@ -11,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func TestNonUniqueIndexAdd(t *testing.T) {
|
||||
sut, dataPath := getNonUniqueIdxSut(t)
|
||||
sut, dataPath := getNonUniqueIdxSut(t, "Color")
|
||||
|
||||
ids, err := sut.Lookup("Green")
|
||||
assert.NoError(t, err)
|
||||
@@ -30,50 +32,31 @@ func TestNonUniqueIndexAdd(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNonUniqueIndexUpdate(t *testing.T) {
|
||||
sut, dataPath := getNonUniqueIdxSut(t)
|
||||
sut, dataPath := getNonUniqueIdxSut(t, "Color")
|
||||
|
||||
err := sut.Update("goefe-789", "", "Black")
|
||||
err := sut.Update("goefe-789", "Green", "Black")
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = sut.Update("xadaf-189", "", "Black")
|
||||
err = sut.Update("xadaf-189", "Green", "Black")
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.DirExists(t, path.Join(dataPath, "index.disk/PetByColor/Black"))
|
||||
assert.NoDirExists(t, path.Join(dataPath, "index.disk/PetByColor/Green"))
|
||||
assert.DirExists(t, path.Join(dataPath, "index.disk/non_unique.test.Users.Disk.Color/Black"))
|
||||
assert.NoDirExists(t, path.Join(dataPath, "index.disk/non_unique.test.Users.Disk.Color/Green"))
|
||||
|
||||
_ = os.RemoveAll(dataPath)
|
||||
}
|
||||
|
||||
func TestNonUniqueIndexDelete(t *testing.T) {
|
||||
sut, dataPath := getNonUniqueIdxSut(t)
|
||||
assert.FileExists(t, path.Join(dataPath, "index.disk/PetByColor/Green/goefe-789"))
|
||||
sut, dataPath := getNonUniqueIdxSut(t, "Color")
|
||||
assert.FileExists(t, path.Join(dataPath, "index.disk/non_unique.test.Users.Disk.Color/Green/goefe-789"))
|
||||
err := sut.Remove("goefe-789", "")
|
||||
assert.NoError(t, err)
|
||||
assert.NoFileExists(t, path.Join(dataPath, "index.disk/PetByColor/Green/goefe-789"))
|
||||
assert.NoFileExists(t, path.Join(dataPath, "index.disk/non_unique.test.Users.Disk.Color/Green/goefe-789"))
|
||||
_ = os.RemoveAll(dataPath)
|
||||
}
|
||||
|
||||
func TestNonUniqueIndexInit(t *testing.T) {
|
||||
dataDir := CreateTmpDir(t)
|
||||
indexRootDir := path.Join(dataDir, "index.disk")
|
||||
filesDir := path.Join(dataDir, "users")
|
||||
|
||||
uniq := NewNonUniqueIndex("User", "DisplayName", filesDir, indexRootDir)
|
||||
assert.Error(t, uniq.Init(), "Init should return an error about missing files-dir")
|
||||
|
||||
if err := os.Mkdir(filesDir, 0777); err != nil {
|
||||
t.Fatalf("Could not create test data-dir %s", err)
|
||||
}
|
||||
|
||||
assert.NoError(t, uniq.Init(), "Init shouldn't return an error")
|
||||
assert.DirExists(t, indexRootDir)
|
||||
assert.DirExists(t, path.Join(indexRootDir, "UserByDisplayName"))
|
||||
|
||||
_ = os.RemoveAll(dataDir)
|
||||
}
|
||||
|
||||
func TestNonUniqueIndexSearch(t *testing.T) {
|
||||
sut, dataPath := getNonUniqueIdxSut(t)
|
||||
sut, dataPath := getNonUniqueIdxSut(t, "Email")
|
||||
|
||||
res, err := sut.Search("Gr*")
|
||||
|
||||
@@ -90,9 +73,22 @@ func TestNonUniqueIndexSearch(t *testing.T) {
|
||||
_ = os.RemoveAll(dataPath)
|
||||
}
|
||||
|
||||
func getNonUniqueIdxSut(t *testing.T) (sut index.Index, dataPath string) {
|
||||
dataPath = WriteIndexTestData(t, TestData, "Id")
|
||||
sut = NewNonUniqueIndex("Pet", "Color", path.Join(dataPath, "pets"), path.Join(dataPath, "index.disk"))
|
||||
func getNonUniqueIdxSut(t *testing.T, indexBy string) (index.Index, string) {
|
||||
dataPath := WriteIndexTestData(t, TestData, "Id")
|
||||
cfg := config.Config{
|
||||
Repo: config.Repo{
|
||||
Disk: config.Disk{
|
||||
Path: dataPath,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
sut := NewNonUniqueIndexWithOptions(
|
||||
option.WithTypeName("test.Users.Disk"),
|
||||
option.WithIndexBy(indexBy),
|
||||
option.WithFilesDir(path.Join(cfg.Repo.Disk.Path, "pets")),
|
||||
option.WithDataDir(cfg.Repo.Disk.Path),
|
||||
)
|
||||
err := sut.Init()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -107,5 +103,5 @@ func getNonUniqueIdxSut(t *testing.T) (sut index.Index, dataPath string) {
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
return sut, dataPath
|
||||
}
|
||||
|
||||
@@ -53,15 +53,13 @@ func NewUniqueIndexWithOptions(o ...option.Option) index.Index {
|
||||
opt(opts)
|
||||
}
|
||||
|
||||
u := &Unique{
|
||||
return &Unique{
|
||||
indexBy: opts.IndexBy,
|
||||
typeName: opts.TypeName,
|
||||
filesDir: opts.FilesDir,
|
||||
indexBaseDir: path.Join(opts.DataDir, "index.disk"),
|
||||
indexRootDir: path.Join(path.Join(opts.DataDir, "index.disk"), strings.Join([]string{"unique", opts.TypeName, opts.IndexBy}, ".")),
|
||||
}
|
||||
|
||||
return u
|
||||
}
|
||||
|
||||
// NewUniqueIndex instantiates a new UniqueIndex instance. Init() should be
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package disk
|
||||
|
||||
import (
|
||||
"github.com/owncloud/ocis/accounts/pkg/config"
|
||||
"github.com/owncloud/ocis/accounts/pkg/indexer/errors"
|
||||
"github.com/owncloud/ocis/accounts/pkg/indexer/index"
|
||||
"github.com/owncloud/ocis/accounts/pkg/indexer/option"
|
||||
. "github.com/owncloud/ocis/accounts/pkg/indexer/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"os"
|
||||
@@ -11,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func TestUniqueLookupSingleEntry(t *testing.T) {
|
||||
uniq, dataDir := getUniqueIdxSut(t)
|
||||
uniq, dataDir := getUniqueIdxSut(t, "Email")
|
||||
filesDir := path.Join(dataDir, "users")
|
||||
|
||||
t.Log("existing lookup")
|
||||
@@ -31,7 +33,7 @@ func TestUniqueLookupSingleEntry(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUniqueUniqueConstraint(t *testing.T) {
|
||||
uniq, dataDir := getUniqueIdxSut(t)
|
||||
uniq, dataDir := getUniqueIdxSut(t, "Email")
|
||||
|
||||
_, err := uniq.Add("abcdefg-123", "mikey@example.com")
|
||||
assert.Error(t, err)
|
||||
@@ -41,7 +43,7 @@ func TestUniqueUniqueConstraint(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUniqueRemove(t *testing.T) {
|
||||
uniq, dataDir := getUniqueIdxSut(t)
|
||||
uniq, dataDir := getUniqueIdxSut(t, "Email")
|
||||
|
||||
err := uniq.Remove("", "mikey@example.com")
|
||||
assert.NoError(t, err)
|
||||
@@ -54,46 +56,27 @@ func TestUniqueRemove(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUniqueUpdate(t *testing.T) {
|
||||
uniq, dataDir := getUniqueIdxSut(t)
|
||||
uniq, dataDir := getUniqueIdxSut(t, "Email")
|
||||
|
||||
t.Log("successful update")
|
||||
err := uniq.Update("", "", "mikey2@example.com")
|
||||
err := uniq.Update("", "mikey@example.com", "mikey2@example.com")
|
||||
assert.NoError(t, err)
|
||||
|
||||
t.Log("failed update because already exists")
|
||||
err = uniq.Update("", "", "mikey2@example.com")
|
||||
err = uniq.Update("", "mikey2@example.com", "mikey2@example.com")
|
||||
assert.Error(t, err)
|
||||
assert.IsType(t, &errors.AlreadyExistsErr{}, err)
|
||||
|
||||
t.Log("failed update because not found")
|
||||
err = uniq.Update("", "", "something2@example.com")
|
||||
err = uniq.Update("", "nonexisting@example.com", "something2@example.com")
|
||||
assert.Error(t, err)
|
||||
assert.IsType(t, &errors.NotFoundErr{}, err)
|
||||
|
||||
_ = os.RemoveAll(dataDir)
|
||||
}
|
||||
|
||||
func TestUniqueInit(t *testing.T) {
|
||||
dataDir := CreateTmpDir(t)
|
||||
indexRootDir := path.Join(dataDir, "index.disk")
|
||||
filesDir := path.Join(dataDir, "users")
|
||||
|
||||
uniq := NewUniqueIndex("User", "Email", filesDir, indexRootDir)
|
||||
assert.Error(t, uniq.Init(), "Init should return an error about missing files-dir")
|
||||
|
||||
if err := os.Mkdir(filesDir, 0777); err != nil {
|
||||
t.Fatalf("Could not create test data-dir %s", err)
|
||||
}
|
||||
|
||||
assert.NoError(t, uniq.Init(), "Init shouldn't return an error")
|
||||
assert.DirExists(t, indexRootDir)
|
||||
assert.DirExists(t, path.Join(indexRootDir, "UniqueUserByEmail"))
|
||||
|
||||
_ = os.RemoveAll(dataDir)
|
||||
}
|
||||
|
||||
func TestUniqueIndexSearch(t *testing.T) {
|
||||
sut, dataPath := getUniqueIdxSut(t)
|
||||
sut, dataDir := getUniqueIdxSut(t, "Email")
|
||||
|
||||
res, err := sut.Search("j*@example.com")
|
||||
|
||||
@@ -107,7 +90,7 @@ func TestUniqueIndexSearch(t *testing.T) {
|
||||
assert.Error(t, err)
|
||||
assert.IsType(t, &errors.NotFoundErr{}, err)
|
||||
|
||||
_ = os.RemoveAll(dataPath)
|
||||
_ = os.RemoveAll(dataDir)
|
||||
}
|
||||
|
||||
func TestErrors(t *testing.T) {
|
||||
@@ -115,9 +98,22 @@ func TestErrors(t *testing.T) {
|
||||
assert.True(t, errors.IsNotFoundErr(&errors.NotFoundErr{}))
|
||||
}
|
||||
|
||||
func getUniqueIdxSut(t *testing.T) (sut index.Index, dataPath string) {
|
||||
dataPath = WriteIndexTestData(t, TestData, "Id")
|
||||
sut = NewUniqueIndex("User", "Email", path.Join(dataPath, "users"), path.Join(dataPath, "indexer.disk"))
|
||||
func getUniqueIdxSut(t *testing.T, indexBy string) (index.Index, string) {
|
||||
dataPath := WriteIndexTestData(t, TestData, "Id")
|
||||
cfg := config.Config{
|
||||
Repo: config.Repo{
|
||||
Disk: config.Disk{
|
||||
Path: dataPath,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
sut := NewUniqueIndexWithOptions(
|
||||
option.WithTypeName("test.Users.Disk"),
|
||||
option.WithIndexBy(indexBy),
|
||||
option.WithFilesDir(path.Join(cfg.Repo.Disk.Path, "users")),
|
||||
option.WithDataDir(cfg.Repo.Disk.Path),
|
||||
)
|
||||
err := sut.Init()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -132,5 +128,5 @@ func getUniqueIdxSut(t *testing.T) (sut index.Index, dataPath string) {
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
return sut, dataPath
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
_ "github.com/owncloud/ocis/accounts/pkg/indexer/index/cs3"
|
||||
_ "github.com/owncloud/ocis/accounts/pkg/indexer/index/disk"
|
||||
. "github.com/owncloud/ocis/accounts/pkg/indexer/test"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"os"
|
||||
"testing"
|
||||
@@ -27,10 +26,12 @@ func TestIndexer_AddWithUniqueIndex(t *testing.T) {
|
||||
u := &User{Id: "abcdefg-123", UserName: "mikey", Email: "mikey@example.com"}
|
||||
err = indexer.Add(u)
|
||||
assert.NoError(t, err)
|
||||
|
||||
_ = os.RemoveAll(dataDir)
|
||||
}
|
||||
|
||||
func TestIndexer_AddWithUniqueIndexCS3(t *testing.T) {
|
||||
dataDir := WriteIndexTestDataCS3(t, TestData, "Id")
|
||||
dir := WriteIndexTestDataCS3(t, TestData, "Id")
|
||||
indexer := CreateIndexer(&config.Config{
|
||||
Repo: config.Repo{
|
||||
CS3: config.CS3{
|
||||
@@ -49,7 +50,7 @@ func TestIndexer_AddWithUniqueIndexCS3(t *testing.T) {
|
||||
err = indexer.Add(u)
|
||||
assert.NoError(t, err)
|
||||
|
||||
_ = os.RemoveAll(dataDir)
|
||||
_ = os.RemoveAll(dir)
|
||||
}
|
||||
|
||||
func TestIndexer_AddWithNonUniqueIndexCS3(t *testing.T) {
|
||||
@@ -77,10 +78,12 @@ func TestIndexer_AddWithNonUniqueIndexCS3(t *testing.T) {
|
||||
|
||||
func TestIndexer_FindByWithUniqueIndex(t *testing.T) {
|
||||
dataDir := WriteIndexTestData(t, TestData, "Id")
|
||||
indexer := NewIndexer(&Config{
|
||||
DataDir: dataDir,
|
||||
IndexRootDirName: "index.disk",
|
||||
Log: zerolog.Logger{},
|
||||
indexer := CreateIndexer(&config.Config{
|
||||
Repo: config.Repo{
|
||||
Disk: config.Disk{
|
||||
Path: dataDir,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
err := indexer.AddIndex(&User{}, "UserName", "Id", "users", "unique")
|
||||
@@ -93,14 +96,18 @@ func TestIndexer_FindByWithUniqueIndex(t *testing.T) {
|
||||
res, err := indexer.FindBy(User{}, "UserName", "mikey")
|
||||
assert.NoError(t, err)
|
||||
t.Log(res)
|
||||
|
||||
_ = os.RemoveAll(dataDir)
|
||||
}
|
||||
|
||||
func TestIndexer_AddWithNonUniqueIndex(t *testing.T) {
|
||||
dataDir := WriteIndexTestData(t, TestData, "Id")
|
||||
indexer := NewIndexer(&Config{
|
||||
DataDir: dataDir,
|
||||
IndexRootDirName: "index.disk",
|
||||
Log: zerolog.Logger{},
|
||||
indexer := CreateIndexer(&config.Config{
|
||||
Repo: config.Repo{
|
||||
Disk: config.Disk{
|
||||
Path: dataDir,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
err := indexer.AddIndex(&TestPet{}, "Kind", "Id", "pets", "non_unique")
|
||||
@@ -123,10 +130,12 @@ func TestIndexer_AddWithNonUniqueIndex(t *testing.T) {
|
||||
|
||||
func TestIndexer_DeleteWithNonUniqueIndex(t *testing.T) {
|
||||
dataDir := WriteIndexTestData(t, TestData, "Id")
|
||||
indexer := NewIndexer(&Config{
|
||||
DataDir: dataDir,
|
||||
IndexRootDirName: "index.disk",
|
||||
Log: zerolog.Logger{},
|
||||
indexer := CreateIndexer(&config.Config{
|
||||
Repo: config.Repo{
|
||||
Disk: config.Disk{
|
||||
Path: dataDir,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
err := indexer.AddIndex(&TestPet{}, "Kind", "Id", "pets", "non_unique")
|
||||
@@ -143,14 +152,18 @@ func TestIndexer_DeleteWithNonUniqueIndex(t *testing.T) {
|
||||
|
||||
err = indexer.Delete(pet2)
|
||||
assert.NoError(t, err)
|
||||
|
||||
_ = os.RemoveAll(dataDir)
|
||||
}
|
||||
|
||||
func TestIndexer_SearchWithNonUniqueIndex(t *testing.T) {
|
||||
dataDir := WriteIndexTestData(t, TestData, "Id")
|
||||
indexer := NewIndexer(&Config{
|
||||
DataDir: dataDir,
|
||||
IndexRootDirName: "index.disk",
|
||||
Log: zerolog.Logger{},
|
||||
indexer := CreateIndexer(&config.Config{
|
||||
Repo: config.Repo{
|
||||
Disk: config.Disk{
|
||||
Path: dataDir,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
err := indexer.AddIndex(&TestPet{}, "Name", "Id", "pets", "non_unique")
|
||||
@@ -169,14 +182,17 @@ func TestIndexer_SearchWithNonUniqueIndex(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
t.Log(res)
|
||||
_ = os.RemoveAll(dataDir)
|
||||
}
|
||||
|
||||
func TestIndexer_UpdateWithUniqueIndex(t *testing.T) {
|
||||
dataDir := WriteIndexTestData(t, TestData, "Id")
|
||||
indexer := NewIndexer(&Config{
|
||||
DataDir: dataDir,
|
||||
IndexRootDirName: "index.disk",
|
||||
Log: zerolog.Logger{},
|
||||
indexer := CreateIndexer(&config.Config{
|
||||
Repo: config.Repo{
|
||||
Disk: config.Disk{
|
||||
Path: dataDir,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
err := indexer.AddIndex(&User{}, "UserName", "Id", "users", "unique")
|
||||
@@ -223,14 +239,18 @@ func TestIndexer_UpdateWithUniqueIndex(t *testing.T) {
|
||||
fbEmail, err3 := indexer.FindBy(&User{}, "Email", "mikey-new@example.com")
|
||||
assert.NoError(t, err3)
|
||||
assert.Len(t, fbEmail, 1)
|
||||
|
||||
_ = os.RemoveAll(dataDir)
|
||||
}
|
||||
|
||||
func TestIndexer_UpdateWithNonUniqueIndex(t *testing.T) {
|
||||
dataDir := WriteIndexTestData(t, TestData, "Id")
|
||||
indexer := NewIndexer(&Config{
|
||||
DataDir: dataDir,
|
||||
IndexRootDirName: "index.disk",
|
||||
Log: zerolog.Logger{},
|
||||
indexer := CreateIndexer(&config.Config{
|
||||
Repo: config.Repo{
|
||||
Disk: config.Disk{
|
||||
Path: dataDir,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
err := indexer.AddIndex(&TestPet{}, "Name", "Id", "pets", "non_unique")
|
||||
@@ -244,90 +264,6 @@ func TestIndexer_UpdateWithNonUniqueIndex(t *testing.T) {
|
||||
|
||||
err = indexer.Add(pet2)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
/*
|
||||
func TestManagerQueryMultipleIndices(t *testing.T) {
|
||||
dataDir := writeIndexTestData(t, testData, "Id")
|
||||
man := NewIndexer(&Config{
|
||||
DataDir: dataDir,
|
||||
IndexRootDirName: "index.disk",
|
||||
Log: zerolog.Logger{},
|
||||
})
|
||||
|
||||
err := man.AddIndex("User", "Email", "users")
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = man.AddIndex("User", "UserName", "users")
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = man.AddNormalIndex("TestPet", "Color", "pets")
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = man.AddIndex("TestPet", "Name", "pets")
|
||||
assert.NoError(t, err)
|
||||
|
||||
for path := range testData {
|
||||
for _, entity := range testData[path] {
|
||||
err := man.Add(valueOf(entity, "Id"), entity)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
type test struct {
|
||||
typeName, key, value, wantRes string
|
||||
wantErr error
|
||||
}
|
||||
|
||||
tests := []test{
|
||||
{typeName: "User", key: "Email", value: "jacky@example.com", wantRes: "ewf4ofk-555"},
|
||||
{typeName: "User", key: "UserName", value: "jacky", wantRes: "ewf4ofk-555"},
|
||||
{typeName: "TestPet", key: "Color", value: "Brown", wantRes: "rebef-123"},
|
||||
{typeName: "TestPet", key: "Color", value: "Cyan", wantRes: "", wantErr: ¬FoundErr{}},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
name := fmt.Sprintf("Query%sBy%s=%s", tc.typeName, tc.key, tc.value)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
pk, err := man.Find(tc.typeName, tc.key, tc.value)
|
||||
assert.Equal(t, tc.wantRes, pk)
|
||||
assert.IsType(t, tc.wantErr, err)
|
||||
})
|
||||
}
|
||||
|
||||
_ = os.RemoveAll(dataDir)
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
func TestManagerDelete(t *testing.T) {
|
||||
dataDir := writeIndexTestData(t, testData, "Id")
|
||||
man := NewIndexer(&Config{
|
||||
DataDir: dataDir,
|
||||
IndexRootDirName: "index.disk",
|
||||
Log: zerolog.Logger{},
|
||||
})
|
||||
|
||||
err := man.AddIndex("User", "Email", "users")
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = man.AddIndex("User", "UserName", "users")
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = man.AddIndex("TestPet", "Name", "pets")
|
||||
assert.NoError(t, err)
|
||||
|
||||
for path := range testData {
|
||||
for _, entity := range testData[path] {
|
||||
err := man.Add(valueOf(entity, "Id"), entity)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
err = man.Delete("User", "hijklmn-456")
|
||||
_ = os.RemoveAll(dataDir)
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
/var/tmp/testfiles-747949844/pets/goefe-789
|
||||
@@ -0,0 +1 @@
|
||||
/var/tmp/testfiles-747949844/pets/xadaf-189
|
||||
@@ -56,7 +56,7 @@ func WriteIndexTestData(t *testing.T, m map[string][]interface{}, pk string) str
|
||||
}
|
||||
|
||||
func WriteIndexTestDataCS3(t *testing.T, m map[string][]interface{}, pk string) string {
|
||||
rootDir := "/var/tmp/ocis/root/data"
|
||||
rootDir := "/var/tmp/ocis/storage/users/data"
|
||||
for dirName := range m {
|
||||
fileTypePath := path.Join(rootDir, dirName)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user