Merge branch 'master' into 9998-unsigned_manifest
[arvados.git] / services / keepstore / collision_test.go
1 package main
2
3 import (
4         "bytes"
5         "testing/iotest"
6
7         check "gopkg.in/check.v1"
8 )
9
10 var _ = check.Suite(&CollisionSuite{})
11
12 type CollisionSuite struct{}
13
14 func (s *CollisionSuite) TestCollisionOrCorrupt(c *check.C) {
15         fooMD5 := "acbd18db4cc2f85cedef654fccc4a4d8"
16
17         c.Check(collisionOrCorrupt(fooMD5, []byte{'f'}, []byte{'o'}, bytes.NewBufferString("o")),
18                 check.Equals, CollisionError)
19         c.Check(collisionOrCorrupt(fooMD5, []byte{'f'}, nil, bytes.NewBufferString("oo")),
20                 check.Equals, CollisionError)
21         c.Check(collisionOrCorrupt(fooMD5, []byte{'f'}, []byte{'o', 'o'}, nil),
22                 check.Equals, CollisionError)
23         c.Check(collisionOrCorrupt(fooMD5, nil, []byte{}, bytes.NewBufferString("foo")),
24                 check.Equals, CollisionError)
25         c.Check(collisionOrCorrupt(fooMD5, []byte{'f', 'o', 'o'}, nil, bytes.NewBufferString("")),
26                 check.Equals, CollisionError)
27         c.Check(collisionOrCorrupt(fooMD5, nil, nil, iotest.NewReadLogger("foo: ", iotest.DataErrReader(iotest.OneByteReader(bytes.NewBufferString("foo"))))),
28                 check.Equals, CollisionError)
29
30         c.Check(collisionOrCorrupt(fooMD5, []byte{'f', 'o', 'o'}, nil, bytes.NewBufferString("bar")),
31                 check.Equals, DiskHashError)
32         c.Check(collisionOrCorrupt(fooMD5, []byte{'f', 'o'}, nil, nil),
33                 check.Equals, DiskHashError)
34         c.Check(collisionOrCorrupt(fooMD5, []byte{}, nil, bytes.NewBufferString("")),
35                 check.Equals, DiskHashError)
36         c.Check(collisionOrCorrupt(fooMD5, []byte{'f', 'O'}, nil, bytes.NewBufferString("o")),
37                 check.Equals, DiskHashError)
38         c.Check(collisionOrCorrupt(fooMD5, []byte{'f', 'O', 'o'}, nil, nil),
39                 check.Equals, DiskHashError)
40         c.Check(collisionOrCorrupt(fooMD5, []byte{'f', 'o'}, []byte{'O'}, nil),
41                 check.Equals, DiskHashError)
42         c.Check(collisionOrCorrupt(fooMD5, []byte{'f', 'o'}, nil, bytes.NewBufferString("O")),
43                 check.Equals, DiskHashError)
44
45         c.Check(collisionOrCorrupt(fooMD5, []byte{}, nil, iotest.TimeoutReader(iotest.OneByteReader(bytes.NewBufferString("foo")))),
46                 check.Equals, iotest.ErrTimeout)
47 }