@@ -2085,8 +2085,49 @@ func Test_GetTag(t *testing.T) {
20852085 }
20862086}
20872087
2088- func Test_ResolveGitReference (t * testing.T ) {
2088+ func Test_filterPaths (t * testing.T ) {
2089+ tests := []struct {
2090+ name string
2091+ tree []* github.TreeEntry
2092+ path string
2093+ maxResults int
2094+ expected []string
2095+ }{
2096+ {
2097+ name : "file name" ,
2098+ tree : []* github.TreeEntry {
2099+ {Path : github .Ptr ("folder/foo.txt" ), Type : github .Ptr ("blob" )},
2100+ {Path : github .Ptr ("bar.txt" ), Type : github .Ptr ("blob" )},
2101+ {Path : github .Ptr ("nested/folder/foo.txt" ), Type : github .Ptr ("blob" )},
2102+ {Path : github .Ptr ("nested/folder/baz.txt" ), Type : github .Ptr ("blob" )},
2103+ },
2104+ path : "foo.txt" ,
2105+ maxResults : - 1 ,
2106+ expected : []string {"folder/foo.txt" , "nested/folder/foo.txt" },
2107+ },
2108+ {
2109+ name : "dir name" ,
2110+ tree : []* github.TreeEntry {
2111+ {Path : github .Ptr ("folder" ), Type : github .Ptr ("tree" )},
2112+ {Path : github .Ptr ("bar.txt" ), Type : github .Ptr ("blob" )},
2113+ {Path : github .Ptr ("nested/folder" ), Type : github .Ptr ("tree" )},
2114+ {Path : github .Ptr ("nested/folder/baz.txt" ), Type : github .Ptr ("blob" )},
2115+ },
2116+ path : "folder/" ,
2117+ maxResults : - 1 ,
2118+ expected : []string {"folder/" , "nested/folder/" },
2119+ },
2120+ }
2121+
2122+ for _ , tc := range tests {
2123+ t .Run (tc .name , func (t * testing.T ) {
2124+ result := filterPaths (tc .tree , tc .path , tc .maxResults )
2125+ assert .Equal (t , tc .expected , result )
2126+ })
2127+ }
2128+ }
20892129
2130+ func Test_resolveGitReference (t * testing.T ) {
20902131 ctx := context .Background ()
20912132 owner := "owner"
20922133 repo := "repo"
0 commit comments