-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
138 additions
and
47 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
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,70 @@ | ||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved. | ||
// | ||
// This Source Code Form is subject to the terms of the MIT License. | ||
// If a copy of the MIT was not distributed with this file, | ||
// You can obtain one at https://github.com/gogf/gf. | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/gogf/gf/v2/os/gcmd" | ||
"github.com/gogf/gf/v2/os/gfile" | ||
"github.com/gogf/gf/v2/test/gtest" | ||
"github.com/gogf/gf/v2/text/gstr" | ||
"github.com/gogf/gf/v2/util/guid" | ||
) | ||
|
||
func Test_Gen_Pbentity_NameCase(t *testing.T) { | ||
gtest.C(t, func(t *gtest.T) { | ||
var ( | ||
err error | ||
db = testDB | ||
table = "table_user" | ||
sqlContent = fmt.Sprintf( | ||
gtest.DataContent(`genpbentity`, `user.tpl.sql`), | ||
table, | ||
) | ||
) | ||
dropTableWithDb(db, table) | ||
array := gstr.SplitAndTrim(sqlContent, ";") | ||
for _, v := range array { | ||
if _, err = db.Exec(ctx, v); err != nil { | ||
t.AssertNil(err) | ||
} | ||
} | ||
defer dropTableWithDb(db, table) | ||
var path = gfile.Temp(guid.S()) | ||
err = gfile.Mkdir(path) | ||
t.AssertNil(err) | ||
defer gfile.Remove(path) | ||
|
||
root, err := gcmd.NewFromObject(GF) | ||
t.AssertNil(err) | ||
err = root.AddObject( | ||
Gen, | ||
) | ||
t.AssertNil(err) | ||
os.Args = []string{"gf", "gen", "pbentity", "-l", link, "-p", path, "-package=unittest", "-nameCase=SnakeScreaming"} | ||
|
||
err = root.RunWithError(ctx) | ||
t.AssertNil(err) | ||
|
||
files := []string{ | ||
filepath.FromSlash(path + "/table_user.proto"), | ||
} | ||
|
||
testPath := gtest.DataPath("genpbentity", "generated_user") | ||
expectFiles := []string{ | ||
filepath.FromSlash(testPath + "/table_user.proto"), | ||
} | ||
// check files content | ||
for i := range files { | ||
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i])) | ||
} | ||
}) | ||
} |
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
21 changes: 21 additions & 0 deletions
21
cmd/gf/internal/cmd/testdata/genpbentity/generated_user/table_user.proto
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,21 @@ | ||
// ========================================================================== | ||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. | ||
// ========================================================================== | ||
|
||
syntax = "proto3"; | ||
|
||
package unittest; | ||
|
||
option go_package = "unittest"; | ||
|
||
import "google/protobuf/timestamp.proto"; | ||
|
||
message TableUser { | ||
uint32 ID = 1; // User ID | ||
string PASSPORT = 2; // User Passport | ||
string PASSWORD = 3; // User Password | ||
string NICKNAME = 4; // User Nickname | ||
string SCORE = 5; // Total score amount. | ||
google.protobuf.Timestamp CREATE_AT = 6; // Created Time | ||
google.protobuf.Timestamp UPDATE_AT = 7; // Updated Time | ||
} |
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,10 @@ | ||
CREATE TABLE `%s` ( | ||
`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'User ID', | ||
`passport` varchar(45) NOT NULL COMMENT 'User Passport', | ||
`password` varchar(45) NOT NULL COMMENT 'User Password', | ||
`nickname` varchar(45) NOT NULL COMMENT 'User Nickname', | ||
`score` decimal(10,2) unsigned DEFAULT NULL COMMENT 'Total score amount.', | ||
`create_at` datetime DEFAULT NULL COMMENT 'Created Time', | ||
`update_at` datetime DEFAULT NULL COMMENT 'Updated Time', | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; |