Debian Codegraph @

v2/test/run_stage_test.go

raw
1 package test
2
3 import (
4 "encoding/json"
5 "testing"
6
7 "github.com/owenrumney/go-sarif/v2/sarif"
8 "github.com/stretchr/testify/assert"
9 )
10
11 type runTest struct {
12 t *testing.T
13 run *sarif.Run
14 jsonString string
15 }
16
17 func newRunTest(t *testing.T) (*runTest, *runTest, *runTest) {
18 r := &runTest{
19 t: t,
20 run: &sarif.Run{
21 Tool: *sarif.NewTool(sarif.NewDriver("driver1")),
22 Artifacts: []*sarif.Artifact{},
23 Results: []*sarif.Result{},
24 },
25 }
26 return r, r, r
27 }
28
29 func (r *runTest) a_result_is_added() {
30 r.run.CreateResultForRule("rule1")
31 }
32
33 func (r *runTest) properties_added_to_a_run() {
34 pb := sarif.NewPropertyBag()
35
36 pb.AddString("string_key", "string_value")
37 pb.AddBoolean("boolean_key", false)
38
39 r.run.AttachPropertyBag(pb)
40 }
41
42 func (r *runTest) the_run_is_json() {
43 b, err := json.Marshal(r.run)
44 assert.Nil(r.t, err)
45 r.jsonString = string(b)
46 }
47
48 func (r *runTest) string_is_as_expected(expected string) {
49 assert.Equal(r.t, expected, r.jsonString)
50 }