-
Notifications
You must be signed in to change notification settings - Fork 598
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/bitnami-cataloger
- Loading branch information
Showing
29 changed files
with
3,366 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ require ( | |
// we are hinting brotli to latest due to warning when installing archiver v3: | ||
// go: warning: github.com/andybalholm/[email protected]: retracted by module author: occasional panics and data corruption | ||
github.com/aquasecurity/go-pep440-version v0.0.1 | ||
github.com/bmatcuk/doublestar/v4 v4.8.0 | ||
github.com/bmatcuk/doublestar/v4 v4.8.1 | ||
github.com/charmbracelet/bubbles v0.20.0 | ||
github.com/charmbracelet/bubbletea v1.2.4 | ||
github.com/charmbracelet/lipgloss v1.0.0 | ||
|
@@ -34,7 +34,7 @@ require ( | |
github.com/elliotchance/phpserialize v1.4.0 | ||
github.com/facebookincubator/nvdtools v0.1.5 | ||
github.com/github/go-spdx/v2 v2.3.2 | ||
github.com/gkampitakis/go-snaps v0.5.8 | ||
github.com/gkampitakis/go-snaps v0.5.9 | ||
github.com/go-git/go-billy/v5 v5.6.2 | ||
github.com/go-git/go-git/v5 v5.13.2 | ||
github.com/go-test/deep v1.1.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package licenses | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
"github.com/google/licensecheck" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestIdentifyLicenseIDs(t *testing.T) { | ||
type expectation struct { | ||
yieldError bool | ||
ids []string | ||
content []byte | ||
} | ||
tests := []struct { | ||
name string | ||
in string | ||
expected expectation | ||
}{ | ||
{ | ||
name: "apache license 2.0", | ||
in: `test-fixtures/apache-license-2.0`, | ||
expected: expectation{ | ||
yieldError: false, | ||
ids: []string{"Apache-2.0"}, | ||
content: []byte{}, | ||
}, | ||
}, | ||
{ | ||
name: "custom license", | ||
in: "test-fixtures/nvidia-software-and-cuda-supplement", | ||
expected: expectation{ | ||
yieldError: false, | ||
ids: []string{}, | ||
content: mustOpen("test-fixtures/nvidia-software-and-cuda-supplement"), | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
content, err := os.ReadFile(test.in) | ||
require.NoError(t, err) | ||
ids, content, err := testScanner().IdentifyLicenseIDs(context.TODO(), bytes.NewReader(content)) | ||
if test.expected.yieldError { | ||
require.Error(t, err) | ||
} else { | ||
require.NoError(t, err) | ||
|
||
require.Len(t, ids, len(test.expected.ids)) | ||
require.Len(t, content, len(test.expected.content)) | ||
|
||
if len(test.expected.ids) > 0 { | ||
require.Equal(t, ids, test.expected.ids) | ||
} | ||
|
||
if len(test.expected.content) > 0 { | ||
require.Equal(t, content, test.expected.content) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func testScanner() Scanner { | ||
return &scanner{ | ||
coverageThreshold: coverageThreshold, | ||
scanner: licensecheck.Scan, | ||
} | ||
} | ||
|
||
func mustOpen(fixture string) []byte { | ||
content, err := os.ReadFile(fixture) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return content | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package licenses | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"io" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/anchore/syft/syft/file" | ||
"github.com/anchore/syft/syft/pkg" | ||
) | ||
|
||
type bytesReadCloser struct { | ||
bytes.Buffer | ||
} | ||
|
||
func (brc *bytesReadCloser) Close() error { | ||
return nil | ||
} | ||
|
||
func newBytesReadCloser(data []byte) *bytesReadCloser { | ||
return &bytesReadCloser{ | ||
Buffer: *bytes.NewBuffer(data), | ||
} | ||
} | ||
|
||
func TestSearch(t *testing.T) { | ||
type expectation struct { | ||
yieldError bool | ||
licenses []pkg.License | ||
} | ||
testLocation := file.NewLocation("LICENSE") | ||
tests := []struct { | ||
name string | ||
in string | ||
expected expectation | ||
}{ | ||
{ | ||
name: "apache license 2.0", | ||
in: "test-fixtures/apache-license-2.0", | ||
expected: expectation{ | ||
yieldError: false, | ||
licenses: []pkg.License{ | ||
{ | ||
Value: "Apache-2.0", | ||
SPDXExpression: "Apache-2.0", | ||
Type: "concluded", | ||
URLs: nil, | ||
Locations: file.NewLocationSet(testLocation), | ||
Contents: "", | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "custom license", | ||
in: "test-fixtures/nvidia-software-and-cuda-supplement", | ||
expected: expectation{ | ||
yieldError: false, | ||
licenses: []pkg.License{ | ||
{ | ||
Value: "UNKNOWN", | ||
SPDXExpression: "UNKNOWN_eebcea3ab1d1a28e671de90119ffcfb35fe86951e4af1b17af52b7a82fcf7d0a", | ||
Type: "declared", | ||
URLs: nil, | ||
Locations: file.NewLocationSet(testLocation), | ||
Contents: string(mustOpen("test-fixtures/nvidia-software-and-cuda-supplement")), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
content, err := os.ReadFile(test.in) | ||
require.NoError(t, err) | ||
result, err := Search(context.TODO(), testScanner(), file.NewLocationReadCloser(file.NewLocation("LICENSE"), io.NopCloser(bytes.NewReader(content)))) | ||
if test.expected.yieldError { | ||
require.Error(t, err) | ||
} else { | ||
require.NoError(t, err) | ||
|
||
require.Len(t, result, len(test.expected.licenses)) | ||
|
||
if len(test.expected.licenses) > 0 { | ||
require.Equal(t, test.expected.licenses, result) | ||
} | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.