File: run_stage_test.go

package info (click to toggle)
golang-github-owenrumney-go-sarif 2.3.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 712 kB
  • sloc: makefile: 13
file content (50 lines) | stat: -rw-r--r-- 938 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package test

import (
	"encoding/json"
	"testing"

	"github.com/owenrumney/go-sarif/sarif"
	"github.com/stretchr/testify/assert"
)

type runTest struct {
	t          *testing.T
	run        *sarif.Run
	jsonString string
}

func newRunTest(t *testing.T) (*runTest, *runTest, *runTest) {
	r := &runTest{
		t: t,
		run: &sarif.Run{
			Tool:      sarif.Tool{},
			Artifacts: []*sarif.Artifact{},
			Results:   []*sarif.Result{},
		},
	}
	return r, r, r
}

func (r *runTest) a_result_is_added() {
	r.run.AddResult("rule1")
}

func (r *runTest) properties_added_to_a_run() {
	pb := sarif.NewPropertyBag()

	pb.AddString("string_key", "string_value")
	pb.AddBoolean("boolean_key", false)

	r.run.AttachPropertyBag(pb)
}

func (r *runTest) the_run_is_json() {
	b, err := json.Marshal(r.run)
	assert.Nil(r.t, err)
	r.jsonString = string(b)
}

func (r *runTest) string_is_as_expected(expected string) {
	assert.Equal(r.t, expected, r.jsonString)
}