diff --git a/Makefile b/Makefile index 7635d742..d1310734 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ COMMIT := $(shell git log | head -n 1 | awk '{print substr($$2, 0, 12)}') NOW := $(shell date +"%FT%T%z") # ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) -TESTFOLDER := $(shell $(GO) list ./... | grep -E 'api|model|flow|script|fs|i18n' | grep -vE 'examples|tests*|config|widgets') +TESTFOLDER := $(shell $(GO) list ./... | grep -E 'api|model|flow|script|fs|i18n|connector' | grep -vE 'examples|tests*|config|widgets') TESTTAGS ?= "" # TESTWIDGETS := $(shell $(GO) list ./widgets/...) diff --git a/connector/connector.go b/connector/connector.go index 858f3f37..d9ad09c1 100644 --- a/connector/connector.go +++ b/connector/connector.go @@ -1,36 +1,20 @@ package connector import ( - "fmt" - "path/filepath" - + "github.com/yaoapp/gou/application" "github.com/yaoapp/gou/connector" - "github.com/yaoapp/kun/log" "github.com/yaoapp/yao/config" "github.com/yaoapp/yao/share" ) // Load load store func Load(cfg config.Config) error { - var root = filepath.Join(cfg.Root, "connectors") - return LoadFrom(root, "") -} - -// 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 := connector.Load(string(content), name) - if err != nil { - log.With(log.F{"root": root, "file": filename}).Error(err.Error()) + exts := []string{"*.yao", "*.json", "*.jsonc"} + return application.App.Walk("connectors", func(root, file string, isdir bool) error { + if isdir { + return nil } - }) - - return err + _, err := connector.Load(file, share.ID(root, file)) + return err + }, exts...) } diff --git a/connector/connector_test.go b/connector/connector_test.go index d82a6844..2b8909ca 100644 --- a/connector/connector_test.go +++ b/connector/connector_test.go @@ -6,18 +6,24 @@ import ( "github.com/stretchr/testify/assert" "github.com/yaoapp/gou/connector" "github.com/yaoapp/yao/config" + "github.com/yaoapp/yao/test" ) func TestLoad(t *testing.T) { + test.Prepare(t, config.Conf) + defer test.Clean() + Load(config.Conf) - LoadFrom("not a path", "404.") check(t) } func check(t *testing.T) { - keys := []string{} - for key := range connector.Connectors { - keys = append(keys, key) + ids := map[string]bool{} + for id := range connector.Connectors { + ids[id] = true } - assert.Equal(t, 4, len(keys)) + assert.True(t, ids["mongo"]) + assert.True(t, ids["mysql"]) + assert.True(t, ids["redis"]) + assert.True(t, ids["sqlite"]) }