Skip to content

Commit

Permalink
refactor: use empty strings instead of (devel)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyLewen committed Apr 22, 2024
1 parent d8af068 commit 35f6401
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions docs/docs/coverage/language/golang.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ There are times when Go uses the `(devel)` version for modules/dependencies and
In other cases, Go uses the `(devel)` version[^3].
- Dependencies replaced with local ones use the `(devel)` versions.

In these cases, the version of such packages is empty.

[^1]: It doesn't require the Internet access.
[^2]: Need to download modules to local cache beforehand
Expand Down
5 changes: 3 additions & 2 deletions pkg/dependency/parser/golang/binary/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"sort"
"strings"

"github.com/samber/lo"
"golang.org/x/xerrors"

"github.com/aquasecurity/trivy/pkg/dependency/types"
Expand Down Expand Up @@ -56,7 +57,7 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]types.Library, []types.Dependency,
// Only binaries installed with `go install` contain semver version of the main module.
// Other binaries use the `(devel)` version.
// See https://github.com/aquasecurity/trivy/issues/1837#issuecomment-1832523477.
Version: info.Main.Version,
Version: lo.Ternary(info.Main.Version != "(devel)", info.Main.Version, ""), // Use empty string instead of `(devel)`
},
}...)

Expand All @@ -75,7 +76,7 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]types.Library, []types.Dependency,

libs = append(libs, types.Library{
Name: mod.Path,
Version: mod.Version,
Version: lo.Ternary(mod.Version != "(devel)", mod.Version, ""), // Use empty string instead of `(devel)`,
})
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/dependency/parser/golang/binary/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestParse(t *testing.T) {
},
{
Name: "github.com/aquasecurity/test",
Version: "(devel)",
Version: "",
},
{
Name: "golang.org/x/xerrors",
Expand All @@ -58,7 +58,7 @@ func TestParse(t *testing.T) {
},
{
Name: "github.com/aquasecurity/test",
Version: "(devel)",
Version: "",
},
{
Name: "golang.org/x/xerrors",
Expand All @@ -84,7 +84,7 @@ func TestParse(t *testing.T) {
},
{
Name: "github.com/aquasecurity/test",
Version: "(devel)",
Version: "",
},
{
Name: "golang.org/x/xerrors",
Expand All @@ -106,7 +106,7 @@ func TestParse(t *testing.T) {
},
{
Name: "github.com/ebati/trivy-mod-parse",
Version: "(devel)",
Version: "",
},
{
Name: "github.com/go-sql-driver/mysql",
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/analyzer/language/golang/binary/binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func Test_gobinaryLibraryAnalyzer_Analyze(t *testing.T) {
},
{
Name: "github.com/aquasecurity/test",
Version: "(devel)",
Version: "",
},
{
Name: "golang.org/x/xerrors",
Expand Down
2 changes: 1 addition & 1 deletion pkg/purl/purl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestNewPackageURL(t *testing.T) {
typ: ftypes.GoModule,
pkg: ftypes.Package{
Name: "./private_repos/cnrm.googlesource.com/cnrm/",
Version: "(devel)",
Version: "",
},
want: nil,
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/sbom/cyclonedx/marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func TestMarshaler_MarshalReport(t *testing.T) {
// dependency has been replaced with local directory
{
Name: "./api",
Version: "(devel)",
Version: "",
},
},
},
Expand Down Expand Up @@ -423,7 +423,7 @@ func TestMarshaler_MarshalReport(t *testing.T) {
BOMRef: "3ff14136-e09f-4df9-80ea-000000000013",
Type: cdx.ComponentTypeLibrary,
Name: "./api",
Version: "(devel)",
Version: "",
Properties: &[]cdx.Property{
{
Name: "aquasecurity:trivy:PkgType",
Expand Down
7 changes: 3 additions & 4 deletions pkg/sbom/spdx/marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ func TestMarshaler_Marshal(t *testing.T) {
Packages: []ftypes.Package{
{
Name: "./private_repos/cnrm.googlesource.com/cnrm/",
Version: "(devel)",
Version: "",
},
{
Name: "golang.org/x/crypto",
Expand Down Expand Up @@ -1105,10 +1105,9 @@ func TestMarshaler_Marshal(t *testing.T) {
},
},
{
PackageSPDXIdentifier: spdx.ElementID("Package-9a16e221e11f8a90"),
PackageSPDXIdentifier: spdx.ElementID("Package-b1c3b9e2363f5ff7"),
PackageDownloadLocation: "NONE",
PackageName: "./private_repos/cnrm.googlesource.com/cnrm/",
PackageVersion: "(devel)",
PackageLicenseConcluded: "NONE",
PackageLicenseDeclared: "NONE",
PrimaryPackagePurpose: tspdx.PackagePurposeLibrary,
Expand Down Expand Up @@ -1152,7 +1151,7 @@ func TestMarshaler_Marshal(t *testing.T) {
Relationships: []*spdx.Relationship{
{
RefA: spdx.DocElementID{ElementRefID: "Application-aab0f4e8cf174c67"},
RefB: spdx.DocElementID{ElementRefID: "Package-9a16e221e11f8a90"},
RefB: spdx.DocElementID{ElementRefID: "Package-b1c3b9e2363f5ff7"},
Relationship: "CONTAINS",
},
{
Expand Down

0 comments on commit 35f6401

Please sign in to comment.