@@ -19,6 +19,7 @@ package tool
1919import (
2020 "context"
2121 "reflect"
22+ "sort"
2223 "testing"
2324
2425 "github.com/cloudwego/eino/components/tool"
@@ -180,6 +181,22 @@ func TestASTTools_GetRepoStructure(t *testing.T) {
180181 RepoName : "metainfo" ,
181182 },
182183 },
184+ want : & GetRepoStructResp {
185+ Modules : []ModuleStruct {
186+ {
187+ ModPath : "metainfo" ,
188+ Packages : []PackageStruct {
189+ {PkgPath : "metainfo" , Files : []FileStruct {{FilePath : "src/lib.rs" }}},
190+ {PkgPath : "metainfo::backward" , Files : []FileStruct {{FilePath : "src/backward.rs" }}},
191+ {PkgPath : "metainfo::convert" , Files : []FileStruct {{FilePath : "src/convert.rs" }}},
192+ {PkgPath : "metainfo::faststr_map" , Files : []FileStruct {{FilePath : "src/faststr_map.rs" }}},
193+ {PkgPath : "metainfo::forward" , Files : []FileStruct {{FilePath : "src/forward.rs" }}},
194+ {PkgPath : "metainfo::kv" , Files : []FileStruct {{FilePath : "src/kv.rs" }}},
195+ {PkgPath : "metainfo::type_map" , Files : []FileStruct {{FilePath : "src/type_map.rs" }}},
196+ },
197+ },
198+ },
199+ },
183200 },
184201 {
185202 name : "test" ,
@@ -194,8 +211,66 @@ func TestASTTools_GetRepoStructure(t *testing.T) {
194211 RepoName : "localsession" ,
195212 },
196213 },
214+ want : & GetRepoStructResp {
215+ Modules : []ModuleStruct {
216+ {
217+ ModPath : "github.com/cloudwego/localsession" ,
218+ Packages : []PackageStruct {
219+ {
220+ PkgPath : "github.com/cloudwego/localsession" ,
221+ Files : []FileStruct {
222+ {FilePath : "gls.go" },
223+ {FilePath : "manager.go" },
224+ {FilePath : "session.go" },
225+ {FilePath : "stubs.go" },
226+ },
227+ },
228+ {
229+ PkgPath : "github.com/cloudwego/localsession [github.com/cloudwego/localsession.test]" ,
230+ Files : []FileStruct {
231+ {FilePath : "api_test.go" },
232+ {FilePath : "example_test.go" },
233+ },
234+ },
235+ {
236+ PkgPath : "github.com/cloudwego/localsession/backup" ,
237+ Files : []FileStruct {
238+ {FilePath : "backup/metainfo.go" },
239+ },
240+ },
241+ {
242+ PkgPath : "github.com/cloudwego/localsession/backup [github.com/cloudwego/localsession/backup.test]" ,
243+ Files : []FileStruct {
244+ {FilePath : "backup/metainfo_test.go" },
245+ },
246+ },
247+ },
248+ },
249+ },
250+ },
197251 },
198252 }
253+ sortResp := func (resp * GetRepoStructResp ) {
254+ if resp == nil {
255+ return
256+ }
257+ sort .Slice (resp .Modules , func (i , j int ) bool {
258+ return resp .Modules [i ].ModPath < resp .Modules [j ].ModPath
259+ })
260+ for i := range resp .Modules {
261+ mod := & resp .Modules [i ]
262+ sort .Slice (mod .Packages , func (i , j int ) bool {
263+ return mod .Packages [i ].PkgPath < mod .Packages [j ].PkgPath
264+ })
265+ for j := range mod .Packages {
266+ pkg := & mod .Packages [j ]
267+ sort .Slice (pkg .Files , func (i , j int ) bool {
268+ return pkg .Files [i ].FilePath < pkg .Files [j ].FilePath
269+ })
270+ }
271+ }
272+ }
273+
199274 for _ , tt := range tests {
200275 t .Run (tt .name , func (t * testing.T ) {
201276 tr := NewASTReadTools (tt .fields .opts )
@@ -204,6 +279,8 @@ func TestASTTools_GetRepoStructure(t *testing.T) {
204279 t .Errorf ("ASTTools.GetRepoStructure() error = %v, wantErr %v" , err , tt .wantErr )
205280 return
206281 }
282+ sortResp (got )
283+ sortResp (tt .want )
207284 if ! reflect .DeepEqual (got , tt .want ) {
208285 t .Errorf ("ASTTools.GetRepoStructure() = %v, want %v" , got , tt .want )
209286 }
0 commit comments