mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-22 21:49:07 -06:00
refactor test suite
This commit is contained in:
@@ -10,8 +10,11 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const cs3RootFolder = "/var/tmp/ocis/storage/users/data"
|
||||
|
||||
func TestAutoincrementIndexAdd(t *testing.T) {
|
||||
dataDir := WriteIndexTestDataCS3(t, Data, "ID")
|
||||
dataDir, err := WriteIndexTestData(Data, "ID", cs3RootFolder)
|
||||
assert.NoError(t, err)
|
||||
cfg := generateConfig()
|
||||
|
||||
sut := NewAutoincrementIndex(
|
||||
@@ -23,8 +26,7 @@ func TestAutoincrementIndexAdd(t *testing.T) {
|
||||
option.WithProviderAddr(cfg.Repo.CS3.ProviderAddr),
|
||||
)
|
||||
|
||||
err := sut.Init()
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, sut.Init())
|
||||
|
||||
for i := 0; i < 5; i++ {
|
||||
res, err := sut.Add("abcdefg-123", "")
|
||||
@@ -36,7 +38,8 @@ func TestAutoincrementIndexAdd(t *testing.T) {
|
||||
}
|
||||
|
||||
func BenchmarkAutoincrementIndexAdd(b *testing.B) {
|
||||
dataDir := WriteIndexBenchmarkDataCS3(b, Data, "ID")
|
||||
dataDir, err := WriteIndexTestData(Data, "ID", cs3RootFolder)
|
||||
assert.NoError(b, err)
|
||||
cfg := generateConfig()
|
||||
|
||||
sut := NewAutoincrementIndex(
|
||||
@@ -48,7 +51,7 @@ func BenchmarkAutoincrementIndexAdd(b *testing.B) {
|
||||
option.WithProviderAddr(cfg.Repo.CS3.ProviderAddr),
|
||||
)
|
||||
|
||||
err := sut.Init()
|
||||
err = sut.Init()
|
||||
assert.NoError(b, err)
|
||||
|
||||
for n := 0; n < b.N; n++ {
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
package cs3
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"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 TestCS3NonUniqueIndex_FakeSymlink(t *testing.T) {
|
||||
//go setupMetadataStorage()
|
||||
//defer cancelFunc()
|
||||
|
||||
dataDir := WriteIndexTestDataCS3(t, Data, "ID")
|
||||
dataDir, err := WriteIndexTestData(Data, "ID", cs3RootFolder)
|
||||
assert.NoError(t, err)
|
||||
cfg := config.Config{
|
||||
Repo: config.Repo{
|
||||
Disk: config.Disk{
|
||||
@@ -40,7 +39,7 @@ func TestCS3NonUniqueIndex_FakeSymlink(t *testing.T) {
|
||||
option.WithProviderAddr(cfg.Repo.CS3.ProviderAddr),
|
||||
)
|
||||
|
||||
err := sut.Init()
|
||||
err = sut.Init()
|
||||
assert.NoError(t, err)
|
||||
|
||||
res, err := sut.Add("abcdefg-123", "mikey")
|
||||
|
||||
@@ -12,7 +12,8 @@ import (
|
||||
)
|
||||
|
||||
func TestCS3UniqueIndex_FakeSymlink(t *testing.T) {
|
||||
dataDir := WriteIndexTestDataCS3(t,Data, "ID")
|
||||
dataDir, err := WriteIndexTestData(Data, "ID", cs3RootFolder)
|
||||
assert.NoError(t, err)
|
||||
cfg := config.Config{
|
||||
Repo: config.Repo{
|
||||
Disk: config.Disk{
|
||||
@@ -38,7 +39,7 @@ func TestCS3UniqueIndex_FakeSymlink(t *testing.T) {
|
||||
option.WithProviderAddr(cfg.Repo.CS3.ProviderAddr),
|
||||
)
|
||||
|
||||
err := sut.Init()
|
||||
err = sut.Init()
|
||||
assert.NoError(t, err)
|
||||
|
||||
res, err := sut.Add("abcdefg-123", "mikey")
|
||||
@@ -61,7 +62,8 @@ func TestCS3UniqueIndex_FakeSymlink(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCS3UniqueIndexSearch(t *testing.T) {
|
||||
dataDir := WriteIndexTestDataCS3(t, Data, "ID")
|
||||
dataDir, err := WriteIndexTestData(Data, "ID", cs3RootFolder)
|
||||
assert.NoError(t, err)
|
||||
cfg := config.Config{
|
||||
Repo: config.Repo{
|
||||
Disk: config.Disk{
|
||||
@@ -87,7 +89,7 @@ func TestCS3UniqueIndexSearch(t *testing.T) {
|
||||
option.WithProviderAddr(cfg.Repo.CS3.ProviderAddr),
|
||||
)
|
||||
|
||||
err := sut.Init()
|
||||
err = sut.Init()
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = sut.Add("hijklmn-456", "mikey")
|
||||
|
||||
@@ -2,15 +2,16 @@ package disk
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"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"
|
||||
"path"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNonUniqueIndexAdd(t *testing.T) {
|
||||
@@ -78,7 +79,7 @@ func TestNonUniqueIndexSearch(t *testing.T) {
|
||||
|
||||
// entity: used to get the fully qualified name for the index root path.
|
||||
func getNonUniqueIdxSut(t *testing.T, entity interface{}, indexBy string) (index.Index, string) {
|
||||
dataPath := WriteIndexTestData(t, Data, "ID")
|
||||
dataPath, _ := WriteIndexTestData(Data, "ID", "")
|
||||
cfg := config.Config{
|
||||
Repo: config.Repo{
|
||||
Disk: config.Disk{
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package disk
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"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"
|
||||
"path"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUniqueLookupSingleEntry(t *testing.T) {
|
||||
@@ -99,7 +100,7 @@ func TestErrors(t *testing.T) {
|
||||
}
|
||||
|
||||
func getUniqueIdxSut(t *testing.T, indexBy string, entityType interface{}) (index.Index, string) {
|
||||
dataPath := WriteIndexTestData(t, Data, "ID")
|
||||
dataPath, _ := WriteIndexTestData(Data, "ID", "")
|
||||
cfg := config.Config{
|
||||
Repo: config.Repo{
|
||||
Disk: config.Disk{
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package indexer
|
||||
|
||||
import (
|
||||
"github.com/owncloud/ocis/accounts/pkg/indexer/option"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/owncloud/ocis/accounts/pkg/proto/v0"
|
||||
|
||||
"github.com/owncloud/ocis/accounts/pkg/indexer/option"
|
||||
|
||||
"github.com/owncloud/ocis/accounts/pkg/config"
|
||||
_ "github.com/owncloud/ocis/accounts/pkg/indexer/index/cs3"
|
||||
_ "github.com/owncloud/ocis/accounts/pkg/indexer/index/disk"
|
||||
@@ -13,8 +16,11 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const cs3RootFolder = "/var/tmp/ocis/storage/users/data"
|
||||
|
||||
func TestIndexer_CS3_AddWithUniqueIndex(t *testing.T) {
|
||||
dataDir := WriteIndexTestDataCS3(t, Data, "ID")
|
||||
dataDir, err := WriteIndexTestData(Data, "ID", cs3RootFolder)
|
||||
assert.NoError(t, err)
|
||||
indexer := CreateIndexer(&config.Config{
|
||||
Repo: config.Repo{
|
||||
CS3: config.CS3{
|
||||
@@ -26,7 +32,7 @@ func TestIndexer_CS3_AddWithUniqueIndex(t *testing.T) {
|
||||
},
|
||||
})
|
||||
|
||||
err := indexer.AddIndex(&User{}, "UserName", "ID", "users", "unique", nil)
|
||||
err = indexer.AddIndex(&User{}, "UserName", "ID", "users", "unique", nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
u := &User{ID: "abcdefg-123", UserName: "mikey", Email: "mikey@example.com"}
|
||||
@@ -37,7 +43,8 @@ func TestIndexer_CS3_AddWithUniqueIndex(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIndexer_CS3_AddWithNonUniqueIndex(t *testing.T) {
|
||||
dataDir := WriteIndexTestDataCS3(t, Data, "ID")
|
||||
dataDir, err := WriteIndexTestData(Data, "ID", cs3RootFolder)
|
||||
assert.NoError(t, err)
|
||||
indexer := CreateIndexer(&config.Config{
|
||||
Repo: config.Repo{
|
||||
CS3: config.CS3{
|
||||
@@ -49,7 +56,7 @@ func TestIndexer_CS3_AddWithNonUniqueIndex(t *testing.T) {
|
||||
},
|
||||
})
|
||||
|
||||
err := indexer.AddIndex(&User{}, "UserName", "ID", "users", "non_unique", nil)
|
||||
err = indexer.AddIndex(&User{}, "UserName", "ID", "users", "non_unique", nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
u := &User{ID: "abcdefg-123", UserName: "mikey", Email: "mikey@example.com"}
|
||||
@@ -60,7 +67,8 @@ func TestIndexer_CS3_AddWithNonUniqueIndex(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIndexer_Disk_FindByWithUniqueIndex(t *testing.T) {
|
||||
dataDir := WriteIndexTestData(t, Data, "ID")
|
||||
dataDir, err := WriteIndexTestData(Data, "ID", "")
|
||||
assert.NoError(t, err)
|
||||
indexer := CreateIndexer(&config.Config{
|
||||
Repo: config.Repo{
|
||||
Disk: config.Disk{
|
||||
@@ -69,7 +77,7 @@ func TestIndexer_Disk_FindByWithUniqueIndex(t *testing.T) {
|
||||
},
|
||||
})
|
||||
|
||||
err := indexer.AddIndex(&User{}, "UserName", "ID", "users", "unique", nil)
|
||||
err = indexer.AddIndex(&User{}, "UserName", "ID", "users", "unique", nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
u := &User{ID: "abcdefg-123", UserName: "mikey", Email: "mikey@example.com"}
|
||||
@@ -84,7 +92,8 @@ func TestIndexer_Disk_FindByWithUniqueIndex(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIndexer_Disk_AddWithUniqueIndex(t *testing.T) {
|
||||
dataDir := WriteIndexTestData(t, Data, "ID")
|
||||
dataDir, err := WriteIndexTestData(Data, "ID", "")
|
||||
assert.NoError(t, err)
|
||||
indexer := CreateIndexer(&config.Config{
|
||||
Repo: config.Repo{
|
||||
Disk: config.Disk{
|
||||
@@ -93,7 +102,7 @@ func TestIndexer_Disk_AddWithUniqueIndex(t *testing.T) {
|
||||
},
|
||||
})
|
||||
|
||||
err := indexer.AddIndex(&User{}, "UserName", "ID", "users", "unique", nil)
|
||||
err = indexer.AddIndex(&User{}, "UserName", "ID", "users", "unique", nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
u := &User{ID: "abcdefg-123", UserName: "mikey", Email: "mikey@example.com"}
|
||||
@@ -104,7 +113,8 @@ func TestIndexer_Disk_AddWithUniqueIndex(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIndexer_Disk_AddWithNonUniqueIndex(t *testing.T) {
|
||||
dataDir := WriteIndexTestData(t, Data, "ID")
|
||||
dataDir, err := WriteIndexTestData(Data, "ID", "")
|
||||
assert.NoError(t, err)
|
||||
indexer := CreateIndexer(&config.Config{
|
||||
Repo: config.Repo{
|
||||
Disk: config.Disk{
|
||||
@@ -113,7 +123,7 @@ func TestIndexer_Disk_AddWithNonUniqueIndex(t *testing.T) {
|
||||
},
|
||||
})
|
||||
|
||||
err := indexer.AddIndex(&Pet{}, "Kind", "ID", "pets", "non_unique", nil)
|
||||
err = indexer.AddIndex(&Pet{}, "Kind", "ID", "pets", "non_unique", nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
pet1 := Pet{ID: "goefe-789", Kind: "Hog", Color: "Green", Name: "Dicky"}
|
||||
@@ -134,7 +144,8 @@ func TestIndexer_Disk_AddWithNonUniqueIndex(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIndexer_Disk_AddWithAutoincrementIndex(t *testing.T) {
|
||||
dataDir := WriteIndexTestData(t, Data, "ID")
|
||||
dataDir, err := WriteIndexTestData(Data, "ID", "")
|
||||
assert.NoError(t, err)
|
||||
indexer := CreateIndexer(&config.Config{
|
||||
Repo: config.Repo{
|
||||
Disk: config.Disk{
|
||||
@@ -143,7 +154,7 @@ func TestIndexer_Disk_AddWithAutoincrementIndex(t *testing.T) {
|
||||
},
|
||||
})
|
||||
|
||||
err := indexer.AddIndex(&User{}, "UID", "ID", "users", "autoincrement", &option.Bound{Lower: 5})
|
||||
err = indexer.AddIndex(&User{}, "UID", "ID", "users", "autoincrement", &option.Bound{Lower: 5})
|
||||
assert.NoError(t, err)
|
||||
|
||||
res1, err := indexer.Add(Data["users"][0])
|
||||
@@ -165,7 +176,8 @@ func TestIndexer_Disk_AddWithAutoincrementIndex(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIndexer_Disk_DeleteWithNonUniqueIndex(t *testing.T) {
|
||||
dataDir := WriteIndexTestData(t, Data, "ID")
|
||||
dataDir, err := WriteIndexTestData(Data, "ID", "")
|
||||
assert.NoError(t, err)
|
||||
indexer := CreateIndexer(&config.Config{
|
||||
Repo: config.Repo{
|
||||
Disk: config.Disk{
|
||||
@@ -174,7 +186,7 @@ func TestIndexer_Disk_DeleteWithNonUniqueIndex(t *testing.T) {
|
||||
},
|
||||
})
|
||||
|
||||
err := indexer.AddIndex(&Pet{}, "Kind", "ID", "pets", "non_unique", nil)
|
||||
err = indexer.AddIndex(&Pet{}, "Kind", "ID", "pets", "non_unique", nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
pet1 := Pet{ID: "goefe-789", Kind: "Hog", Color: "Green", Name: "Dicky"}
|
||||
@@ -193,7 +205,8 @@ func TestIndexer_Disk_DeleteWithNonUniqueIndex(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIndexer_Disk_SearchWithNonUniqueIndex(t *testing.T) {
|
||||
dataDir := WriteIndexTestData(t, Data, "ID")
|
||||
dataDir, err := WriteIndexTestData(Data, "ID", "")
|
||||
assert.NoError(t, err)
|
||||
indexer := CreateIndexer(&config.Config{
|
||||
Repo: config.Repo{
|
||||
Disk: config.Disk{
|
||||
@@ -202,7 +215,7 @@ func TestIndexer_Disk_SearchWithNonUniqueIndex(t *testing.T) {
|
||||
},
|
||||
})
|
||||
|
||||
err := indexer.AddIndex(&Pet{}, "Name", "ID", "pets", "non_unique", nil)
|
||||
err = indexer.AddIndex(&Pet{}, "Name", "ID", "pets", "non_unique", nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
pet1 := Pet{ID: "goefe-789", Kind: "Hog", Color: "Green", Name: "Dicky"}
|
||||
@@ -222,7 +235,8 @@ func TestIndexer_Disk_SearchWithNonUniqueIndex(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIndexer_Disk_UpdateWithUniqueIndex(t *testing.T) {
|
||||
dataDir := WriteIndexTestData(t, Data, "ID")
|
||||
dataDir, err := WriteIndexTestData(Data, "ID", "")
|
||||
assert.NoError(t, err)
|
||||
indexer := CreateIndexer(&config.Config{
|
||||
Repo: config.Repo{
|
||||
Disk: config.Disk{
|
||||
@@ -231,7 +245,7 @@ func TestIndexer_Disk_UpdateWithUniqueIndex(t *testing.T) {
|
||||
},
|
||||
})
|
||||
|
||||
err := indexer.AddIndex(&User{}, "UserName", "ID", "users", "unique", nil)
|
||||
err = indexer.AddIndex(&User{}, "UserName", "ID", "users", "unique", nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = indexer.AddIndex(&User{}, "Email", "ID", "users", "unique", nil)
|
||||
@@ -280,7 +294,8 @@ func TestIndexer_Disk_UpdateWithUniqueIndex(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIndexer_Disk_UpdateWithNonUniqueIndex(t *testing.T) {
|
||||
dataDir := WriteIndexTestData(t, Data, "ID")
|
||||
dataDir, err := WriteIndexTestData(Data, "ID", "")
|
||||
assert.NoError(t, err)
|
||||
indexer := CreateIndexer(&config.Config{
|
||||
Repo: config.Repo{
|
||||
Disk: config.Disk{
|
||||
@@ -289,7 +304,7 @@ func TestIndexer_Disk_UpdateWithNonUniqueIndex(t *testing.T) {
|
||||
},
|
||||
})
|
||||
|
||||
err := indexer.AddIndex(&Pet{}, "Name", "ID", "pets", "non_unique", nil)
|
||||
err = indexer.AddIndex(&Pet{}, "Name", "ID", "pets", "non_unique", nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
pet1 := Pet{ID: "goefe-789", Kind: "Hog", Color: "Green", Name: "Dicky"}
|
||||
@@ -303,3 +318,32 @@ func TestIndexer_Disk_UpdateWithNonUniqueIndex(t *testing.T) {
|
||||
|
||||
_ = os.RemoveAll(dataDir)
|
||||
}
|
||||
|
||||
func TestIndexer_Disk_AutoIncrementIndex(t *testing.T) {
|
||||
scenarios := []struct {
|
||||
name string
|
||||
indexOn string
|
||||
entity *proto.Account
|
||||
}{
|
||||
{
|
||||
name: "create an index on a valid autoincrement field",
|
||||
indexOn: "Number",
|
||||
entity: &proto.Account{},
|
||||
},
|
||||
}
|
||||
|
||||
for i := range scenarios {
|
||||
t.Run(scenarios[i].name, func(t *testing.T) {
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func setup() error {
|
||||
//dataDir := WriteIndexTestData(t, Data, "ID")
|
||||
return nil
|
||||
}
|
||||
|
||||
func teardown() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -5,19 +5,18 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// User is a user.
|
||||
type User struct {
|
||||
ID, UserName, Email string
|
||||
UID int
|
||||
UID int
|
||||
}
|
||||
|
||||
// Pet is a pet.
|
||||
type Pet struct {
|
||||
ID, Kind, Color, Name string
|
||||
UID int
|
||||
UID int
|
||||
}
|
||||
|
||||
// Data mock data.
|
||||
@@ -37,76 +36,57 @@ var Data = map[string][]interface{}{
|
||||
}
|
||||
|
||||
// WriteIndexTestData writes mock data to disk.
|
||||
func WriteIndexTestData(t *testing.T, m map[string][]interface{}, pk string) string {
|
||||
rootDir := CreateTmpDir(t)
|
||||
func WriteIndexTestData(m map[string][]interface{}, privateKey, dir string) (string, error) {
|
||||
rootDir, err := getRootDir(dir)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
err = writeData(m, privateKey, rootDir)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return rootDir, nil
|
||||
}
|
||||
|
||||
// getRootDir allows for some minimal behavior on destination on disk. Testing the cs3 api behavior locally means
|
||||
// keeping track of where the cs3 data lives on disk, this function allows for multiplexing whether or not to use a
|
||||
// temporary folder or an already defined one.
|
||||
func getRootDir(dir string) (string, error) {
|
||||
var rootDir string
|
||||
var err error
|
||||
|
||||
if dir != "" {
|
||||
rootDir = dir
|
||||
} else {
|
||||
rootDir, err = CreateTmpDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
return rootDir, nil
|
||||
}
|
||||
|
||||
// writeData writes test data to disk on rootDir location Marshaled as json.
|
||||
func writeData(m map[string][]interface{}, privateKey string, rootDir string) error {
|
||||
for dirName := range m {
|
||||
fileTypePath := path.Join(rootDir, dirName)
|
||||
|
||||
if err := os.MkdirAll(fileTypePath, 0777); err != nil {
|
||||
t.Fatal(err)
|
||||
return err
|
||||
}
|
||||
for _, u := range m[dirName] {
|
||||
data, err := json.Marshal(u)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
pkVal := ValueOf(u, pk)
|
||||
pkVal := ValueOf(u, privateKey)
|
||||
if err := ioutil.WriteFile(path.Join(fileTypePath, pkVal), data, 0777); err != nil {
|
||||
t.Fatal(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rootDir
|
||||
}
|
||||
|
||||
// WriteIndexTestDataCS3 writes more data to disk.
|
||||
func WriteIndexTestDataCS3(t *testing.T, m map[string][]interface{}, pk string) string {
|
||||
rootDir := "/var/tmp/ocis/storage/users/data"
|
||||
for dirName := range m {
|
||||
fileTypePath := path.Join(rootDir, dirName)
|
||||
|
||||
if err := os.MkdirAll(fileTypePath, 0777); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, u := range m[dirName] {
|
||||
data, err := json.Marshal(u)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
pkVal := ValueOf(u, pk)
|
||||
if err := ioutil.WriteFile(path.Join(fileTypePath, pkVal), data, 0777); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rootDir
|
||||
}
|
||||
|
||||
// WriteIndexBenchmarkDataCS3 writes more data to disk.
|
||||
func WriteIndexBenchmarkDataCS3(b *testing.B, m map[string][]interface{}, pk string) string {
|
||||
rootDir := "/var/tmp/ocis/storage/users/data"
|
||||
for dirName := range m {
|
||||
fileTypePath := path.Join(rootDir, dirName)
|
||||
|
||||
if err := os.MkdirAll(fileTypePath, 0777); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
for _, u := range m[dirName] {
|
||||
data, err := json.Marshal(u)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
pkVal := ValueOf(u, pk)
|
||||
if err := ioutil.WriteFile(path.Join(fileTypePath, pkVal), data, 0777); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rootDir
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -6,17 +6,16 @@ import (
|
||||
"path"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// CreateTmpDir creates a temporary dir for tests data.
|
||||
func CreateTmpDir(t *testing.T) string {
|
||||
func CreateTmpDir() (string, error) {
|
||||
name, err := ioutil.TempDir("/var/tmp", "testfiles-")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
return name
|
||||
return name, nil
|
||||
}
|
||||
|
||||
// ValueOf gets the value of a type v on a given field <field>.
|
||||
@@ -39,7 +38,8 @@ func getType(v interface{}) (reflect.Value, error) {
|
||||
return rv, nil
|
||||
}
|
||||
|
||||
// GetTypeFQN formats a valid name from a type <t>.
|
||||
// GetTypeFQN formats a valid name from a type <t>. This is a duplication of the already existing function in the
|
||||
// indexer package, but since there is a circular dependency we chose to duplicate it.
|
||||
func GetTypeFQN(t interface{}) string {
|
||||
typ, _ := getType(t)
|
||||
typeName := path.Join(typ.Type().PkgPath(), typ.Type().Name())
|
||||
|
||||
@@ -25,7 +25,7 @@ func (s Service) expandMembers(g *proto.Group) {
|
||||
if err := s.repo.LoadAccount(context.Background(), g.Members[i].Id, a); err == nil {
|
||||
expanded = append(expanded, a)
|
||||
} else {
|
||||
// log errors but continue execution for now
|
||||
// log errors but con/var/tmp/ocis-accounts-store-408341811tinue execution for now
|
||||
s.log.Error().Err(err).Str("id", g.Members[i].Id).Msg("could not load account")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user