From 08799ca57ef5671b192fa05592b9bc8462a59217 Mon Sep 17 00:00:00 2001 From: filip Date: Sun, 29 Sep 2024 20:26:02 +0200 Subject: [PATCH] small codescene fixes --- internal/report/sbom/report.go | 20 +++++++------------- internal/report/sbom/report_test.go | 27 +++++++++++++++++---------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/internal/report/sbom/report.go b/internal/report/sbom/report.go index 09133b8f..209d0921 100644 --- a/internal/report/sbom/report.go +++ b/internal/report/sbom/report.go @@ -61,13 +61,7 @@ func (r Reporter) Order(args report.IOrderArgs) error { return ErrHandleArgs } - uuid, err := r.generate( - orderArgs.CommitID, - orderArgs.RepositoryID, - orderArgs.Branch, - orderArgs.Vulnerabilities, - orderArgs.Licenses, - ) + uuid, err := r.generate(orderArgs) if err != nil { return err } @@ -80,17 +74,17 @@ func (r Reporter) Order(args report.IOrderArgs) error { } -func (r Reporter) generate(commitID, repositoryID, branch string, vulnerabilities, licenses bool) (string, error) { +func (r Reporter) generate(orderArgs OrderArgs) (string, error) { // Tries to start generating an SBOM and returns the UUID for the report body, err := json.Marshal(generateSbom{ Format: "CycloneDX", - RepositoryID: repositoryID, - CommitID: commitID, + RepositoryID: orderArgs.RepositoryID, + CommitID: orderArgs.CommitID, Email: "", - Branch: branch, + Branch: orderArgs.Branch, Locale: "en", - Vulnerabilities: vulnerabilities, - Licenses: licenses, + Vulnerabilities: orderArgs.Vulnerabilities, + Licenses: orderArgs.Licenses, SendEmail: false, VulnerabilityStatuses: []string{"vulnerable", "unexamined", "paused", "snoozed"}, }) diff --git a/internal/report/sbom/report_test.go b/internal/report/sbom/report_test.go index b154cc2c..21fb67aa 100644 --- a/internal/report/sbom/report_test.go +++ b/internal/report/sbom/report_test.go @@ -16,8 +16,7 @@ func TestOrderError(t *testing.T) { debClientMock := testdata.NewDebClientMock() debClientMock.AddMockResponse(testdata.MockResponse{StatusCode: http.StatusOK}) reporter := Reporter{DebClient: debClientMock, FileWriter: &ioTestData.FileWriterMock{}} - args := OrderArgs{CommitID: "", RepositoryID: ""} - err := reporter.Order(args) + err := reporter.Order(OrderArgs{CommitID: "", RepositoryID: ""}) assert.Error(t, err) } @@ -32,8 +31,7 @@ func TestOrder(t *testing.T) { ResponseBody: io.NopCloser(strings.NewReader("{}")), }) reporter := Reporter{DebClient: debClientMock, FileWriter: &ioTestData.FileWriterMock{}} - args := OrderArgs{CommitID: "", RepositoryID: ""} - err := reporter.Order(args) + err := reporter.Order(OrderArgs{CommitID: "", RepositoryID: ""}) assert.NoError(t, err) } @@ -47,8 +45,7 @@ func TestOrderDownloadErr(t *testing.T) { StatusCode: http.StatusForbidden, }) reporter := Reporter{DebClient: debClientMock, FileWriter: &ioTestData.FileWriterMock{}} - args := OrderArgs{CommitID: "", RepositoryID: ""} - err := reporter.Order(args) + err := reporter.Order(OrderArgs{CommitID: "", RepositoryID: ""}) assert.Error(t, err) } @@ -67,7 +64,7 @@ func TestGenerateOK(t *testing.T) { ResponseBody: io.NopCloser(strings.NewReader("{}")), }) reporter := Reporter{DebClient: debClientMock, FileWriter: &ioTestData.FileWriterMock{}} - uuid, err := reporter.generate("", "", "", false, false) + uuid, err := reporter.generate(orderArgs()) assert.NoError(t, err) assert.NotNil(t, uuid) } @@ -79,7 +76,7 @@ func TestGenerateSubscriptionError(t *testing.T) { ResponseBody: io.NopCloser(strings.NewReader("{}")), }) reporter := Reporter{DebClient: debClientMock, FileWriter: &ioTestData.FileWriterMock{}} - uuid, err := reporter.generate("", "", "", false, false) + uuid, err := reporter.generate(orderArgs()) assert.Error(t, err) assert.NotNil(t, uuid) } @@ -91,7 +88,7 @@ func TestGenerateError(t *testing.T) { ResponseBody: io.NopCloser(strings.NewReader("{}")), }) reporter := Reporter{DebClient: debClientMock, FileWriter: &ioTestData.FileWriterMock{}} - uuid, err := reporter.generate("", "", "", false, false) + uuid, err := reporter.generate(orderArgs()) assert.Error(t, err) assert.NotNil(t, uuid) } @@ -100,7 +97,7 @@ func TestGenerateDefaultGetError(t *testing.T) { debClientMock := testdata.NewDebClientMock() debClientMock.AddMockResponse(testdata.MockResponse{Error: errors.New("")}) reporter := Reporter{DebClient: debClientMock, FileWriter: &ioTestData.FileWriterMock{}} - res, err := reporter.generate("", "", "", false, false) + res, err := reporter.generate(orderArgs()) assert.Error(t, err) assert.Equal(t, "", res) } @@ -170,3 +167,13 @@ func TestWriteSBOM(t *testing.T) { err := reporter.writeSBOM("", "", nil) assert.Error(t, err) } + +func orderArgs() OrderArgs { + return OrderArgs{ + Vulnerabilities: false, + Licenses: false, + Branch: "", + CommitID: "", + RepositoryID: "", + } +}