[add] migrate store

This commit is contained in:
Max 2023-02-03 15:21:31 +08:00
parent 5faf62a789
commit a9e865ff41
3 changed files with 23 additions and 25 deletions

View file

@ -9,7 +9,7 @@ COMMIT := $(shell git log | head -n 1 | awk '{print substr($$2, 0, 12)}')
NOW := $(shell date +"%FT%T%z") NOW := $(shell date +"%FT%T%z")
# ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) # ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
TESTFOLDER := $(shell $(GO) list ./... | grep -E 'api|model|flow|script|fs|i18n|connector|query|plugin|cert|crypto|task|schedule|runtime|helper|utils|widget|importer' | grep -vE 'examples|tests*|config|widgets') TESTFOLDER := $(shell $(GO) list ./... | grep -E 'api|model|flow|script|fs|i18n|connector|query|plugin|cert|crypto|task|schedule|runtime|helper|utils|widget|importer|store' | grep -vE 'examples|tests*|config|widgets')
TESTTAGS ?= "" TESTTAGS ?= ""
# TESTWIDGETS := $(shell $(GO) list ./widgets/...) # TESTWIDGETS := $(shell $(GO) list ./widgets/...)

View file

@ -11,26 +11,11 @@ import (
func Load(cfg config.Config) error { func Load(cfg config.Config) error {
exts := []string{"*.yao", "*.json", "*.jsonc"} exts := []string{"*.yao", "*.json", "*.jsonc"}
return application.App.Walk("stores", func(root, file string, isdir bool) error { return application.App.Walk("stores", func(root, file string, isdir bool) error {
if isdir {
return nil
}
_, err := store.Load(file, share.ID(root, file)) _, err := store.Load(file, share.ID(root, file))
return err return err
}, exts...) }, exts...)
} }
// // LoadFrom load from dir
// func LoadFrom(dir string, prefix string) error {
// if share.DirNotExists(dir) {
// return fmt.Errorf("%s does not exists", dir)
// }
// err := share.Walk(dir, ".json", func(root, filename string) {
// name := prefix + share.SpecName(root, filename)
// content := share.ReadFile(filename)
// _, err := gou.LoadStore(string(content), name)
// if err != nil {
// log.With(log.F{"root": root, "file": filename}).Error(err.Error())
// }
// })
// return err
// }

View file

@ -7,18 +7,31 @@ import (
"github.com/yaoapp/gou/store" "github.com/yaoapp/gou/store"
"github.com/yaoapp/yao/config" "github.com/yaoapp/yao/config"
"github.com/yaoapp/yao/connector" "github.com/yaoapp/yao/connector"
"github.com/yaoapp/yao/test"
) )
func TestLoad(t *testing.T) { func TestLoad(t *testing.T) {
connector.Load(config.Conf) test.Prepare(t, config.Conf)
defer test.Clean()
loadConnectors(t)
Load(config.Conf) Load(config.Conf)
check(t) check(t)
} }
func check(t *testing.T) { func check(t *testing.T) {
keys := []string{} ids := map[string]bool{}
for key := range store.Pools { for id := range store.Pools {
keys = append(keys, key) ids[id] = true
}
assert.True(t, ids["cache"])
assert.True(t, ids["data"])
assert.True(t, ids["share"])
}
func loadConnectors(t *testing.T) {
err := connector.Load(config.Conf)
if err != nil {
t.Fatal(err)
} }
assert.Equal(t, 3, len(keys))
} }