14645: Adds FUSE ops time to crunchstat output
[arvados.git] / services / keepstore / collision_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package main
6
7 import (
8         "bytes"
9         "testing/iotest"
10
11         check "gopkg.in/check.v1"
12 )
13
14 var _ = check.Suite(&CollisionSuite{})
15
16 type CollisionSuite struct{}
17
18 func (s *CollisionSuite) TestCollisionOrCorrupt(c *check.C) {
19         fooMD5 := "acbd18db4cc2f85cedef654fccc4a4d8"
20
21         c.Check(collisionOrCorrupt(fooMD5, []byte{'f'}, []byte{'o'}, bytes.NewBufferString("o")),
22                 check.Equals, CollisionError)
23         c.Check(collisionOrCorrupt(fooMD5, []byte{'f'}, nil, bytes.NewBufferString("oo")),
24                 check.Equals, CollisionError)
25         c.Check(collisionOrCorrupt(fooMD5, []byte{'f'}, []byte{'o', 'o'}, nil),
26                 check.Equals, CollisionError)
27         c.Check(collisionOrCorrupt(fooMD5, nil, []byte{}, bytes.NewBufferString("foo")),
28                 check.Equals, CollisionError)
29         c.Check(collisionOrCorrupt(fooMD5, []byte{'f', 'o', 'o'}, nil, bytes.NewBufferString("")),
30                 check.Equals, CollisionError)
31         c.Check(collisionOrCorrupt(fooMD5, nil, nil, iotest.NewReadLogger("foo: ", iotest.DataErrReader(iotest.OneByteReader(bytes.NewBufferString("foo"))))),
32                 check.Equals, CollisionError)
33
34         c.Check(collisionOrCorrupt(fooMD5, []byte{'f', 'o', 'o'}, nil, bytes.NewBufferString("bar")),
35                 check.Equals, DiskHashError)
36         c.Check(collisionOrCorrupt(fooMD5, []byte{'f', 'o'}, nil, nil),
37                 check.Equals, DiskHashError)
38         c.Check(collisionOrCorrupt(fooMD5, []byte{}, nil, bytes.NewBufferString("")),
39                 check.Equals, DiskHashError)
40         c.Check(collisionOrCorrupt(fooMD5, []byte{'f', 'O'}, nil, bytes.NewBufferString("o")),
41                 check.Equals, DiskHashError)
42         c.Check(collisionOrCorrupt(fooMD5, []byte{'f', 'O', 'o'}, nil, nil),
43                 check.Equals, DiskHashError)
44         c.Check(collisionOrCorrupt(fooMD5, []byte{'f', 'o'}, []byte{'O'}, nil),
45                 check.Equals, DiskHashError)
46         c.Check(collisionOrCorrupt(fooMD5, []byte{'f', 'o'}, nil, bytes.NewBufferString("O")),
47                 check.Equals, DiskHashError)
48
49         c.Check(collisionOrCorrupt(fooMD5, []byte{}, nil, iotest.TimeoutReader(iotest.OneByteReader(bytes.NewBufferString("foo")))),
50                 check.Equals, iotest.ErrTimeout)
51 }