forked from zeromicro/go-zero
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* model/rpc generate code from template cache * delete unused(deprecated) code * support template init|update|clean|revert * model: return the execute result for insert and update operation * // deprecated: containsAny * add template test * add default buildVersion * update build version
- Loading branch information
Keson
authored
Oct 21, 2020
1 parent
fe0d068
commit 41964f9
Showing
43 changed files
with
904 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package gogen | ||
|
||
import ( | ||
"io/ioutil" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/tal-tech/go-zero/tools/goctl/util" | ||
) | ||
|
||
func TestGenTemplates(t *testing.T) { | ||
err := util.InitTemplates(category, templates) | ||
assert.Nil(t, err) | ||
dir, err := util.GetTemplateDir(category) | ||
assert.Nil(t, err) | ||
file := filepath.Join(dir, "main.tpl") | ||
data, err := ioutil.ReadFile(file) | ||
assert.Nil(t, err) | ||
assert.Equal(t, string(data), mainTemplate) | ||
} | ||
|
||
func TestRevertTemplate(t *testing.T) { | ||
name := "main.tpl" | ||
err := util.InitTemplates(category, templates) | ||
assert.Nil(t, err) | ||
|
||
dir, err := util.GetTemplateDir(category) | ||
assert.Nil(t, err) | ||
|
||
file := filepath.Join(dir, name) | ||
data, err := ioutil.ReadFile(file) | ||
assert.Nil(t, err) | ||
|
||
modifyData := string(data) + "modify" | ||
err = util.CreateTemplate(category, name, modifyData) | ||
assert.Nil(t, err) | ||
|
||
data, err = ioutil.ReadFile(file) | ||
assert.Nil(t, err) | ||
|
||
assert.Equal(t, string(data), modifyData) | ||
|
||
assert.Nil(t, RevertTemplate(name)) | ||
|
||
data, err = ioutil.ReadFile(file) | ||
assert.Nil(t, err) | ||
assert.Equal(t, mainTemplate, string(data)) | ||
} | ||
|
||
func TestClean(t *testing.T) { | ||
name := "main.tpl" | ||
err := util.InitTemplates(category, templates) | ||
assert.Nil(t, err) | ||
|
||
assert.Nil(t, Clean()) | ||
|
||
dir, err := util.GetTemplateDir(category) | ||
assert.Nil(t, err) | ||
|
||
file := filepath.Join(dir, name) | ||
_, err = ioutil.ReadFile(file) | ||
assert.NotNil(t, err) | ||
} | ||
|
||
func TestUpdate(t *testing.T) { | ||
name := "main.tpl" | ||
err := util.InitTemplates(category, templates) | ||
assert.Nil(t, err) | ||
|
||
dir, err := util.GetTemplateDir(category) | ||
assert.Nil(t, err) | ||
|
||
file := filepath.Join(dir, name) | ||
data, err := ioutil.ReadFile(file) | ||
assert.Nil(t, err) | ||
|
||
modifyData := string(data) + "modify" | ||
err = util.CreateTemplate(category, name, modifyData) | ||
assert.Nil(t, err) | ||
|
||
data, err = ioutil.ReadFile(file) | ||
assert.Nil(t, err) | ||
|
||
assert.Equal(t, string(data), modifyData) | ||
|
||
assert.Nil(t, Update(category)) | ||
|
||
data, err = ioutil.ReadFile(file) | ||
assert.Nil(t, err) | ||
assert.Equal(t, mainTemplate, string(data)) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
# Change log | ||
|
||
## 2020-10-19 | ||
|
||
* 增加template | ||
|
||
## 2020-08-20 | ||
|
||
* 新增支持通过连接数据库生成model | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package converter | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestConvertDataType(t *testing.T) { | ||
v, err := ConvertDataType("tinyint") | ||
assert.Nil(t, err) | ||
assert.Equal(t, "int64", v) | ||
|
||
v, err = ConvertDataType("timestamp") | ||
assert.Nil(t, err) | ||
assert.Equal(t, "time.Time", v) | ||
|
||
_, err = ConvertDataType("float32") | ||
assert.NotNil(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.