This repository has been archived by the owner on Nov 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
logs_test.go
79 lines (71 loc) · 1.64 KB
/
logs_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
package tugboat
import (
"bytes"
"io"
"strings"
"testing"
)
func TestLogWriter(t *testing.T) {
tests := []struct {
in io.Reader
out []string
}{
{
strings.NewReader(`-----> Fetching custom git buildpack... done
-----> Go app detected
-----> Using go1.3
-----> Running: godep go install -tags heroku ./...
-----> Discovering process types
Procfile declares types -> web
-----> Compressing... done, 1.6MB
-----> Launching... done, v6
https://acme-inc.herokuapp.com/ deployed to Heroku
`),
[]string{
"-----> Fetching custom git buildpack... done\n",
"-----> Go app detected\n",
"-----> Using go1.3\n",
"-----> Running: godep go install -tags heroku ./...\n",
"-----> Discovering process types\n",
" Procfile declares types -> web\n",
"\n",
"-----> Compressing... done, 1.6MB\n",
"-----> Launching... done, v6\n",
" https://acme-inc.herokuapp.com/ deployed to Heroku\n",
"",
},
},
{
bytes.NewReader([]byte{
'h', 'e', 'l', 'l', 'o', '\n',
0x00,
'w', 'o', 'r', 'l', 'd',
}),
[]string{
"hello\n",
"world",
},
},
}
for _, tt := range tests {
var lines []*LogLine
w := &logWriter{
createLogLine: func(l *LogLine) error {
lines = append(lines, l)
return nil
},
deploymentID: "1",
}
if _, err := io.Copy(w, tt.in); err != nil {
t.Fatal(err)
}
if got, want := len(lines), len(tt.out); got != want {
t.Fatalf("len(lines) => %d; want %d", got, want)
}
for i := 0; i < len(lines); i++ {
if got, want := lines[i].Text, tt.out[i]; got != want {
t.Errorf("Line #%d => %q; want %q", i, got, want)
}
}
}
}