forked from ycrash/yc-360-script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost_test.go
More file actions
57 lines (54 loc) · 973 Bytes
/
post_test.go
File metadata and controls
57 lines (54 loc) · 973 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package shell
import (
"io"
"io/ioutil"
"os"
"testing"
)
func TestLastNLines(t *testing.T) {
file, err := os.Open("config/testdata/config.yaml")
if err != nil {
t.Fatal(err)
}
defer file.Close()
err = PositionLastLines(file, 5)
if err != nil {
t.Fatal(err)
}
bytes, err := ioutil.ReadAll(file)
if err != nil {
t.Fatal(err)
}
result := ` - urlParams: pidstat
cmd: pidstat
processTokens:
- uploadDir
- buggyApp`
if string(bytes) != result {
t.Fatalf("invalid result '%x' != '%x'", bytes, result)
}
}
func TestLast1000Lines(t *testing.T) {
src, err := os.Open("testdata/tier1app.txt")
if err != nil {
t.Fatal(err)
}
defer src.Close()
err = PositionLastLines(src, 1000)
if err != nil {
t.Fatal(err)
}
dst, err := os.Create("testdata/applog.txt")
if err != nil {
t.Fatal(err)
}
defer dst.Close()
_, err = io.Copy(dst, src)
if err != nil {
t.Fatal(err)
}
err = dst.Sync()
if err != nil {
t.Fatal(err)
}
}