-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils_test.go
More file actions
41 lines (35 loc) · 822 Bytes
/
utils_test.go
File metadata and controls
41 lines (35 loc) · 822 Bytes
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
package utils
import (
"bytes"
"strings"
"testing"
)
func TestStreamOuptutSuccess(t *testing.T) {
str := "abc\ndef\n"
src := strings.NewReader(str)
dest := bytes.NewBuffer(nil)
out := bytes.NewBuffer(nil)
err := streamOutput(src, dest, out)
if err != nil {
t.Fatal(err)
}
destStr := string(dest.Bytes())
if destStr != str {
t.Fatalf("dest was [%s], expected [%s]", destStr, str)
}
outStr := string(out.Bytes())
if outStr != str {
t.Fatalf("out was [%s], expected [%s]", outStr, str)
}
}
func TestStreamOutputErr(t *testing.T) {
// no ending newline
str := "abc\ndef"
src := strings.NewReader(str)
dest := bytes.NewBuffer(nil)
out := bytes.NewBuffer(nil)
err := streamOutput(src, dest, out)
if err == nil {
t.Fatal("expected an error for a string that doesn't end with a newline")
}
}