File: file_test.go

package info (click to toggle)
golang-github-go-git-go-git 5.16.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,684 kB
  • sloc: makefile: 81; sh: 76
file content (67 lines) | stat: -rw-r--r-- 1,633 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package fsnoder

import (
	"testing"

	"github.com/go-git/go-git/v5/utils/merkletrie/noder"

	. "gopkg.in/check.v1"
)

func Test(t *testing.T) { TestingT(t) }

type FileSuite struct{}

var _ = Suite(&FileSuite{})

var (
	HashOfEmptyFile = []byte{0xcb, 0xf2, 0x9c, 0xe4, 0x84, 0x22, 0x23, 0x25} // fnv64 basis offset
	HashOfContents  = []byte{0xee, 0x7e, 0xf3, 0xd0, 0xc2, 0xb5, 0xef, 0x83} // hash of "contents"
)

func (s *FileSuite) TestNewFileEmpty(c *C) {
	f, err := newFile("name", "")
	c.Assert(err, IsNil)

	c.Assert(f.Hash(), DeepEquals, HashOfEmptyFile)
	c.Assert(f.Name(), Equals, "name")
	c.Assert(f.IsDir(), Equals, false)
	assertChildren(c, f, noder.NoChildren)
	c.Assert(f.String(), Equals, "name<>")
}

func (s *FileSuite) TestNewFileWithContents(c *C) {
	f, err := newFile("name", "contents")
	c.Assert(err, IsNil)

	c.Assert(f.Hash(), DeepEquals, HashOfContents)
	c.Assert(f.Name(), Equals, "name")
	c.Assert(f.IsDir(), Equals, false)
	assertChildren(c, f, noder.NoChildren)
	c.Assert(f.String(), Equals, "name<contents>")
}

func (s *FileSuite) TestNewfileErrorEmptyName(c *C) {
	_, err := newFile("", "contents")
	c.Assert(err, Not(IsNil))
}

func (s *FileSuite) TestDifferentContentsHaveDifferentHash(c *C) {
	f1, err := newFile("name", "contents")
	c.Assert(err, IsNil)

	f2, err := newFile("name", "foo")
	c.Assert(err, IsNil)

	c.Assert(f1.Hash(), Not(DeepEquals), f2.Hash())
}

func (s *FileSuite) TestSameContentsHaveSameHash(c *C) {
	f1, err := newFile("name1", "contents")
	c.Assert(err, IsNil)

	f2, err := newFile("name2", "contents")
	c.Assert(err, IsNil)

	c.Assert(f1.Hash(), DeepEquals, f2.Hash())
}