-
Notifications
You must be signed in to change notification settings - Fork 7
/
main_test.go
121 lines (105 loc) · 3.88 KB
/
main_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package main
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestBuildCommentBody(t *testing.T) {
assert.Equal(t,
"MARKER\n"+
"# Golang test coverage difference report\n\n"+
"Summary\n\n"+
"<details>\n<summary>Package report</summary>\n\n"+
"```\nReport table\n```\n"+
"</details>",
buildCommentBody("MARKER", "Summary", "Report table"))
}
func TestBuildTable(t *testing.T) {
t.Run("empty data set", func(t *testing.T) {
base := &CoverProfile{}
head := &CoverProfile{}
assert.Equal(t, strings.Trim(`
package before after delta
------- ------- ------- -------
total: - - n/a
`, "\n"),
buildTable("", base, head))
})
t.Run("package data only base", func(t *testing.T) {
base := &CoverProfile{
Total: 60,
Covered: 20,
Packages: map[string]*Package{
"github.com/flipgroup/golang-cover-diff/my/package": {
Total: 8,
Covered: 3,
},
},
}
head := &CoverProfile{
Total: 80,
Covered: 33,
}
assert.Equal(t, strings.Trim(`
package before after delta
------- ------- ------- -------
my/package 37.50% - gone
total: 33.33% 41.25% +7.92%
`, "\n"),
buildTable("github.com/flipgroup/golang-cover-diff", base, head))
})
t.Run("package data both sides", func(t *testing.T) {
base := &CoverProfile{
Total: 60,
Covered: 20,
Packages: map[string]*Package{
"github.com/flipgroup/golang-cover-diff/my/package": {
Total: 8,
Covered: 3,
},
"github.com/flipgroup/golang-cover-diff/apples": {
Total: 52,
Covered: 17,
},
},
}
head := &CoverProfile{
Total: 80,
Covered: 33,
Packages: map[string]*Package{
"github.com/flipgroup/golang-cover-diff/my/package": {
Total: 28,
Covered: 16,
},
"github.com/flipgroup/golang-cover-diff/apples": {
Total: 52,
Covered: 17,
},
},
}
// note: using `$-$` marker to defeat removal of trailing space from `.editorconfig` settings
assert.Equal(t, strings.ReplaceAll(strings.Trim(`
package before after delta
------- ------- ------- -------
apples 32.69% 32.69% $-$
my/package 37.50% 57.14% +19.64%
total: 33.33% 41.25% +7.92%
`, "\n"), "$-$", " "),
buildTable("github.com/flipgroup/golang-cover-diff", base, head))
})
}
func TestRelativePackage(t *testing.T) {
const rootPkgName = "github.com/flipgroup/golang-cover-diff/"
assert.Equal(t,
"my/cool/package",
relativePackage(rootPkgName, "my/cool/package"))
assert.Equal(t,
"my/cool/package",
relativePackage(rootPkgName, "github.com/flipgroup/golang-cover-diff/my/cool/package"))
assert.Equal(t,
"my/cool/package/with/a/stupidly/log/package/path/name/keep/going/on/going/plus/s",
relativePackage(rootPkgName, "github.com/flipgroup/golang-cover-diff/my/cool/package/with/a/stupidly/log/package/path/name/keep/going/on/going/plus/some/more/oh/my/when/will/this/end"))
}
func TestModuleName(t *testing.T) {
assert.Equal(t, "github.com/flipgroup/golang-cover-diff", moduleName())
}