@@ -11,37 +11,39 @@ import (
11
11
godiff "github.com/sourcegraph/go-diff/diff"
12
12
13
13
"github.com/sourcegraph/sourcegraph/internal/api"
14
-
15
14
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared"
15
+ "github.com/sourcegraph/sourcegraph/internal/codeintel/core"
16
16
"github.com/sourcegraph/sourcegraph/internal/gitserver"
17
17
sgtypes "github.com/sourcegraph/sourcegraph/internal/types"
18
18
)
19
19
20
+ var mockRequestArgs = requestArgs {
21
+ repo : & sgtypes.Repo {ID : 50 },
22
+ commit : "deadbeef1" ,
23
+ path : core .NewRepoRelPathUnchecked ("foo/bar.go" ),
24
+ }
25
+
20
26
func TestGetTargetCommitPathFromSourcePath (t * testing.T ) {
21
27
client := gitserver .NewMockClient ()
22
28
23
- args := & requestArgs {
24
- repo : & sgtypes.Repo {ID : 50 },
25
- commit : "deadbeef1" ,
26
- path : "/foo/bar.go" ,
27
- }
29
+ args := & mockRequestArgs
28
30
adjuster := NewGitTreeTranslator (client , args , nil )
29
- path , ok , err := adjuster .GetTargetCommitPathFromSourcePath (context .Background (), "deadbeef2" , "/foo/bar.go" , false )
31
+ path , ok , err := adjuster .GetTargetCommitPathFromSourcePath (context .Background (), "deadbeef2" , args . path . RawValue () , false )
30
32
if err != nil {
31
33
t .Fatalf ("unexpected error: %s" , err )
32
34
}
33
35
34
36
if ! ok {
35
37
t .Errorf ("expected translation to succeed" )
36
38
}
37
- if path != "/ foo/bar.go" {
38
- t .Errorf ("unexpected path. want=%s have=%s" , "/ foo/bar.go" , path )
39
+ if path != "foo/bar.go" {
40
+ t .Errorf ("unexpected path. want=%s have=%s" , "foo/bar.go" , path )
39
41
}
40
42
}
41
43
42
44
func TestGetTargetCommitPositionFromSourcePosition (t * testing.T ) {
43
45
client := gitserver .NewMockClientWithExecReader (nil , func (_ context.Context , _ api.RepoName , args []string ) (reader io.ReadCloser , err error ) {
44
- expectedArgs := []string {"diff" , "--find-renames" , "--full-index" , "--inter-hunk-context=3" , "--no-prefix" , "deadbeef1..deadbeef2" , "--" , "/foo/bar.go" }
46
+ expectedArgs := []string {"diff" , "--find-renames" , "--full-index" , "--inter-hunk-context=3" , "--no-prefix" , "deadbeef1..deadbeef2" , "--" , mockRequestArgs . path . RawValue () }
45
47
if diff := cmp .Diff (expectedArgs , args ); diff != "" {
46
48
t .Errorf ("unexpected exec reader args (-want +got):\n %s" , diff )
47
49
}
@@ -51,11 +53,7 @@ func TestGetTargetCommitPositionFromSourcePosition(t *testing.T) {
51
53
52
54
posIn := shared.Position {Line : 302 , Character : 15 }
53
55
54
- args := & requestArgs {
55
- repo : & sgtypes.Repo {ID : 50 },
56
- commit : "deadbeef1" ,
57
- path : "/foo/bar.go" ,
58
- }
56
+ args := & mockRequestArgs
59
57
adjuster := NewGitTreeTranslator (client , args , nil )
60
58
path , posOut , ok , err := adjuster .GetTargetCommitPositionFromSourcePosition (context .Background (), "deadbeef2" , posIn , false )
61
59
if err != nil {
@@ -65,8 +63,8 @@ func TestGetTargetCommitPositionFromSourcePosition(t *testing.T) {
65
63
if ! ok {
66
64
t .Errorf ("expected translation to succeed" )
67
65
}
68
- if path != "/ foo/bar.go" {
69
- t .Errorf ("unexpected path. want=%s have=%s" , "/ foo/bar.go" , path )
66
+ if path != "foo/bar.go" {
67
+ t .Errorf ("unexpected path. want=%s have=%s" , "foo/bar.go" , path )
70
68
}
71
69
72
70
expectedPos := shared.Position {Line : 294 , Character : 15 }
@@ -82,11 +80,7 @@ func TestGetTargetCommitPositionFromSourcePositionEmptyDiff(t *testing.T) {
82
80
83
81
posIn := shared.Position {Line : 10 , Character : 15 }
84
82
85
- args := & requestArgs {
86
- repo : & sgtypes.Repo {ID : 50 },
87
- commit : "deadbeef1" ,
88
- path : "/foo/bar.go" ,
89
- }
83
+ args := & mockRequestArgs
90
84
adjuster := NewGitTreeTranslator (client , args , nil )
91
85
path , posOut , ok , err := adjuster .GetTargetCommitPositionFromSourcePosition (context .Background (), "deadbeef2" , posIn , false )
92
86
if err != nil {
@@ -96,8 +90,8 @@ func TestGetTargetCommitPositionFromSourcePositionEmptyDiff(t *testing.T) {
96
90
if ! ok {
97
91
t .Errorf ("expected translation to succeed" )
98
92
}
99
- if path != "/ foo/bar.go" {
100
- t .Errorf ("unexpected path. want=%s have=%s" , "/ foo/bar.go" , path )
93
+ if path != "foo/bar.go" {
94
+ t .Errorf ("unexpected path. want=%s have=%s" , "foo/bar.go" , path )
101
95
}
102
96
if diff := cmp .Diff (posOut , posIn ); diff != "" {
103
97
t .Errorf ("unexpected position (-want +got):\n %s" , diff )
@@ -106,7 +100,7 @@ func TestGetTargetCommitPositionFromSourcePositionEmptyDiff(t *testing.T) {
106
100
107
101
func TestGetTargetCommitPositionFromSourcePositionReverse (t * testing.T ) {
108
102
client := gitserver .NewMockClientWithExecReader (nil , func (_ context.Context , _ api.RepoName , args []string ) (reader io.ReadCloser , err error ) {
109
- expectedArgs := []string {"diff" , "--find-renames" , "--full-index" , "--inter-hunk-context=3" , "--no-prefix" , "deadbeef2..deadbeef1" , "--" , "/foo/bar.go" }
103
+ expectedArgs := []string {"diff" , "--find-renames" , "--full-index" , "--inter-hunk-context=3" , "--no-prefix" , "deadbeef2..deadbeef1" , "--" , mockRequestArgs . path . RawValue () }
110
104
if diff := cmp .Diff (expectedArgs , args ); diff != "" {
111
105
t .Errorf ("unexpected exec reader args (-want +got):\n %s" , diff )
112
106
}
@@ -116,11 +110,7 @@ func TestGetTargetCommitPositionFromSourcePositionReverse(t *testing.T) {
116
110
117
111
posIn := shared.Position {Line : 302 , Character : 15 }
118
112
119
- args := & requestArgs {
120
- repo : & sgtypes.Repo {ID : 50 },
121
- commit : "deadbeef1" ,
122
- path : "/foo/bar.go" ,
123
- }
113
+ args := & mockRequestArgs
124
114
adjuster := NewGitTreeTranslator (client , args , nil )
125
115
path , posOut , ok , err := adjuster .GetTargetCommitPositionFromSourcePosition (context .Background (), "deadbeef2" , posIn , true )
126
116
if err != nil {
@@ -130,8 +120,8 @@ func TestGetTargetCommitPositionFromSourcePositionReverse(t *testing.T) {
130
120
if ! ok {
131
121
t .Errorf ("expected translation to succeed" )
132
122
}
133
- if path != "/ foo/bar.go" {
134
- t .Errorf ("unexpected path. want=%s have=%s" , "/ foo/bar.go" , path )
123
+ if path != "foo/bar.go" {
124
+ t .Errorf ("unexpected path. want=%s have=%s" , "foo/bar.go" , path )
135
125
}
136
126
137
127
expectedPos := shared.Position {Line : 294 , Character : 15 }
@@ -142,7 +132,7 @@ func TestGetTargetCommitPositionFromSourcePositionReverse(t *testing.T) {
142
132
143
133
func TestGetTargetCommitRangeFromSourceRange (t * testing.T ) {
144
134
client := gitserver .NewMockClientWithExecReader (nil , func (_ context.Context , _ api.RepoName , args []string ) (reader io.ReadCloser , err error ) {
145
- expectedArgs := []string {"diff" , "--find-renames" , "--full-index" , "--inter-hunk-context=3" , "--no-prefix" , "deadbeef1..deadbeef2" , "--" , "/foo/bar.go" }
135
+ expectedArgs := []string {"diff" , "--find-renames" , "--full-index" , "--inter-hunk-context=3" , "--no-prefix" , "deadbeef1..deadbeef2" , "--" , mockRequestArgs . path . RawValue () }
146
136
if diff := cmp .Diff (expectedArgs , args ); diff != "" {
147
137
t .Errorf ("unexpected exec reader args (-want +got):\n %s" , diff )
148
138
}
@@ -155,22 +145,18 @@ func TestGetTargetCommitRangeFromSourceRange(t *testing.T) {
155
145
End : shared.Position {Line : 305 , Character : 20 },
156
146
}
157
147
158
- args := & requestArgs {
159
- repo : & sgtypes.Repo {ID : 50 },
160
- commit : "deadbeef1" ,
161
- path : "/foo/bar.go" ,
162
- }
148
+ args := & mockRequestArgs
163
149
adjuster := NewGitTreeTranslator (client , args , nil )
164
- path , rOut , ok , err := adjuster .GetTargetCommitRangeFromSourceRange (context .Background (), "deadbeef2" , "/foo/bar.go" , rIn , false )
150
+ path , rOut , ok , err := adjuster .GetTargetCommitRangeFromSourceRange (context .Background (), "deadbeef2" , mockRequestArgs . path . RawValue () , rIn , false )
165
151
if err != nil {
166
152
t .Fatalf ("unexpected error: %s" , err )
167
153
}
168
154
169
155
if ! ok {
170
156
t .Errorf ("expected translation to succeed" )
171
157
}
172
- if path != "/ foo/bar.go" {
173
- t .Errorf ("unexpected path. want=%s have=%s" , "/ foo/bar.go" , path )
158
+ if path != "foo/bar.go" {
159
+ t .Errorf ("unexpected path. want=%s have=%s" , "foo/bar.go" , path )
174
160
}
175
161
176
162
expectedRange := shared.Range {
@@ -192,22 +178,18 @@ func TestGetTargetCommitRangeFromSourceRangeEmptyDiff(t *testing.T) {
192
178
End : shared.Position {Line : 305 , Character : 20 },
193
179
}
194
180
195
- args := & requestArgs {
196
- repo : & sgtypes.Repo {ID : 50 },
197
- commit : "deadbeef1" ,
198
- path : "/foo/bar.go" ,
199
- }
181
+ args := & mockRequestArgs
200
182
adjuster := NewGitTreeTranslator (client , args , nil )
201
- path , rOut , ok , err := adjuster .GetTargetCommitRangeFromSourceRange (context .Background (), "deadbeef2" , "/foo/bar.go" , rIn , false )
183
+ path , rOut , ok , err := adjuster .GetTargetCommitRangeFromSourceRange (context .Background (), "deadbeef2" , mockRequestArgs . path . RawValue () , rIn , false )
202
184
if err != nil {
203
185
t .Fatalf ("unexpected error: %s" , err )
204
186
}
205
187
206
188
if ! ok {
207
189
t .Errorf ("expected translation to succeed" )
208
190
}
209
- if path != "/ foo/bar.go" {
210
- t .Errorf ("unexpected path. want=%s have=%s" , "/ foo/bar.go" , path )
191
+ if path != "foo/bar.go" {
192
+ t .Errorf ("unexpected path. want=%s have=%s" , "foo/bar.go" , path )
211
193
}
212
194
if diff := cmp .Diff (rOut , rIn ); diff != "" {
213
195
t .Errorf ("unexpected position (-want +got):\n %s" , diff )
@@ -216,7 +198,7 @@ func TestGetTargetCommitRangeFromSourceRangeEmptyDiff(t *testing.T) {
216
198
217
199
func TestGetTargetCommitRangeFromSourceRangeReverse (t * testing.T ) {
218
200
client := gitserver .NewMockClientWithExecReader (nil , func (_ context.Context , _ api.RepoName , args []string ) (reader io.ReadCloser , err error ) {
219
- expectedArgs := []string {"diff" , "--find-renames" , "--full-index" , "--inter-hunk-context=3" , "--no-prefix" , "deadbeef2..deadbeef1" , "--" , "/foo/bar.go" }
201
+ expectedArgs := []string {"diff" , "--find-renames" , "--full-index" , "--inter-hunk-context=3" , "--no-prefix" , "deadbeef2..deadbeef1" , "--" , mockRequestArgs . path . RawValue () }
220
202
if diff := cmp .Diff (expectedArgs , args ); diff != "" {
221
203
t .Errorf ("unexpected exec reader args (-want +got):\n %s" , diff )
222
204
}
@@ -229,22 +211,18 @@ func TestGetTargetCommitRangeFromSourceRangeReverse(t *testing.T) {
229
211
End : shared.Position {Line : 305 , Character : 20 },
230
212
}
231
213
232
- args := & requestArgs {
233
- repo : & sgtypes.Repo {ID : 50 },
234
- commit : "deadbeef1" ,
235
- path : "/foo/bar.go" ,
236
- }
214
+ args := & mockRequestArgs
237
215
adjuster := NewGitTreeTranslator (client , args , nil )
238
- path , rOut , ok , err := adjuster .GetTargetCommitRangeFromSourceRange (context .Background (), "deadbeef2" , "/foo/bar.go" , rIn , true )
216
+ path , rOut , ok , err := adjuster .GetTargetCommitRangeFromSourceRange (context .Background (), "deadbeef2" , args . path . RawValue () , rIn , true )
239
217
if err != nil {
240
218
t .Fatalf ("unexpected error: %s" , err )
241
219
}
242
220
243
221
if ! ok {
244
222
t .Errorf ("expected translation to succeed" )
245
223
}
246
- if path != "/ foo/bar.go" {
247
- t .Errorf ("unexpected path. want=%s have=%s" , "/ foo/bar.go" , path )
224
+ if path != "foo/bar.go" {
225
+ t .Errorf ("unexpected path. want=%s have=%s" , "foo/bar.go" , path )
248
226
}
249
227
250
228
expectedRange := shared.Range {
0 commit comments