-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
coverage_test.go
50 lines (47 loc) · 951 Bytes
/
coverage_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
package runn
import (
"context"
"encoding/json"
"fmt"
"os"
"path/filepath"
"testing"
"github.com/k1LoW/runn/testutil"
"github.com/tenntenn/golden"
)
func TestCoverage(t *testing.T) {
tests := []struct {
book string
}{
{"testdata/book/httpbin.yml"},
{"testdata/book/grpc.yml"},
}
t.Setenv("DEBUG", "false")
ctx := context.Background()
for _, tt := range tests {
tt := tt
t.Run(tt.book, func(t *testing.T) {
t.Parallel()
o, err := New(Book(tt.book))
if err != nil {
t.Fatal(err)
}
cov, err := o.collectCoverage(ctx)
if err != nil {
t.Fatal(err)
}
got, err := json.Marshal(cov)
if err != nil {
t.Fatal(err)
}
f := fmt.Sprintf("%s.coverage.json", filepath.Base(tt.book))
if os.Getenv("UPDATE_GOLDEN") != "" {
golden.Update(t, testutil.Testdata(), f, got)
return
}
if diff := golden.Diff(t, testutil.Testdata(), f, got); diff != "" {
t.Error(diff)
}
})
}
}