Skip to content

Commit

Permalink
fix oceanbase
Browse files Browse the repository at this point in the history
  • Loading branch information
wayyoungboy committed Mar 26, 2024
1 parent e21f811 commit 22a4cd9
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 56 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -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/
Expand Down
6 changes: 5 additions & 1 deletion adm/db.go
Expand Up @@ -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 {
Expand All @@ -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")
Expand Down
27 changes: 23 additions & 4 deletions adm/project.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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))
Expand Down Expand Up @@ -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))
}

Expand Down
103 changes: 52 additions & 51 deletions adm/project_template.go
Expand Up @@ -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"
Expand Down Expand Up @@ -1363,7 +1363,8 @@ func TestMainUserAcceptance(t *testing.T) {
<-quit
log.Print("test quit")
}, true)
}`)
}`,
}

var makefile = []byte(`GOCMD = go
GOBUILD = $(GOCMD) build
Expand Down

0 comments on commit 22a4cd9

Please sign in to comment.