Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix integer division by integer bug #29

Merged
merged 4 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/photon.spdx.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spdx/gordf v0.0.0-20201111095634-7098f93598fb // indirect
github.com/spf13/pflag v1.0.5 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLf
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spdx/gordf v0.0.0-20201111095634-7098f93598fb h1:bLo8hvc8XFm9J47r690TUKBzcjSWdJDxmjXJZ+/f92U=
github.com/spdx/gordf v0.0.0-20201111095634-7098f93598fb/go.mod h1:uKWaldnbMnjsSAXRurWqqrdyZen1R7kxl8TkmWk2OyM=
github.com/spdx/tools-golang v0.3.1-0.20221108182156-8a01147e6342 h1:6uvaOTv4GeRqQV6O1/znbpziqhctMRLTy3OGeZrNMic=
github.com/spdx/tools-golang v0.3.1-0.20221108182156-8a01147e6342/go.mod h1:VHzvNsKAfAGqs4ZvwRL+7a0dNsL20s7lGui4K9C0xQM=
Expand Down
4 changes: 2 additions & 2 deletions pkg/spdx/spdx_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (r *SpdxReport) PackageVersions() scorecard.ReportValue {
}
}
return scorecard.ReportValue{
Ratio: float32(r.hasPackVer / r.totalPackages),
Ratio: float32(r.hasPackVer) / float32(r.totalPackages),
}
}

Expand All @@ -91,7 +91,7 @@ func (r *SpdxReport) PackageLicenses() scorecard.ReportValue {
}
}
return scorecard.ReportValue{
Ratio: float32(r.hasLicense / r.totalPackages),
Ratio: float32(r.hasLicense) / float32(r.totalPackages),
}
}

Expand Down
66 changes: 48 additions & 18 deletions pkg/spdx/spdx_report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"github.com/ebay/sbom-scorecard/pkg/scorecard"
)

func TestSpdxE2eReport(t *testing.T) {
r := GetSpdxReport("../../examples/julia.spdx.json")
report_text := r.Report()

if strings.Trim(report_text, " \n") != `34 total packages
var report_tests = []struct {
path string
expected string
}{
{"../../examples/julia.spdx.json", `34 total packages
0 total files
100% have licenses.
0% have package digest.
Expand All @@ -20,25 +20,55 @@ func TestSpdxE2eReport(t *testing.T) {
0% have CPEs.
0% have file digest.
Spec valid? true
Has creation info? false` {
t.Log("Incorrect report results generated.\n" +
"Got this: \n" + report_text)
t.Fail()
}
Has creation info? false`},
{"../../examples/photon.spdx.json", `38 total packages
0 total files
94% have licenses.
2% have package digest.
97% have package versions.
0% have purls.
0% have CPEs.
0% have file digest.
Spec valid? true
Has creation info? true`},
}

func TestSpdxE2eGrade(t *testing.T) {
r := GetSpdxReport("../../examples/julia.spdx.json")
report_text := scorecard.Grade(r)
func TestSpdxE2eReport(t *testing.T) {
for _, e := range report_tests {
res := GetSpdxReport(e.path)
report_text := res.Report()
if strings.Trim(report_text, " \n") != e.expected {
t.Errorf("GetSpdxReport(%v) = %v, expected %v",
e.path, strings.Trim(report_text, " \n"), e.expected)
}
}
}

if strings.Trim(report_text, " \n") != `Spec Compliance: 25/25
var grade_tests = []struct {
path string
expected string
}{
{"../../examples/julia.spdx.json", `Spec Compliance: 25/25
Package ID: 0/20 (0% have purls and 0% have CPEs)
Package Versions: 0/20
Package Licenses: 20/20
Creation Info: 0/15 (No tool was used to create the sbom)
Total points: 45/100 or 45%` {
t.Log("Incorrect report results generated.\n" +
"Got this: \n" + report_text)
t.Fail()
Total points: 45/100 or 45%`},
{"../../examples/photon.spdx.json", `Spec Compliance: 25/25
Package ID: 0/20 (0% have purls and 0% have CPEs)
Package Versions: 19/20
Package Licenses: 18/20
Creation Info: 15/15
Total points: 78/100 or 78%`},
}

func TestSpdxE2eGrade(t *testing.T) {
for _, e := range grade_tests {
res := GetSpdxReport(e.path)
report_text := scorecard.Grade(res)
if strings.Trim(report_text, " \n") != e.expected {
t.Errorf("GetSpdxReport(%v) = %v, expected %v",
e.path, strings.Trim(report_text, " \n"), e.expected)
}
}
}