Debian Codegraph @

plumbing/format/index/index_test.go

raw
1 package index
2
3 import (
4 "path/filepath"
5
6 . "gopkg.in/check.v1"
7 )
8
9 func (s *IndexSuite) TestIndexAdd(c *C) {
10 idx := &Index{}
11 e := idx.Add("foo")
12 e.Size = 42
13
14 e, err := idx.Entry("foo")
15 c.Assert(err, IsNil)
16 c.Assert(e.Name, Equals, "foo")
17 c.Assert(e.Size, Equals, uint32(42))
18 }
19
20 func (s *IndexSuite) TestIndexEntry(c *C) {
21 idx := &Index{
22 Entries: []*Entry{
23 {Name: "foo", Size: 42},
24 {Name: "bar", Size: 82},
25 },
26 }
27
28 e, err := idx.Entry("foo")
29 c.Assert(err, IsNil)
30 c.Assert(e.Name, Equals, "foo")
31
32 e, err = idx.Entry("missing")
33 c.Assert(e, IsNil)
34 c.Assert(err, Equals, ErrEntryNotFound)
35 }
36
37 func (s *IndexSuite) TestIndexRemove(c *C) {
38 idx := &Index{
39 Entries: []*Entry{
40 {Name: "foo", Size: 42},
41 {Name: "bar", Size: 82},
42 },
43 }
44
45 e, err := idx.Remove("foo")
46 c.Assert(err, IsNil)
47 c.Assert(e.Name, Equals, "foo")
48
49 e, err = idx.Remove("foo")
50 c.Assert(e, IsNil)
51 c.Assert(err, Equals, ErrEntryNotFound)
52 }
53
54 func (s *IndexSuite) TestIndexGlob(c *C) {
55 idx := &Index{
56 Entries: []*Entry{
57 {Name: "foo/bar/bar", Size: 42},
58 {Name: "foo/baz/qux", Size: 42},
59 {Name: "fux", Size: 82},
60 },
61 }
62
63 m, err := idx.Glob(filepath.Join("foo", "b*"))
64 c.Assert(err, IsNil)
65 c.Assert(m, HasLen, 2)
66 c.Assert(m[0].Name, Equals, "foo/bar/bar")
67 c.Assert(m[1].Name, Equals, "foo/baz/qux")
68
69 m, err = idx.Glob("f*")
70 c.Assert(err, IsNil)
71 c.Assert(m, HasLen, 3)
72
73 m, err = idx.Glob("f*/baz/q*")
74 c.Assert(err, IsNil)
75 c.Assert(m, HasLen, 1)
76 }