@@ -67,9 +67,14 @@ func TestWriter_WriteRepo(t *testing.T) {
6767}
6868
6969func TestPatcher_PatchImports (t * testing.T ) {
70- data , err := os . ReadFile ( "../../../../tmp/ localsession/gls.go " )
70+ repoDir , err := testutils . GitCloneFast ( "github.com/cloudwego/ localsession" , "localsession" , "main " )
7171 if err != nil {
72- t .Errorf ("fail read file %v" , err )
72+ t .Errorf ("fail to clone repo %v" , err )
73+ }
74+ glsFile := repoDir + "/gls.go"
75+ data , err := os .ReadFile (glsFile )
76+ if err != nil {
77+ t .Errorf ("fail read file %v file: %s" , err , glsFile )
7378 return
7479 }
7580 alias1 := string ("_" )
@@ -90,15 +95,6 @@ func TestPatcher_PatchImports(t *testing.T) {
9095 "time"
9196 _ "runtime"
9297)
93- ` ), 1 )
94- data2 , err := os .ReadFile ("../../../../tmp/localsession/backup/xx_test.go" )
95- if err != nil {
96- t .Errorf ("fail read file %v" , err )
97- return
98- }
99- data2 = bytes .Replace (data2 , []byte (`package backup
100- ` ), []byte (`package backup
101- import "fmt"
10298` ), 1 )
10399
104100 type args struct {
@@ -110,35 +106,17 @@ import "fmt"
110106 want []byte
111107 wantErr bool
112108 }{
113- // {
114- // name: "empty new",
115- // args: args{
116- // file: &uniast.File{
117- // Name: "gls.go",
118- // Imports: []uniast.Import{},
119- // Path: "gls.go",
120- // },
121- // },
122- // want: data,
123- // wantErr: false,
124- // },
125- // {
126- // name: "empty old",
127- // args: args{
128- // file: &uniast.File{
129- // Name: "backup/xx_test.go",
130- // Imports: []uniast.Import{
131- // {
132- // Path: `"fmt"`,
133- // Alias: nil,
134- // },
135- // },
136- // Path: "backup/xx_test.go",
137- // },
138- // },
139- // want: data2,
140- // wantErr: false,
141- // },
109+ {
110+ name : "empty new" ,
111+ args : args {
112+ file : & uniast.File {
113+ Imports : []uniast.Import {},
114+ Path : glsFile ,
115+ },
116+ },
117+ want : data ,
118+ wantErr : false ,
119+ },
142120 {
143121 name : "add" ,
144122 args : args {
@@ -149,7 +127,7 @@ import "fmt"
149127 Alias : & alias1 ,
150128 },
151129 },
152- Path : "gls.go" ,
130+ Path : glsFile ,
153131 },
154132 },
155133 want : data1 ,
@@ -161,7 +139,8 @@ import "fmt"
161139 t .Run (tt .name , func (t * testing.T ) {
162140 old , err := os .ReadFile (tt .args .file .Path )
163141 if err != nil {
164- t .Errorf ("fail read file %v" , err )
142+ println ("wtf" , tt .args .file .Path )
143+ t .Errorf ("fail read file %v file: %s" , err , tt .args .file .Path )
165144 return
166145 }
167146 got , err := p .PatchImports (tt .args .file .Imports , old )
0 commit comments