-
Notifications
You must be signed in to change notification settings - Fork 2
/
slack_test.go
65 lines (54 loc) · 1.83 KB
/
slack_test.go
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
_ "embed"
"encoding/json"
"fmt"
"github.com/andygrunwald/go-jira"
"github.com/joshdk/go-junit"
"github.com/stretchr/testify/assert"
"testing"
)
var (
//go:embed testdata/slack/message-sample.xml
messageSample []byte
//go:embed testdata/slack/value-sample.xml
valueSample []byte
//go:embed testdata/slack/combined-sample.xml
combinedSample []byte
//go:embed testdata/slack/message-expected.json
messageExpected []byte
//go:embed testdata/slack/value-expected.json
valueExpected []byte
//go:embed testdata/slack/combined-expected.json
combinedExpected []byte
)
func TestConstructSlackMessage(t *testing.T) {
samples := [][]byte{messageSample, valueSample, combinedSample}
expectations := [][]byte{messageExpected, valueExpected, combinedExpected}
assert.Len(t, samples, len(expectations), "There are different amounts of samples and expected files. This a problem with the test rather than the code")
j := junit2jira{}
for i, sample := range samples {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
testsSuites, err := junit.Ingest(sample)
assert.NoError(t, err)
suites, err := j.findFailedTests(testsSuites)
assert.NoError(t, err, "If this fails, it probably indicates a problem with the sample junit report rather than the code")
assert.NotNil(t, suites, "If this fails, it probably indicates a problem with the sample junit report rather than the code")
issues := make([]*testIssue, 0, len(suites))
for _, s := range suites {
issues = append(issues, &testIssue{
issue: nil,
testCase: s,
})
}
issues[0].issue = &jira.Issue{
Self: "some/url/foo-1",
Key: "FOO-1",
}
blocks := convertJunitToSlack(issues...)
b, err := json.MarshalIndent(blocks, "", " ")
assert.NoError(t, err)
assert.JSONEq(t, string(expectations[i]), string(b))
})
}
}