Added unit test cases for the new flags '-allow-tables', '-allow-views', and '-allow-enums'.

This commit is contained in:
SanjaiyKumar 2025-06-18 16:02:36 +05:30
parent bfb02acb43
commit c35892320d
4 changed files with 319 additions and 14 deletions

View file

@ -1384,3 +1384,141 @@ func newLinkTableImpl(schemaName, tableName, alias string) linkTable {
}
}
`
func TestAllowTablesViewsEnums(t *testing.T) {
tests := []struct {
name string
args []string
}{
{
name: "with dsn",
args: []string{
"-dsn=" + defaultDSN(),
"-schema=dvds",
"-allow-tables=actor,ADDRESS,country, Film , cITY,",
"-allow-views=Actor_info, FILM_LIST ,staff_list",
"-allow-enums=mpaa_rating",
"-path=" + genTestDir2,
},
},
{
name: "without dsn",
args: []string{
"-source=PostgreSQL",
"-host=localhost",
"-port=" + strconv.Itoa(dbconfig.PgPort),
"-user=jet",
"-password=jet",
"-dbname=jetdb",
"-schema=dvds",
"-allow-tables=actor,ADDRESS,country, Film , cITY,",
"-allow-views=Actor_info, FILM_LIST ,staff_list",
"-allow-enums=mpaa_rating",
"-path=" + genTestDir2,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := os.RemoveAll(genTestDir2)
require.NoError(t, err)
cmd := exec.Command("jet", tt.args...)
fmt.Println(cmd.Args)
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
err = cmd.Run()
require.NoError(t, err)
// Table SQL Builder files
testutils.AssertFileNamesEqual(t, "./.gentestdata2/jetdb/dvds/table", "actor.go", "address.go",
"country.go", "film.go", "city.go", "table_use_schema.go")
// View SQL Builder files
testutils.AssertFileNamesEqual(t, "./.gentestdata2/jetdb/dvds/view", "actor_info.go", "film_list.go",
"staff_list.go", "view_use_schema.go")
// Enums SQL Builder files
file.Exists(t, "./.gentestdata2/jetdb/dvds/enum", "mpaa_rating.go")
// Model files
testutils.AssertFileNamesEqual(t, "./.gentestdata2/jetdb/dvds/model", "actor.go", "address.go",
"country.go", "film.go", "city.go", "actor_info.go", "film_list.go", "staff_list.go", "mpaa_rating.go")
})
}
}
func TestAllowAndIgnoreTablesViewsEnums(t *testing.T) {
tests := []struct {
name string
args []string
}{
{
name: "with dsn",
args: []string{
"-dsn=" + defaultDSN(),
"-schema=dvds",
"-allow-tables=actor,ADDRESS,country, Film , cITY,",
"-allow-views=Actor_info, FILM_LIST ,staff_list",
"-allow-enums=mpaa_rating",
"-ignore-tables=ADDRESS,country, Film",
"-ignore-views=FILM_LIST",
"-ignore-enums=mpaa_rating",
"-path=" + genTestDir2,
},
},
{
name: "without dsn",
args: []string{
"-source=PostgreSQL",
"-host=localhost",
"-port=" + strconv.Itoa(dbconfig.PgPort),
"-user=jet",
"-password=jet",
"-dbname=jetdb",
"-schema=dvds",
"-allow-tables=actor,ADDRESS,country, Film , cITY,",
"-allow-views=Actor_info, FILM_LIST ,staff_list",
"-allow-enums=mpaa_rating",
"-ignore-tables=ADDRESS,country, Film",
"-ignore-views=FILM_LIST",
"-ignore-enums=mpaa_rating",
"-path=" + genTestDir2,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := os.RemoveAll(genTestDir2)
require.NoError(t, err)
cmd := exec.Command("jet", tt.args...)
fmt.Println(cmd.Args)
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
err = cmd.Run()
require.NoError(t, err)
// Table SQL Builder files
testutils.AssertFileNamesEqual(t, "./.gentestdata2/jetdb/dvds/table", "actor.go", "address.go",
"country.go", "film.go", "city.go", "table_use_schema.go")
// View SQL Builder files
testutils.AssertFileNamesEqual(t, "./.gentestdata2/jetdb/dvds/view", "actor_info.go", "film_list.go",
"staff_list.go", "view_use_schema.go")
// Enums SQL Builder files
file.Exists(t, "./.gentestdata2/jetdb/dvds/enum", "mpaa_rating.go")
// Model files
testutils.AssertFileNamesEqual(t, "./.gentestdata2/jetdb/dvds/model", "actor.go", "address.go",
"country.go", "film.go", "city.go", "actor_info.go", "film_list.go", "staff_list.go", "mpaa_rating.go")
})
}
}