-
Notifications
You must be signed in to change notification settings - Fork 76
/
excoveralls_test.go
57 lines (45 loc) · 1.15 KB
/
excoveralls_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
package excoveralls
import (
"testing"
"gopkg.in/src-d/go-git.v4/plumbing/object"
"github.com/codeclimate/test-reporter/env"
"github.com/stretchr/testify/require"
)
func Test_Format(t *testing.T) {
gb := env.GitBlob
defer func() { env.GitBlob = gb }()
env.GitBlob = func(s string, c *object.Commit) (string, error) {
return s, nil
}
r := require.New(t)
rb := Formatter{
Path: "./excoveralls_example.json",
}
rep, err := rb.Format()
r.NoError(err)
r.InDelta(93.3, rep.CoveredPercent, 1)
sf := rep.SourceFiles["demo-app/services/update_user_info.ex"]
r.InDelta(100, sf.CoveredPercent, 1)
sfLc := sf.LineCounts
r.Equal(sfLc.Covered, 9)
r.Equal(sfLc.Missed, 0)
r.Equal(sfLc.Total, 9)
lc := rep.LineCounts
r.Equal(lc.Covered, 14)
r.Equal(lc.Missed, 1)
r.Equal(lc.Total, 15)
}
func Test_Format_MissingFile(t *testing.T) {
gb := env.GitBlob
defer func() { env.GitBlob = gb }()
env.GitBlob = func(s string, c *object.Commit) (string, error) {
return s, nil
}
r := require.New(t)
rb := Formatter{
Path: "./not_real.json",
}
_, err := rb.Format()
r.Error(err)
r.Equal("could not open coverage file ./not_real.json", err.Error())
}