forked from carmanchris31/reviewdog
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
comment_test.go
58 lines (47 loc) · 1.51 KB
/
comment_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
package reviewdog
import (
"bytes"
"context"
"strings"
"testing"
"github.com/reviewdog/reviewdog/filter"
"github.com/reviewdog/reviewdog/proto/rdf"
)
func TestMultiCommentService_Post(t *testing.T) {
buf1 := new(bytes.Buffer)
buf2 := new(bytes.Buffer)
w := MultiCommentService(NewRawCommentWriter(buf1), NewRawCommentWriter(buf2))
const want = "line1\nline2"
c := &Comment{Result: &filter.FilteredDiagnostic{Diagnostic: &rdf.Diagnostic{OriginalOutput: want}}}
if err := w.Post(context.Background(), c); err != nil {
t.Fatal(err)
}
if got := strings.Trim(buf1.String(), "\n"); got != want {
t.Errorf("writer 1: got %v, want %v", got, want)
}
if got := strings.Trim(buf2.String(), "\n"); got != want {
t.Errorf("writer 2: got %v, want %v", got, want)
}
if err := w.(BulkCommentService).Flush(context.Background()); err != nil {
t.Errorf("MultiCommentService implements BulkCommentService and should not return error when any services implements it: %v", err)
}
}
type fakeBulkCommentService struct {
BulkCommentService
calledFlush bool
}
func (f *fakeBulkCommentService) Flush(_ context.Context) error {
f.calledFlush = true
return nil
}
func TestMultiCommentService_Flush(t *testing.T) {
f1 := &fakeBulkCommentService{}
f2 := &fakeBulkCommentService{}
w := MultiCommentService(f1, f2)
if err := w.(BulkCommentService).Flush(context.Background()); err != nil {
t.Fatal(err)
}
if !f1.calledFlush || !f2.calledFlush {
t.Error("MultiCommentService_Flush should run Flush() for every services")
}
}