From 4fe299292452003be1405c1a6ab0bb8d9f40fa27 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Thu, 17 Jul 2014 14:48:02 +0200 Subject: [PATCH] Repair tests for latest changes --- model/model_test.go | 12 +++++++++++- protocol/protocol_test.go | 20 ++++++++++---------- scanner/walk_test.go | 17 ++++++++++++++--- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/model/model_test.go b/model/model_test.go index b6f50494..7ed9061c 100644 --- a/model/model_test.go +++ b/model/model_test.go @@ -175,11 +175,21 @@ func (f FakeConnection) ID() protocol.NodeID { return f.id } +func (f FakeConnection) Name() string { + return "" +} + func (f FakeConnection) Option(string) string { return "" } -func (FakeConnection) Index(string, []protocol.FileInfo) {} +func (FakeConnection) Index(string, []protocol.FileInfo) error { + return nil +} + +func (FakeConnection) IndexUpdate(string, []protocol.FileInfo) error { + return nil +} func (f FakeConnection) Request(repo, name string, offset int64, size int) ([]byte, error) { return f.requestData, nil diff --git a/protocol/protocol_test.go b/protocol/protocol_test.go index a7e29550..0da9ffb2 100644 --- a/protocol/protocol_test.go +++ b/protocol/protocol_test.go @@ -59,8 +59,8 @@ func TestPing(t *testing.T) { ar, aw := io.Pipe() br, bw := io.Pipe() - c0 := NewConnection(c0ID, ar, bw, nil).(wireFormatConnection).next.(*rawConnection) - c1 := NewConnection(c1ID, br, aw, nil).(wireFormatConnection).next.(*rawConnection) + c0 := NewConnection(c0ID, ar, bw, nil, "name").(wireFormatConnection).next.(*rawConnection) + c1 := NewConnection(c1ID, br, aw, nil, "name").(wireFormatConnection).next.(*rawConnection) if ok := c0.ping(); !ok { t.Error("c0 ping failed") @@ -83,8 +83,8 @@ func TestPingErr(t *testing.T) { eaw := &ErrPipe{PipeWriter: *aw, max: i, err: e} ebw := &ErrPipe{PipeWriter: *bw, max: j, err: e} - c0 := NewConnection(c0ID, ar, ebw, m0).(wireFormatConnection).next.(*rawConnection) - NewConnection(c1ID, br, eaw, m1) + c0 := NewConnection(c0ID, ar, ebw, m0, "name").(wireFormatConnection).next.(*rawConnection) + NewConnection(c1ID, br, eaw, m1, "name") res := c0.ping() if (i < 4 || j < 4) && res { @@ -159,8 +159,8 @@ func TestVersionErr(t *testing.T) { ar, aw := io.Pipe() br, bw := io.Pipe() - c0 := NewConnection(c0ID, ar, bw, m0).(wireFormatConnection).next.(*rawConnection) - NewConnection(c1ID, br, aw, m1) + c0 := NewConnection(c0ID, ar, bw, m0, "name").(wireFormatConnection).next.(*rawConnection) + NewConnection(c1ID, br, aw, m1, "name") c0.xw.WriteUint32(encodeHeader(header{ version: 2, @@ -181,8 +181,8 @@ func TestTypeErr(t *testing.T) { ar, aw := io.Pipe() br, bw := io.Pipe() - c0 := NewConnection(c0ID, ar, bw, m0).(wireFormatConnection).next.(*rawConnection) - NewConnection(c1ID, br, aw, m1) + c0 := NewConnection(c0ID, ar, bw, m0, "name").(wireFormatConnection).next.(*rawConnection) + NewConnection(c1ID, br, aw, m1, "name") c0.xw.WriteUint32(encodeHeader(header{ version: 0, @@ -203,8 +203,8 @@ func TestClose(t *testing.T) { ar, aw := io.Pipe() br, bw := io.Pipe() - c0 := NewConnection(c0ID, ar, bw, m0).(wireFormatConnection).next.(*rawConnection) - NewConnection(c1ID, br, aw, m1) + c0 := NewConnection(c0ID, ar, bw, m0, "name").(wireFormatConnection).next.(*rawConnection) + NewConnection(c1ID, br, aw, m1, "name") c0.close(nil) diff --git a/scanner/walk_test.go b/scanner/walk_test.go index 97d9779c..62e28c4f 100644 --- a/scanner/walk_test.go +++ b/scanner/walk_test.go @@ -9,6 +9,8 @@ import ( "reflect" "testing" "time" + + "github.com/calmh/syncthing/protocol" ) var testdata = []struct { @@ -17,6 +19,7 @@ var testdata = []struct { hash string }{ {"bar", 10, "2f72cc11a6fcd0271ecef8c61056ee1eb1243be3805bf9a9df98f92f7636b05c"}, + {"baz", 0, ""}, {"empty", 0, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"}, {"foo", 7, "aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f"}, } @@ -31,13 +34,19 @@ func TestWalk(t *testing.T) { BlockSize: 128 * 1024, IgnoreFile: ".stignore", } - files, ignores, err := w.Walk() + fchan, ignores, err := w.Walk() + var files []protocol.FileInfo + for f := range fchan { + files = append(files, f) + } if err != nil { t.Fatal(err) } if l1, l2 := len(files), len(testdata); l1 != l2 { + t.Log(files) + t.Log(testdata) t.Fatalf("Incorrect number of walked files %d != %d", l1, l2) } @@ -46,8 +55,10 @@ func TestWalk(t *testing.T) { t.Errorf("Incorrect file name %q != %q for case #%d", n1, n2, i) } - if h1, h2 := fmt.Sprintf("%x", files[i].Blocks[0].Hash), testdata[i].hash; h1 != h2 { - t.Errorf("Incorrect hash %q != %q for case #%d", h1, h2, i) + if testdata[i].hash != "" { + if h1, h2 := fmt.Sprintf("%x", files[i].Blocks[0].Hash), testdata[i].hash; h1 != h2 { + t.Errorf("Incorrect hash %q != %q for case #%d", h1, h2, i) + } } t0 := time.Date(2010, 1, 1, 0, 0, 0, 0, time.UTC).Unix()