Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix oceanbase #607

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also add oceanbase after Import and initialize databas (at line 172).

}
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"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need comment for this replace. And maybe it's better to keep the Driver as oceanbase to avoid mistakes to be introduced by others in the future.

}

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
Original file line number Diff line number Diff line change
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 (
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the indentation in the generated code correct?

"{{.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