优化结构
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"kra/internal/conf"
|
||||
"kra/internal/config"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
@@ -15,14 +15,14 @@ import (
|
||||
func TestDatabaseConnectionConfigured(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
config *conf.Data_Database
|
||||
config *config.Database
|
||||
want bool
|
||||
}{
|
||||
{name: "missing config", config: nil, want: false},
|
||||
{name: "empty database", config: &conf.Data_Database{Driver: "mysql"}, want: false},
|
||||
{name: "named database", config: &conf.Data_Database{Driver: "mysql", Name: "kra"}, want: true},
|
||||
{name: "standalone DSN", config: &conf.Data_Database{Driver: "sqlite", Source: "file:kra.db"}, want: true},
|
||||
{name: "generated DSN still requires a name", config: &conf.Data_Database{Driver: "mysql", Source: "root@tcp(localhost)/", Host: "localhost"}, want: false},
|
||||
{name: "empty database", config: &config.Database{Driver: "mysql"}, want: false},
|
||||
{name: "named database", config: &config.Database{Driver: "mysql", Name: "kra"}, want: true},
|
||||
{name: "standalone DSN", config: &config.Database{Driver: "sqlite", Source: "file:kra.db"}, want: true},
|
||||
{name: "generated DSN still requires a name", config: &config.Database{Driver: "mysql", Source: "root@tcp(localhost)/", Host: "localhost"}, want: false},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
@@ -78,9 +78,9 @@ extension:
|
||||
if err := os.WriteFile(configPath, []byte(original), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
runtime := conf.NewRuntime(&conf.Data{}, &conf.AdminBackend{ConfigPath: configPath})
|
||||
runtime := config.NewStore(&config.Data{}, &config.Admin{ConfigPath: configPath})
|
||||
data := &Data{runtime: runtime}
|
||||
if err := data.persistDatabaseConfig(&conf.Data_Database{Driver: "mysql", Host: "db", Port: "3306", User: "root", Password: "secret", Name: "kra", Config: "parseTime=True"}, "new-key"); err != nil {
|
||||
if err := data.persistDatabaseConfig(&config.Database{Driver: "mysql", Host: "db", Port: "3306", User: "root", Password: "secret", Name: "kra", Config: "parseTime=True"}, "new-key"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
raw, err := os.ReadFile(configPath)
|
||||
|
||||
Reference in New Issue
Block a user