-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcover_test.go
54 lines (52 loc) · 1.22 KB
/
cover_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
package tstat
import (
"reflect"
"testing"
)
func TestCoverage_Package(t *testing.T) {
type fields struct {
Percent float64
Packages []*PackageCoverage
}
type args struct {
name string
}
tests := []struct {
name string
fields fields
args args
want *PackageCoverage
}{
{
name: "Package found",
fields: fields{0, []*PackageCoverage{
{Name: "pkg1", Percent: 50, Files: []*FileCoverage{}},
{Name: "pkg2", Percent: 25, Files: []*FileCoverage{}},
{Name: "pkg3", Percent: 25, Files: []*FileCoverage{}},
}},
args: args{"pkg2"},
want: &PackageCoverage{Name: "pkg2", Percent: 25, Files: []*FileCoverage{}},
},
{
name: "Package not found",
fields: fields{0, []*PackageCoverage{}},
args: args{"notfound"},
want: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := &Coverage{
Percent: tt.fields.Percent,
Packages: tt.fields.Packages,
}
got, ok := c.Package(tt.args.name)
if (tt.want != nil) != ok {
t.Fatalf("Coverage.Package() package %s found=%v, want %v", tt.args.name, ok, tt.want)
}
if ok && !reflect.DeepEqual(got, tt.want) {
t.Errorf("Coverage.Package() got = %v, want %v", got, tt.want)
}
})
}
}