From 22a4cd9009809e9b62fcad39eb93fa6ffecb7192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=A0=E7=A3=8A?= Date: Tue, 26 Mar 2024 16:38:08 +0800 Subject: [PATCH] fix oceanbase --- Makefile | 1 + adm/db.go | 6 ++- adm/project.go | 27 +++++++++-- adm/project_template.go | 103 ++++++++++++++++++++-------------------- 4 files changed, 81 insertions(+), 56 deletions(-) diff --git a/Makefile b/Makefile index 3227b64cd..18cb46cbc 100644 --- a/Makefile +++ b/Makefile @@ -150,6 +150,7 @@ cli: zip -qj ./adm/build/windows/i386/adm_windows_i386_$(VERSION).zip ./adm/build/windows/i386/adm.exe zip -qj ./adm/build/mac/adm_darwin_x86_64_$(VERSION).zip ./adm/build/mac/adm rm -rf ./adm/build/zip/* + mkdir -p ./adm/build/zip/ cp ./adm/build/linux/armel/adm_linux_armel_$(VERSION).zip ./adm/build/zip/ cp ./adm/build/linux/x86_64/adm_linux_x86_64_$(VERSION).zip ./adm/build/zip/ cp ./adm/build/windows/x86_64/adm_windows_x86_64_$(VERSION).zip ./adm/build/zip/ diff --git a/adm/db.go b/adm/db.go index 43b04cc31..e0217dad5 100644 --- a/adm/db.go +++ b/adm/db.go @@ -67,7 +67,7 @@ func askForDBConfig(info *dbInfo) config.DatabaseList { if info.DriverName == "" { info.DriverName = singleSelect(getWord("choose a driver"), - []string{db.DriverMysql, db.DriverPostgresql, db.DriverSqlite, db.DriverMssql}, db.DriverMysql) + []string{db.DriverMysql, db.DriverPostgresql, db.DriverSqlite, db.DriverMssql, db.DriverOceanBase}, db.DriverMysql) } if info.DriverName != db.DriverSqlite { @@ -84,6 +84,10 @@ func askForDBConfig(info *dbInfo) config.DatabaseList { defaultPort = "1433" defaultUser = "sa" } + if info.DriverName == db.DriverOceanBase { + defaultPort = "2881" + defaultUser = "root@sys" + } if info.Host == "" { info.Host = promptWithDefault("sql address", "127.0.0.1") diff --git a/adm/project.go b/adm/project.go index e65c7b20f..ed02c8884 100644 --- a/adm/project.go +++ b/adm/project.go @@ -116,7 +116,7 @@ func buildProject(cfgFile string) { } if p.Driver == "" { p.Driver = singleSelect(getWord("choose a driver"), - []string{"mysql", "postgresql", "sqlite", "mssql"}, "mysql") + []string{"mysql", "postgresql", "sqlite", "mssql", "oceanbase"}, "mysql") } p.DriverModule = p.Driver if p.Driver == db.DriverPostgresql { @@ -238,6 +238,9 @@ func GetCurrentDirectory() string { } func installProjectTmpl(p Project, cfg *config.Config, cfgFile string, info *dbInfo) { + if p.Driver == "oceanbase" { + p.Driver = "OceanBase" + } t, err := template.New("project").Funcs(map[string]interface{}{ "title": strings.Title, @@ -248,7 +251,7 @@ func installProjectTmpl(p Project, cfg *config.Config, cfgFile string, info *dbI c, err := format.Source(buf.Bytes()) checkError(err) checkError(ioutil.WriteFile("./main.go", c, 0644)) - + p.Driver = "oceanbase" checkError(os.Mkdir("pages", os.ModePerm)) checkError(os.Mkdir("tables", os.ModePerm)) checkError(os.Mkdir("logs", os.ModePerm)) @@ -291,10 +294,26 @@ func Init(c db.Connection) { } if defaultLang == "cn" || p.Language == language.CN || p.Language == "cn" { - checkError(ioutil.WriteFile("./main_test.go", mainTestCN, 0644)) + t, err := template.New("project").Funcs(map[string]interface{}{ + "title": strings.Title, + }).Parse(mainTest["mainTestCN"]) + checkError(err) + buf := new(bytes.Buffer) + checkError(t.Execute(buf, p)) + c, err := format.Source(buf.Bytes()) + checkError(err) + checkError(ioutil.WriteFile("./main_test.go", c, 0644)) checkError(ioutil.WriteFile("./README.md", []byte(fmt.Sprintf(readmeCN, p.Port+"/"+p.Prefix)), 0644)) } else { - checkError(ioutil.WriteFile("./main_test.go", mainTest, 0644)) + t, err := template.New("project").Funcs(map[string]interface{}{ + "title": strings.Title, + }).Parse(mainTest["mainTest"]) + checkError(err) + buf := new(bytes.Buffer) + checkError(t.Execute(buf, p)) + c, err := format.Source(buf.Bytes()) + checkError(err) + checkError(ioutil.WriteFile("./main_test.go", c, 0644)) checkError(ioutil.WriteFile("./README.md", []byte(fmt.Sprintf(readme, p.Port+"/"+p.Prefix)), 0644)) } diff --git a/adm/project_template.go b/adm/project_template.go index 672debefa..7c07ab0b9 100644 --- a/adm/project_template.go +++ b/adm/project_template.go @@ -1269,58 +1269,58 @@ like Aldus PageMaker including versions of Lorem Ipsum. }, nil }`) -var mainTest = []byte(`package main - -import ( - "./tables" - "github.com/GoAdminGroup/go-admin/modules/config" - "github.com/GoAdminGroup/go-admin/tests" - "github.com/GoAdminGroup/go-admin/tests/common" - "github.com/GoAdminGroup/go-admin/tests/frameworks/gin" - "github.com/GoAdminGroup/go-admin/tests/web" - "github.com/gavv/httpexpect" - "log" - "testing" -) - -// Black box testing -func TestMainBlackBox(t *testing.T) { - cfg := config.ReadFromJson("./config.json") - tests.BlackBoxTestSuit(t, gin.NewHandler, cfg.Databases, tables.Generators, func(cfg config.DatabaseList) { - // Data cleaner of the framework - tests.Cleaner(cfg) - // Clean your own data: - // ... - }, func(e *httpexpect.Expect) { - // Test cases of the framework - common.Test(e) - // Write your own API test, for example: - // More usages: https://github.com/gavv/httpexpect - // e.POST("/signin").Expect().Status(http.StatusOK) - }) -} - -// User acceptance testing -func TestMainUserAcceptance(t *testing.T) { - web.UserAcceptanceTestSuit(t, func(t *testing.T, page *web.Page) { - // Write test case base on chromedriver, for example: - // More usages: https://github.com/sclevine/agouti - page.NavigateTo("http://127.0.0.1:9033/admin") - //page.Contain("username") - //page.Click("") - }, func(quit chan struct{}) { - // start the server: - // .... - go startServer() - <-quit - log.Print("test quit") - }, true) // if local parameter is true, it will not be headless, and window not close when finishing tests. -}`) - -var mainTestCN = []byte(`package main +var mainTest = map[string]string{ + "mainTest": `package main + + import ( + "{{.Module}}/tables" + "github.com/GoAdminGroup/go-admin/modules/config" + "github.com/GoAdminGroup/go-admin/tests" + "github.com/GoAdminGroup/go-admin/tests/common" + "github.com/GoAdminGroup/go-admin/tests/frameworks/gin" + "github.com/GoAdminGroup/go-admin/tests/web" + "github.com/gavv/httpexpect" + "log" + "testing" + ) + + // Black box testing + func TestMainBlackBox(t *testing.T) { + cfg := config.ReadFromJson("./config.json") + tests.BlackBoxTestSuit(t, gin.NewHandler, cfg.Databases, tables.Generators, func(cfg config.DatabaseList) { + // Data cleaner of the framework + tests.Cleaner(cfg) + // Clean your own data: + // ... + }, func(e *httpexpect.Expect) { + // Test cases of the framework + common.Test(e) + // Write your own API test, for example: + // More usages: https://github.com/gavv/httpexpect + // e.POST("/signin").Expect().Status(http.StatusOK) + }) + } + + // User acceptance testing + func TestMainUserAcceptance(t *testing.T) { + web.UserAcceptanceTestSuit(t, func(t *testing.T, page *web.Page) { + // Write test case base on chromedriver, for example: + // More usages: https://github.com/sclevine/agouti + page.NavigateTo("http://127.0.0.1:9033/admin") + //page.Contain("username") + //page.Click("") + }, func(quit chan struct{}) { + // start the server: + // .... + go startServer() + <-quit + log.Print("test quit") + }, true) // if local parameter is true, it will not be headless, and window not close when finishing tests. + }`, + "mainTestCN": `package main import ( - "./tables" + "{{.Module}}/tables" "github.com/GoAdminGroup/go-admin/modules/config" "github.com/GoAdminGroup/go-admin/tests" "github.com/GoAdminGroup/go-admin/tests/common" @@ -1363,7 +1363,8 @@ func TestMainUserAcceptance(t *testing.T) { <-quit log.Print("test quit") }, true) -}`) +}`, +} var makefile = []byte(`GOCMD = go GOBUILD = $(GOCMD) build