Skip to content

Commit a6e3fac

Browse files
committed
remove filePath function argument which can be obtained from the Library struct directly instead
Co-authored-by: Bobgy Signed-off-by: Tim Ramlot <[email protected]>
1 parent d018223 commit a6e3fac

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

licenses/library.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ func (l *Library) String() string {
353353

354354
// FileURL attempts to determine the URL for a file in this library using
355355
// go module name and version.
356-
func (l *Library) FileURL(ctx context.Context, cl *source.Client, filePath string) (string, error) {
356+
func (l *Library) FileURL(ctx context.Context, cl *source.Client) (string, error) {
357357
if l == nil {
358358
return "", fmt.Errorf("library is nil")
359359
}
@@ -393,7 +393,7 @@ func (l *Library) FileURL(ctx context.Context, cl *source.Client, filePath strin
393393
remote.SetCommit("HEAD")
394394
klog.Warningf("module %s has empty version, defaults to HEAD. The license URL may be incorrect. Please verify!", m.Path)
395395
}
396-
relativePath, err := filepath.Rel(m.Dir, filePath)
396+
relativePath, err := filepath.Rel(m.Dir, l.LicenseFile)
397397
if err != nil {
398398
return "", wrap(err)
399399
}

licenses/library_test.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ func TestLibraryFileURL(t *testing.T) {
221221
for _, test := range []struct {
222222
desc string
223223
lib *Library
224-
path string
225224
wantURL string
226225
wantErr bool
227226
}{
@@ -232,14 +231,13 @@ func TestLibraryFileURL(t *testing.T) {
232231
"github.com/google/trillian",
233232
"github.com/google/trillian/crypto",
234233
},
235-
LicenseFile: "/go/src/github.com/google/trillian/LICENSE",
234+
LicenseFile: "/go/src/github.com/google/trillian/foo/README.md",
236235
module: &Module{
237236
Path: "github.com/google/trillian",
238237
Dir: "/go/src/github.com/google/trillian",
239238
Version: "v1.2.3",
240239
},
241240
},
242-
path: "/go/src/github.com/google/trillian/foo/README.md",
243241
wantURL: "https://github.com/google/trillian/blob/v1.2.3/foo/README.md",
244242
},
245243
{
@@ -249,14 +247,13 @@ func TestLibraryFileURL(t *testing.T) {
249247
"bitbucket.org/user/project/pkg",
250248
"bitbucket.org/user/project/pkg2",
251249
},
252-
LicenseFile: "/foo/bar/bitbucket.org/user/project/LICENSE",
250+
LicenseFile: "/foo/bar/bitbucket.org/user/project/foo/README.md",
253251
module: &Module{
254252
Path: "bitbucket.org/user/project",
255253
Dir: "/foo/bar/bitbucket.org/user/project",
256254
Version: "v1.2.3",
257255
},
258256
},
259-
path: "/foo/bar/bitbucket.org/user/project/foo/README.md",
260257
wantURL: "https://bitbucket.org/user/project/src/v1.2.3/foo/README.md",
261258
},
262259
{
@@ -266,14 +263,13 @@ func TestLibraryFileURL(t *testing.T) {
266263
"example.com/user/project/pkg",
267264
"example.com/user/project/pkg2",
268265
},
269-
LicenseFile: "/foo/bar/example.com/user/project/LICENSE",
266+
LicenseFile: "/foo/bar/example.com/user/project/foo/README.md",
270267
module: &Module{
271268
Path: "example.com/user/project",
272269
Dir: "/foo/bar/example.com/user/project",
273270
Version: "v1.2.3",
274271
},
275272
},
276-
path: "/foo/bar/example.com/user/project/foo/README.md",
277273
wantURL: "https://example.com/user/project/blob/v1.2.3/foo/README.md",
278274
},
279275
{
@@ -283,13 +279,12 @@ func TestLibraryFileURL(t *testing.T) {
283279
"github.com/google/trillian",
284280
"github.com/google/trillian/crypto",
285281
},
286-
LicenseFile: "/go/src/github.com/google/trillian/LICENSE",
282+
LicenseFile: "/go/src/github.com/google/trillian/foo/README.md",
287283
module: &Module{
288284
Path: "github.com/google/trillian",
289285
Dir: "/go/src/github.com/google/trillian",
290286
},
291287
},
292-
path: "/go/src/github.com/google/trillian/foo/README.md",
293288
wantURL: "https://github.com/google/trillian/blob/HEAD/foo/README.md",
294289
},
295290
{
@@ -305,20 +300,19 @@ func TestLibraryFileURL(t *testing.T) {
305300
Version: "v0.23.1",
306301
},
307302
},
308-
path: "/go/modcache/k8s.io/api/LICENSE",
309303
wantURL: "https://github.com/kubernetes/api/blob/v0.23.1/LICENSE",
310304
},
311305
} {
312306
t.Run(test.desc, func(t *testing.T) {
313307
client := source.NewClient(time.Second * 20)
314-
fileURL, err := test.lib.FileURL(context.Background(), client, test.path)
308+
fileURL, err := test.lib.FileURL(context.Background(), client)
315309
if gotErr := err != nil; gotErr != test.wantErr {
316-
t.Fatalf("FileURL(%q) = (_, %q), want err? %t", test.path, err, test.wantErr)
310+
t.Fatalf("FileURL() = (_, %q), want err? %t", err, test.wantErr)
317311
} else if gotErr {
318312
return
319313
}
320314
if got, want := fileURL, test.wantURL; got != want {
321-
t.Fatalf("FileURL(%q) = %q, want %q", test.path, got, want)
315+
t.Fatalf("FileURL() = %q, want %q", got, want)
322316
}
323317
})
324318
}

report.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func reportMain(_ *cobra.Command, args []string) error {
121121

122122
if lib.LicenseFile != "" {
123123
group.Go(func() error {
124-
url, err := lib.FileURL(gctx, client, lib.LicenseFile)
124+
url, err := lib.FileURL(gctx, client)
125125
if err == nil {
126126
reportData[idx].LicenseURL = url
127127
} else {

0 commit comments

Comments
 (0)