diff --git a/config/module.go b/config/module.go index 1cc63089..81e38b46 100644 --- a/config/module.go +++ b/config/module.go @@ -92,9 +92,9 @@ func (m Module) ProvideCommand(command *cobra.Command) { } exportedConfigs = copy } - os.MkdirAll(filepath.Dir(outputFile), 0644) + os.MkdirAll(filepath.Dir(outputFile), os.ModePerm) targetFile, err = os.OpenFile(outputFile, - handler.flags(), 0644) + handler.flags(), os.ModePerm) if err != nil { return errors.Wrap(err, "failed to open config file") } diff --git a/otgorm/dependency.go b/otgorm/dependency.go index 523e7d7d..2eb33df4 100644 --- a/otgorm/dependency.go +++ b/otgorm/dependency.go @@ -1,7 +1,9 @@ package otgorm import ( + "errors" "fmt" + "net" "github.com/DoNewsCode/core/config" "github.com/DoNewsCode/core/contract" @@ -160,9 +162,13 @@ func provideGormConfig(l log.Logger, conf *databaseConf) *gorm.Config { // will fail when initializing dependencies. func provideGormDB(dialector gorm.Dialector, config *gorm.Config, tracer opentracing.Tracer) (*gorm.DB, func(), error) { db, err := gorm.Open(dialector, config) - if err != nil { + + var nerr *net.OpError + + if err != nil && !errors.As(err, &nerr) { return nil, nil, err } + if tracer != nil { AddGormCallbacks(db, tracer) } diff --git a/otgorm/dependency_test.go b/otgorm/dependency_test.go index 83c94b8d..9fa46a30 100644 --- a/otgorm/dependency_test.go +++ b/otgorm/dependency_test.go @@ -17,11 +17,11 @@ func TestProvideDBFactory(t *testing.T) { Conf: config.MapAdapter{"gorm": map[string]databaseConf{ "default": { Database: "sqlite", - Dsn: "", + Dsn: ":memory:", }, "alternative": { - Database: "sqlite", - Dsn: "", + Database: "mysql", + Dsn: "root@tcp(127.0.0.1:3306)/app?charset=utf8mb4&parseTime=True&loc=Local", }, }}, Logger: log.NewNopLogger(),