Skip to content

Commit e4060a4

Browse files
committed
TestInitialiseLog
1 parent d209f2e commit e4060a4

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

blaster/blaster_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,56 @@ import (
2020

2121
"io/ioutil"
2222

23+
"github.com/leemcloughlin/gofarmhash"
2324
"github.com/pkg/errors"
2425
)
2526

27+
func TestInitialiseLog(t *testing.T) {
28+
ctx, cancel := context.WithCancel(context.Background())
29+
30+
b := New(ctx, cancel)
31+
must(t, b.initialiseLog(""))
32+
33+
content := "hash,result,a,b\n1|2,false,3,4\n5|6,true,7,8"
34+
35+
f, _ := ioutil.TempFile("", "")
36+
f.WriteString(content)
37+
f.Close()
38+
39+
b = New(ctx, cancel)
40+
b.Resume = false
41+
must(t, b.initialiseLog(f.Name()))
42+
if len(b.skip) != 0 {
43+
t.Fatal("Should be zero skips with resume = false")
44+
}
45+
46+
b.Exit()
47+
48+
// log file should now be empty
49+
after, _ := ioutil.ReadFile(f.Name())
50+
if string(after) != "hash,result\n" {
51+
t.Fatal("Not expected, got:", string(after))
52+
}
53+
54+
f, _ = ioutil.TempFile("", "")
55+
f.WriteString(content)
56+
f.Close()
57+
58+
b = New(ctx, cancel)
59+
b.Resume = true
60+
must(t, b.initialiseLog(f.Name()))
61+
if !reflect.DeepEqual(b.skip, map[farmhash.Uint128]struct{}{farmhash.Uint128{5, 6}: {}}) {
62+
t.Fatal("Enexpected contents in skip:", b.skip)
63+
}
64+
65+
// log file should now be appended with a \n
66+
after, _ = ioutil.ReadFile(f.Name())
67+
if string(after) != content+"\n" {
68+
t.Fatal("Not expected, got:", string(after))
69+
}
70+
71+
}
72+
2673
func TestLoadEmptyLogs(t *testing.T) {
2774
ctx, cancel := context.WithCancel(context.Background())
2875
b := New(ctx, cancel)

0 commit comments

Comments
 (0)