From 45b3b19e63cbf71c3ab9a46ca194abb6784b2646 Mon Sep 17 00:00:00 2001 From: sg Date: Thu, 24 Oct 2024 16:22:16 +0100 Subject: [PATCH] add example testdata for easier unittests --- pkg/testdata/testdata.go | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 pkg/testdata/testdata.go diff --git a/pkg/testdata/testdata.go b/pkg/testdata/testdata.go new file mode 100644 index 000000000..6b1b4d689 --- /dev/null +++ b/pkg/testdata/testdata.go @@ -0,0 +1,71 @@ +package testdata + +import ( + "fmt" + "time" + + v1protos "github.com/smithy-security/smithy/api/proto/v1" + "google.golang.org/protobuf/types/known/timestamppb" +) + +var ( + staticTime, _ = time.Parse(time.RFC3339, "Fri, 27 Sep 24 13:15:50 +0000") + Issues = []*v1protos.Issue{ + { + Target: "file://foo/bar/baz.go:1-1", + Type: "G456", + Title: "There is a `foo` type issue", + Severity: v1protos.Severity_SEVERITY_INFO, + Cvss: 2.0, + Confidence: v1protos.Confidence_CONFIDENCE_HIGH, + Description: "We found `foo` on bar", + Source: "git://github.com/x/z", + }, + { + Target: "file://foo/bar/baz.go:2-10", + Type: "G457", + Title: "There is a `bar` type issue", + Severity: v1protos.Severity_SEVERITY_UNSPECIFIED, + Cvss: 3.1, + Confidence: v1protos.Confidence_CONFIDENCE_CRITICAL, + Description: "We found `bar` on bar", + Source: "git://github.com/w/e", + }, + { + Target: "file://foo/bar/foobar.go", + Type: "G458", + Title: "There is a `foobar` type issue", + Severity: v1protos.Severity_SEVERITY_CRITICAL, + Cvss: 3.1, + Confidence: v1protos.Confidence_CONFIDENCE_UNSPECIFIED, + Description: "We found `foobar` on bar", + Source: "git://github.com/q/w", + }, + } + LaunchToolResponse = v1protos.LaunchToolResponse{ + ScanInfo: &v1protos.ScanInfo{ + ScanUuid: "e95e4ee9-f101-45d7-9917-34c74acf1919", + ScanStartTime: timestamppb.New(staticTime), + ScanTags: map[string]string{ + "unittests": "True", + }, + }, + ToolName: "tests", + Issues: Issues, + } + EnrichedLaunchToolResponse = v1protos.EnrichedLaunchToolResponse{ + OriginalResults: &LaunchToolResponse, + Issues: func() []*v1protos.EnrichedIssue { + var ei []*v1protos.EnrichedIssue + for c, i := range Issues { + ei = append(ei, &v1protos.EnrichedIssue{RawIssue: i, + Count: uint64(c), + Annotations: map[string]string{ + "issueNum": fmt.Sprintf("%d", c), + "someOther": "Annotation", + }}) + } + return ei + }(), + } +)