@@ -13,6 +13,8 @@ import (
13
13
14
14
"github.com/gogf/gf/cmd/gf/v2/internal/cmd/gendao"
15
15
"github.com/gogf/gf/v2/database/gdb"
16
+ "github.com/gogf/gf/v2/frame/g"
17
+ "github.com/gogf/gf/v2/os/gcfg"
16
18
"github.com/gogf/gf/v2/os/gfile"
17
19
"github.com/gogf/gf/v2/test/gtest"
18
20
"github.com/gogf/gf/v2/text/gstr"
@@ -245,7 +247,7 @@ func Test_Gen_Dao_Issue2572(t *testing.T) {
245
247
group = "test"
246
248
in = gendao.CGenDaoInput {
247
249
Path : path ,
248
- Link : link ,
250
+ Link : "" ,
249
251
Tables : "" ,
250
252
TablesEx : "" ,
251
253
Group : group ,
@@ -333,7 +335,7 @@ func Test_Gen_Dao_Issue2616(t *testing.T) {
333
335
group = "test"
334
336
in = gendao.CGenDaoInput {
335
337
Path : path ,
336
- Link : link ,
338
+ Link : "" ,
337
339
Tables : "" ,
338
340
TablesEx : "" ,
339
341
Group : group ,
@@ -486,3 +488,99 @@ func Test_Gen_Dao_Issue2746(t *testing.T) {
486
488
t .Assert (expectContent , gfile .GetContents (file ))
487
489
})
488
490
}
491
+
492
+ // https://github.com/gogf/gf/issues/3459
493
+ func Test_Gen_Dao_Issue3459 (t * testing.T ) {
494
+ gtest .C (t , func (t * gtest.T ) {
495
+ var (
496
+ err error
497
+ db = testDB
498
+ table = "table_user"
499
+ sqlContent = fmt .Sprintf (
500
+ gtest .DataContent (`gendao` , `user.tpl.sql` ),
501
+ table ,
502
+ )
503
+ )
504
+ dropTableWithDb (db , table )
505
+ array := gstr .SplitAndTrim (sqlContent , ";" )
506
+ for _ , v := range array {
507
+ if _ , err = db .Exec (ctx , v ); err != nil {
508
+ t .AssertNil (err )
509
+ }
510
+ }
511
+ defer dropTableWithDb (db , table )
512
+
513
+ var (
514
+ confDir = gtest .DataPath ("issue" , "3459" )
515
+ path = gfile .Temp (guid .S ())
516
+ group = "test"
517
+ in = gendao.CGenDaoInput {
518
+ Path : path ,
519
+ Link : link ,
520
+ Tables : "" ,
521
+ TablesEx : "" ,
522
+ Group : group ,
523
+ Prefix : "" ,
524
+ RemovePrefix : "" ,
525
+ JsonCase : "SnakeScreaming" ,
526
+ ImportPrefix : "" ,
527
+ DaoPath : "" ,
528
+ DoPath : "" ,
529
+ EntityPath : "" ,
530
+ TplDaoIndexPath : "" ,
531
+ TplDaoInternalPath : "" ,
532
+ TplDaoDoPath : "" ,
533
+ TplDaoEntityPath : "" ,
534
+ StdTime : false ,
535
+ WithTime : false ,
536
+ GJsonSupport : false ,
537
+ OverwriteDao : false ,
538
+ DescriptionTag : false ,
539
+ NoJsonTag : false ,
540
+ NoModelComment : false ,
541
+ Clear : false ,
542
+ TypeMapping : nil ,
543
+ }
544
+ )
545
+ err = g .Cfg ().GetAdapter ().(* gcfg.AdapterFile ).SetPath (confDir )
546
+ t .AssertNil (err )
547
+
548
+ err = gutil .FillStructWithDefault (& in )
549
+ t .AssertNil (err )
550
+
551
+ err = gfile .Mkdir (path )
552
+ t .AssertNil (err )
553
+
554
+ // for go mod import path auto retrieve.
555
+ err = gfile .Copy (
556
+ gtest .DataPath ("gendao" , "go.mod.txt" ),
557
+ gfile .Join (path , "go.mod" ),
558
+ )
559
+ t .AssertNil (err )
560
+
561
+ _ , err = gendao.CGenDao {}.Dao (ctx , in )
562
+ t .AssertNil (err )
563
+ defer gfile .Remove (path )
564
+
565
+ // files
566
+ files , err := gfile .ScanDir (path , "*.go" , true )
567
+ t .AssertNil (err )
568
+ t .Assert (files , []string {
569
+ filepath .FromSlash (path + "/dao/internal/table_user.go" ),
570
+ filepath .FromSlash (path + "/dao/table_user.go" ),
571
+ filepath .FromSlash (path + "/model/do/table_user.go" ),
572
+ filepath .FromSlash (path + "/model/entity/table_user.go" ),
573
+ })
574
+ // content
575
+ testPath := gtest .DataPath ("gendao" , "generated_user" )
576
+ expectFiles := []string {
577
+ filepath .FromSlash (testPath + "/dao/internal/table_user.go" ),
578
+ filepath .FromSlash (testPath + "/dao/table_user.go" ),
579
+ filepath .FromSlash (testPath + "/model/do/table_user.go" ),
580
+ filepath .FromSlash (testPath + "/model/entity/table_user.go" ),
581
+ }
582
+ for i , _ := range files {
583
+ t .Assert (gfile .GetContents (files [i ]), gfile .GetContents (expectFiles [i ]))
584
+ }
585
+ })
586
+ }
0 commit comments