Skip to content

Commit

Permalink
TestInitialiseLog
Browse files Browse the repository at this point in the history
  • Loading branch information
dave committed Dec 2, 2017
1 parent d209f2e commit e4060a4
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions blaster/blaster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,56 @@ import (

"io/ioutil"

"github.com/leemcloughlin/gofarmhash"
"github.com/pkg/errors"
)

func TestInitialiseLog(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())

b := New(ctx, cancel)
must(t, b.initialiseLog(""))

content := "hash,result,a,b\n1|2,false,3,4\n5|6,true,7,8"

f, _ := ioutil.TempFile("", "")
f.WriteString(content)
f.Close()

b = New(ctx, cancel)
b.Resume = false
must(t, b.initialiseLog(f.Name()))
if len(b.skip) != 0 {
t.Fatal("Should be zero skips with resume = false")
}

b.Exit()

// log file should now be empty
after, _ := ioutil.ReadFile(f.Name())
if string(after) != "hash,result\n" {
t.Fatal("Not expected, got:", string(after))
}

f, _ = ioutil.TempFile("", "")
f.WriteString(content)
f.Close()

b = New(ctx, cancel)
b.Resume = true
must(t, b.initialiseLog(f.Name()))
if !reflect.DeepEqual(b.skip, map[farmhash.Uint128]struct{}{farmhash.Uint128{5, 6}: {}}) {
t.Fatal("Enexpected contents in skip:", b.skip)
}

// log file should now be appended with a \n
after, _ = ioutil.ReadFile(f.Name())
if string(after) != content+"\n" {
t.Fatal("Not expected, got:", string(after))
}

}

func TestLoadEmptyLogs(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
b := New(ctx, cancel)
Expand Down

0 comments on commit e4060a4

Please sign in to comment.