-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add GOOS and GOARCH into PURL (#217)
* feat: add os and arch into PURL - keep bom-ref as is - only metadata.component.purl and components.component.purl are updated Signed-off-by: Wen Zhou <[email protected]> * update: change to use gocmd to get GOOS and GOARCH from "go env -json" Signed-off-by: Wen Zhou <[email protected]> * test: update testdata Signed-off-by: Wen Zhou <[email protected]> * style: gofmt and use logger NoP() Signed-off-by: Wen Zhou <[email protected]> Signed-off-by: Wen Zhou <[email protected]>
- Loading branch information
Showing
24 changed files
with
133 additions
and
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,13 +19,17 @@ package gomod | |
|
||
import ( | ||
"bytes" | ||
|
||
"os/exec" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/rs/zerolog" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/CycloneDX/cyclonedx-gomod/internal/gocmd" | ||
) | ||
|
||
func TestModule_Coordinates(t *testing.T) { | ||
|
@@ -66,13 +70,28 @@ func TestModule_Hash(t *testing.T) { | |
require.Equal(t, "h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=", hash) | ||
} | ||
|
||
func TestModule_PackageURL(t *testing.T) { | ||
func TestModule_BOMRef(t *testing.T) { | ||
|
||
module := Module{ | ||
Path: "github.com/CycloneDX/cyclonedx-go", | ||
Version: "v0.1.0", | ||
} | ||
assert.Equal(t, "pkg:golang/github.com/CycloneDX/[email protected]?type=module", module.BOMRef()) | ||
} | ||
|
||
assert.Equal(t, "pkg:golang/github.com/CycloneDX/[email protected]?type=module", module.PackageURL()) | ||
func TestModule_PackageURL(t *testing.T) { | ||
// To get value from "go env -json", cannot just use t.GetEnv() might return "" | ||
envMap, _ = gocmd.GetEnv(zerolog.Nop()) | ||
goos := envMap["GOOS"] | ||
goarch := envMap["GOARCH"] | ||
|
||
module := Module{ | ||
Path: "github.com/CycloneDX/cyclonedx-go", | ||
Version: "v0.1.0", | ||
} | ||
assert.Equal(t, "linux", goos) | ||
assert.Equal(t, "amd64", goarch) | ||
assert.Equal(t, "pkg:golang/github.com/CycloneDX/[email protected]?type=module&goos="+goos+"&goarch="+goarch, module.PackageURL()) | ||
} | ||
|
||
func TestIsModule(t *testing.T) { | ||
|
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
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
<component bom-ref="pkg:golang/[email protected]?type=module" type="application"> | ||
<name>testmod-simple</name> | ||
<version>v0.0.0-20210716183230-c7ea7c975ab8</version> | ||
<purl>pkg:golang/[email protected]?type=module</purl> | ||
<purl>pkg:golang/[email protected]?type=module&goos=linux&goarch=amd64</purl> | ||
<properties> | ||
<property name="cdx:gomod:build:env:CGO_ENABLED">REDACTED</property> | ||
<property name="cdx:gomod:build:env:GOARCH">REDACTED</property> | ||
|
@@ -21,7 +21,7 @@ | |
<hashes> | ||
<hash alg="SHA-256">a8962d5e72515a6a5eee6ff75e5ca1aec2eb11446a1d1336931ce8c57ab2503b</hash> | ||
</hashes> | ||
<purl>pkg:golang/github.com/google/[email protected]?type=module</purl> | ||
<purl>pkg:golang/github.com/google/[email protected]?type=module&goos=linux&goarch=amd64</purl> | ||
<externalReferences> | ||
<reference type="vcs"> | ||
<url>https://github.com/google/uuid</url> | ||
|
@@ -39,7 +39,7 @@ | |
<name>std</name> | ||
<version>REDACTED</version> | ||
<scope>required</scope> | ||
<purl>pkg:golang/std@REDACTED?type=module</purl> | ||
<purl>pkg:golang/std@REDACTED?type=module&goos=linux&goarch=amd64</purl> | ||
</component> | ||
</components> | ||
<dependencies> | ||
|
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
<component bom-ref="pkg:golang/[email protected]?type=module#cmd/purl" type="application"> | ||
<name>testmod-simple</name> | ||
<version>v0.0.0-20210901192510-dc2d14d2351d</version> | ||
<purl>pkg:golang/[email protected]?type=module#cmd/purl</purl> | ||
<purl>pkg:golang/[email protected]?type=module&goos=linux&goarch=amd64#cmd/purl</purl> | ||
<properties> | ||
<property name="cdx:gomod:build:env:CGO_ENABLED">REDACTED</property> | ||
<property name="cdx:gomod:build:env:GOARCH">REDACTED</property> | ||
|
@@ -21,7 +21,7 @@ | |
<hashes> | ||
<hash alg="SHA-256">79f58173df0efdd059460d69c36c620f3a2f9e532309af4d3e77da88176e87c2</hash> | ||
</hashes> | ||
<purl>pkg:golang/github.com/package-url/[email protected]?type=module</purl> | ||
<purl>pkg:golang/github.com/package-url/[email protected]?type=module&goos=linux&goarch=amd64</purl> | ||
<externalReferences> | ||
<reference type="vcs"> | ||
<url>https://github.com/package-url/packageurl-go</url> | ||
|
@@ -32,7 +32,7 @@ | |
<name>std</name> | ||
<version>REDACTED</version> | ||
<scope>required</scope> | ||
<purl>pkg:golang/std@REDACTED?type=module</purl> | ||
<purl>pkg:golang/std@REDACTED?type=module&goos=linux&goarch=amd64</purl> | ||
</component> | ||
</components> | ||
<dependencies> | ||
|
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
<component bom-ref="pkg:golang/[email protected]?type=module#cmd/uuid" type="application"> | ||
<name>testmod-simple</name> | ||
<version>v0.0.0-20210901192510-dc2d14d2351d</version> | ||
<purl>pkg:golang/[email protected]?type=module#cmd/uuid</purl> | ||
<purl>pkg:golang/[email protected]?type=module&goos=linux&goarch=amd64#cmd/uuid</purl> | ||
<properties> | ||
<property name="cdx:gomod:build:env:CGO_ENABLED">REDACTED</property> | ||
<property name="cdx:gomod:build:env:GOARCH">REDACTED</property> | ||
|
@@ -21,7 +21,7 @@ | |
<hashes> | ||
<hash alg="SHA-256">a8962d5e72515a6a5eee6ff75e5ca1aec2eb11446a1d1336931ce8c57ab2503b</hash> | ||
</hashes> | ||
<purl>pkg:golang/github.com/google/[email protected]?type=module</purl> | ||
<purl>pkg:golang/github.com/google/[email protected]?type=module&goos=linux&goarch=amd64</purl> | ||
<externalReferences> | ||
<reference type="vcs"> | ||
<url>https://github.com/google/uuid</url> | ||
|
@@ -39,7 +39,7 @@ | |
<name>std</name> | ||
<version>REDACTED</version> | ||
<scope>required</scope> | ||
<purl>pkg:golang/std@REDACTED?type=module</purl> | ||
<purl>pkg:golang/std@REDACTED?type=module&goos=linux&goarch=amd64</purl> | ||
</component> | ||
</components> | ||
<dependencies> | ||
|
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
<component bom-ref="pkg:golang/[email protected]?type=module" type="application"> | ||
<name>testmod-vendored</name> | ||
<version>v0.0.0-20210716185931-5c9f3d791930</version> | ||
<purl>pkg:golang/[email protected]?type=module</purl> | ||
<purl>pkg:golang/[email protected]?type=module&goos=linux&goarch=amd64</purl> | ||
<properties> | ||
<property name="cdx:gomod:build:env:CGO_ENABLED">REDACTED</property> | ||
<property name="cdx:gomod:build:env:GOARCH">REDACTED</property> | ||
|
@@ -18,7 +18,7 @@ | |
<name>github.com/google/uuid</name> | ||
<version>v1.2.0</version> | ||
<scope>required</scope> | ||
<purl>pkg:golang/github.com/google/[email protected]?type=module</purl> | ||
<purl>pkg:golang/github.com/google/[email protected]?type=module&goos=linux&goarch=amd64</purl> | ||
<externalReferences> | ||
<reference type="vcs"> | ||
<url>https://github.com/google/uuid</url> | ||
|
@@ -36,7 +36,7 @@ | |
<name>std</name> | ||
<version>REDACTED</version> | ||
<scope>required</scope> | ||
<purl>pkg:golang/std@REDACTED?type=module</purl> | ||
<purl>pkg:golang/std@REDACTED?type=module&goos=linux&goarch=amd64</purl> | ||
</component> | ||
</components> | ||
<dependencies> | ||
|
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
<component bom-ref="pkg:golang/[email protected]?type=module" type="application"> | ||
<name>testmod-vendored</name> | ||
<version>v0.0.0-20210716185931-5c9f3d791930</version> | ||
<purl>pkg:golang/[email protected]?type=module</purl> | ||
<purl>pkg:golang/[email protected]?type=module&goos=linux&goarch=amd64</purl> | ||
<properties> | ||
<property name="cdx:gomod:build:env:CGO_ENABLED">REDACTED</property> | ||
<property name="cdx:gomod:build:env:GOARCH">REDACTED</property> | ||
|
@@ -39,7 +39,7 @@ | |
<name>github.com/google/uuid</name> | ||
<version>v1.2.0</version> | ||
<scope>required</scope> | ||
<purl>pkg:golang/github.com/google/[email protected]?type=module</purl> | ||
<purl>pkg:golang/github.com/google/[email protected]?type=module&goos=linux&goarch=amd64</purl> | ||
<externalReferences> | ||
<reference type="vcs"> | ||
<url>https://github.com/google/uuid</url> | ||
|
@@ -210,7 +210,7 @@ | |
<name>std</name> | ||
<version>REDACTED</version> | ||
<scope>required</scope> | ||
<purl>pkg:golang/std@REDACTED?type=module</purl> | ||
<purl>pkg:golang/std@REDACTED?type=module&goos=linux&goarch=amd64</purl> | ||
<components></components> | ||
</component> | ||
</components> | ||
|
Oops, something went wrong.