@@ -11,28 +11,14 @@ import (
1111 "github.com/grafana/pyroscope/pkg/frontend/vcs/config"
1212)
1313
14- type VCSClientMock struct {
15- fileToFind string
16- searchedSequence []string
17- }
18-
19- func (c * VCSClientMock ) GetFile (ctx context.Context , req client.FileRequest ) (client.File , error ) {
20- c .searchedSequence = append (c .searchedSequence , req .Path )
21- if req .Path == c .fileToFind {
22- return client.File {}, nil
23- } else {
24- return client.File {}, client .ErrNotFound
25- }
26- }
27-
2814func Test_tryFindGoFile (t * testing.T ) {
2915 pyroscopeRepo , _ := giturl .NewGitURL ("http://github.com/grafana/pyroscope" )
3016 tests := []struct {
3117 name string
3218 searchedPath string
3319 rootPath string
3420 repo giturl.IGitURL
35- clientMock * VCSClientMock
21+ clientMock * mockVCSClient
3622 attempts int
3723 expectedSearchedPaths []string
3824 expectedError error
@@ -42,7 +28,7 @@ func Test_tryFindGoFile(t *testing.T) {
4228 searchedPath : "/var/service1/src/main.go" ,
4329 rootPath : "" ,
4430 repo : pyroscopeRepo ,
45- clientMock : & VCSClientMock { fileToFind : "/ main.go"} ,
31+ clientMock : newMockVCSClient (). addFiles ( newFile ( " main.go")) ,
4632 attempts : 5 ,
4733 expectedSearchedPaths : []string {"var/service1/src/main.go" , "service1/src/main.go" , "src/main.go" , "main.go" },
4834 expectedError : nil ,
@@ -52,7 +38,7 @@ func Test_tryFindGoFile(t *testing.T) {
5238 searchedPath : "/src/main.go" ,
5339 rootPath : "service/example" ,
5440 repo : pyroscopeRepo ,
55- clientMock : & VCSClientMock { fileToFind : "service/example/main.go" } ,
41+ clientMock : newMockVCSClient (). addFiles ( newFile ( "service/example/main.go" )) ,
5642 attempts : 5 ,
5743 expectedSearchedPaths : []string {"service/example/src/main.go" , "service/example/main.go" },
5844 expectedError : nil ,
@@ -62,7 +48,7 @@ func Test_tryFindGoFile(t *testing.T) {
6248 searchedPath : "github.com/grafana/pyroscope/main.go" ,
6349 rootPath : "" ,
6450 repo : pyroscopeRepo ,
65- clientMock : & VCSClientMock { fileToFind : "/ main.go"} ,
51+ clientMock : newMockVCSClient (). addFiles ( newFile ( " main.go")) ,
6652 attempts : 1 ,
6753 expectedSearchedPaths : []string {"main.go" },
6854 expectedError : nil ,
@@ -72,7 +58,7 @@ func Test_tryFindGoFile(t *testing.T) {
7258 searchedPath : "/Users/pyroscope/git/github.com/grafana/pyroscope/main.go" ,
7359 rootPath : "" ,
7460 repo : pyroscopeRepo ,
75- clientMock : & VCSClientMock { fileToFind : "/ main.go"} ,
61+ clientMock : newMockVCSClient (). addFiles ( newFile ( " main.go")) ,
7662 attempts : 1 ,
7763 expectedSearchedPaths : []string {"main.go" },
7864 expectedError : nil ,
@@ -82,7 +68,7 @@ func Test_tryFindGoFile(t *testing.T) {
8268 searchedPath : "/var/service1/src/main.go" ,
8369 rootPath : "" ,
8470 repo : pyroscopeRepo ,
85- clientMock : & VCSClientMock { fileToFind : "/ main.go"} ,
71+ clientMock : newMockVCSClient (). addFiles ( newFile ( " main.go")) ,
8672 attempts : 3 ,
8773 expectedSearchedPaths : []string {"var/service1/src/main.go" , "service1/src/main.go" , "src/main.go" },
8874 expectedError : client .ErrNotFound ,
@@ -94,6 +80,7 @@ func Test_tryFindGoFile(t *testing.T) {
9480 sut := FileFinder {
9581 file : config.FileSpec {Path : tt .searchedPath },
9682 rootPath : tt .rootPath ,
83+ ref : defaultRef ("" ),
9784 repo : tt .repo ,
9885 client : tt .clientMock ,
9986 }
0 commit comments