github.com/tencent/goom@v1.0.1/builder_test.go (about) 1 package mocker 2 3 import ( 4 "runtime/debug" 5 "testing" 6 7 "github.com/stretchr/testify/suite" 8 ) 9 10 func TestBuilderTestSuite(t *testing.T) { 11 suite.Run(t, new(builderTestSuite)) 12 } 13 14 type builderTestSuite struct { 15 suite.Suite 16 } 17 18 func (s *builderTestSuite) TestBuilder_reset2CurPkg() { 19 tests := []struct { 20 name string 21 wants string 22 }{{ 23 name: "reset to current package", 24 wants: "github.com/tencent/goom", 25 }} 26 s.Run("success", func() { 27 for _, tt := range tests { 28 s.Run(tt.name, func() { 29 b := Create() 30 s.Equal(b.pkgName, tt.wants) 31 b.Func(fake) 32 s.Equal(b.pkgName, tt.wants) 33 }) 34 } 35 }) 36 } 37 38 func (s *builderTestSuite) Test_currentPackage() { 39 tests := []struct { 40 name string 41 want string 42 }{ 43 { 44 name: "get current package name", 45 want: "testing", 46 }, 47 } 48 for _, tt := range tests { 49 s.Run(tt.name, func() { 50 // called by testing.tRunner() 51 if got := currentPackage(); got != tt.want { 52 if !s.Equal(got, tt.want) { 53 debug.PrintStack() 54 } 55 } 56 }) 57 } 58 } 59 60 func (s *builderTestSuite) Test_currentPkg() { 61 type args struct { 62 skip int 63 } 64 tests := []struct { 65 name string 66 args args 67 want string 68 }{ 69 { 70 name: "skip 4", 71 args: args{ 72 skip: 4, 73 }, 74 want: "runtime", 75 }, 76 { 77 name: "skip 3", 78 args: args{ 79 skip: 3, 80 }, 81 want: "testing", 82 }, 83 { 84 name: "skip 2", 85 args: args{ 86 skip: 2, 87 }, 88 want: "github.com/stretchr/testify/suite", 89 }, 90 { 91 name: "skip 1(current package)", 92 args: args{ 93 skip: 1, 94 }, 95 want: "github.com/tencent/goom", 96 }, 97 { 98 name: "skip 0(currentPkg define in package)", 99 args: args{ 100 skip: 0, 101 }, 102 want: "github.com/tencent/goom", 103 }, 104 } 105 for _, tt := range tests { 106 s.Run(tt.name, func() { 107 if got := currentPkg(tt.args.skip); got != tt.want { 108 if !s.Equal(got, tt.want) { 109 debug.PrintStack() 110 } 111 } 112 }) 113 } 114 } 115 116 // fake 模拟函数 117 func fake() {}