Exemplo n.º 1
0
func (t *RoundtripTest) PreservesSymlinkTargets() {
	// Input
	in := []*fs.FileInfo{
		makeLegalEntry(),
		makeLegalEntry(),
	}

	in[0].Type = fs.TypeSymlink
	in[1].Type = fs.TypeSymlink

	in[0].Target = "taco"
	in[1].Target = "burrito"

	// Marshal
	d, err := repr.MarshalDir(in)
	AssertEq(nil, err)
	AssertNe(nil, d)

	// Unmarshal
	out, err := repr.UnmarshalDir(d)
	AssertEq(nil, err)
	AssertNe(nil, out)

	// Output
	AssertThat(out, ElementsAre(Any(), Any()))

	ExpectEq(in[0].Target, out[0].Target)
	ExpectEq(in[1].Target, out[1].Target)
}
Exemplo n.º 2
0
func (t *RoundtripTest) PreservesInode() {
	// Input
	in := []*fs.FileInfo{
		makeLegalEntry(),
		makeLegalEntry(),
	}

	in[0].Inode = 17
	in[1].Inode = 19

	// Marshal
	d, err := repr.MarshalDir(in)
	AssertEq(nil, err)
	AssertNe(nil, d)

	// Unmarshal
	out, err := repr.UnmarshalDir(d)
	AssertEq(nil, err)
	AssertNe(nil, out)

	// Output
	AssertEq(2, len(out))

	ExpectEq(in[0].Inode, out[0].Inode)
	ExpectEq(in[1].Inode, out[1].Inode)
}
Exemplo n.º 3
0
func (t *RoundtripTest) PreservesDeviceNumbers() {
	// Input
	in := []*fs.FileInfo{
		makeLegalEntry(),
		makeLegalEntry(),
	}

	in[0].Type = fs.TypeCharDevice
	in[1].Type = fs.TypeBlockDevice

	in[0].DeviceNumber = 17
	in[1].DeviceNumber = 19

	// Marshal
	d, err := repr.MarshalDir(in)
	AssertEq(nil, err)
	AssertNe(nil, d)

	// Unmarshal
	out, err := repr.UnmarshalDir(d)
	AssertEq(nil, err)
	AssertNe(nil, out)

	// Output
	AssertThat(out, ElementsAre(Any(), Any()))

	ExpectEq(in[0].DeviceNumber, out[0].DeviceNumber)
	ExpectEq(in[1].DeviceNumber, out[1].DeviceNumber)
}
Exemplo n.º 4
0
func (t *RoundtripTest) PreservesScores() {
	// Input
	in := []*fs.FileInfo{
		makeLegalEntry(),
		makeLegalEntry(),
	}

	score00 := blob.ComputeScore([]byte("taco"))
	score01 := blob.ComputeScore([]byte("burrito"))
	score10 := blob.ComputeScore([]byte("enchilada"))

	in[0].Scores = []blob.Score{score00, score01}
	in[1].Scores = []blob.Score{score10}

	// Marshal
	d, err := repr.MarshalDir(in)
	AssertEq(nil, err)
	AssertNe(nil, d)

	// Unmarshal
	out, err := repr.UnmarshalDir(d)
	AssertEq(nil, err)
	AssertNe(nil, out)

	// Output
	AssertThat(out, ElementsAre(Any(), Any()))

	AssertThat(out[0].Scores, ElementsAre(Any(), Any()))
	ExpectEq(score00, out[0].Scores[0])
	ExpectEq(score01, out[0].Scores[1])

	AssertThat(out[1].Scores, ElementsAre(Any()))
	ExpectEq(score10, out[1].Scores[0])
}
Exemplo n.º 5
0
func (t *RoundtripTest) PreservesHardLinkTargets() {
	// Input
	in := []*fs.FileInfo{
		makeLegalEntry(),
		makeLegalEntry(),
	}

	s := "taco"
	in[0].HardLinkTarget = &s

	// Marshal
	d, err := repr.MarshalDir(in)
	AssertEq(nil, err)
	AssertNe(nil, d)

	// Unmarshal
	out, err := repr.UnmarshalDir(d)
	AssertEq(nil, err)
	AssertNe(nil, out)

	// Output
	AssertThat(out, ElementsAre(Any(), Any()))

	AssertNe(nil, out[0].HardLinkTarget)
	ExpectEq(*in[0].HardLinkTarget, *out[0].HardLinkTarget)
	ExpectEq(nil, out[1].HardLinkTarget)
}
Exemplo n.º 6
0
func (t *RoundtripTest) PreservesModTimes() {
	// Input
	in := []*fs.FileInfo{
		makeLegalEntry(),
		makeLegalEntry(),
	}

	in[0].MTime = time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
	in[1].MTime = time.Date(1985, time.March, 18, 15, 33, 0, 0, time.UTC)

	// Marshal
	d, err := repr.MarshalDir(in)
	AssertEq(nil, err)
	AssertNe(nil, d)

	// Unmarshal
	out, err := repr.UnmarshalDir(d)
	AssertEq(nil, err)
	AssertNe(nil, out)

	// Output
	AssertThat(out, ElementsAre(Any(), Any()))

	ExpectTrue(in[0].MTime.Equal(out[0].MTime), "%v", out[0].MTime)
	ExpectTrue(in[1].MTime.Equal(out[1].MTime), "%v", out[1].MTime)
}
Exemplo n.º 7
0
func (t *RoundtripTest) PreservesGids() {
	// Input
	in := []*fs.FileInfo{
		makeLegalEntry(),
		makeLegalEntry(),
	}

	in[0].Gid = 17
	in[1].Gid = 19

	// Marshal
	d, err := repr.MarshalDir(in)
	AssertEq(nil, err)
	AssertNe(nil, d)

	// Unmarshal
	out, err := repr.UnmarshalDir(d)
	AssertEq(nil, err)
	AssertNe(nil, out)

	// Output
	AssertThat(out, ElementsAre(Any(), Any()))

	ExpectEq(in[0].Gid, out[0].Gid)
	ExpectEq(in[1].Gid, out[1].Gid)
}
Exemplo n.º 8
0
func (t *RoundtripTest) PreservesPermissions() {
	// Input
	in := []*fs.FileInfo{
		makeLegalEntry(),
		makeLegalEntry(),
	}

	in[0].Permissions = 0644 | os.ModeSticky | os.ModeSetuid
	in[1].Permissions = 0755 | os.ModeSetgid

	// Marshal
	d, err := repr.MarshalDir(in)
	AssertEq(nil, err)
	AssertNe(nil, d)

	// Unmarshal
	out, err := repr.UnmarshalDir(d)
	AssertEq(nil, err)
	AssertNe(nil, out)

	// Output
	AssertThat(out, ElementsAre(Any(), Any()))

	ExpectEq(in[0].Permissions, out[0].Permissions)
	ExpectEq(in[1].Permissions, out[1].Permissions)
}
Exemplo n.º 9
0
func (t *RoundtripTest) NoEntries() {
	// Input
	in := []*fs.FileInfo{}

	// Marshal
	d, err := repr.MarshalDir(in)
	AssertEq(nil, err)
	AssertNe(nil, d)

	// Unmarshal
	out, err := repr.UnmarshalDir(d)
	AssertEq(nil, err)
	AssertNe(nil, out)

	// Output
	ExpectThat(out, ElementsAre())
}
Exemplo n.º 10
0
func (t *VisitorTest) Directory() {
	var err error

	// Children
	child0 := &fsNode{
		Info: fs.FileInfo{
			Name:  "taco",
			MTime: time.Date(2012, time.August, 15, 12, 56, 00, 0, time.Local),
		},
	}

	child1 := &fsNode{
		Info: fs.FileInfo{
			Name:  "burrito",
			MTime: time.Date(2015, 4, 5, 2, 15, 0, 0, time.Local),
		},
	}

	// Node setup
	t.node.RelPath = ""
	t.node.Info = fs.FileInfo{
		Type: fs.TypeDirectory,
	}

	t.node.Children = []*fsNode{child0, child1}

	// Snoop on the call to the blob store.
	var savedReq *blob.StoreRequest
	expectedScore := blob.ComputeScore([]byte("taco"))

	ExpectCall(t.blobStore, "Store")(Any(), Any()).
		WillOnce(DoAll(SaveArg(1, &savedReq), Return(expectedScore, nil)))

	// Call
	err = t.call()
	AssertEq(nil, err)
	AssertThat(t.node.Info.Scores, ElementsAre(expectedScore))

	// Parse the blob.
	entries, err := repr.UnmarshalDir(savedReq.Blob)
	AssertEq(nil, err)
	AssertEq(2, len(entries))

	ExpectThat(*entries[0], DeepEquals(child0.Info))
	ExpectThat(*entries[1], DeepEquals(child1.Info))
}
Exemplo n.º 11
0
func (t *RoundtripTest) PreservesTypes() {
	// Input
	in := []*fs.FileInfo{
		makeLegalEntry(),
		makeLegalEntry(),
		makeLegalEntry(),
		makeLegalEntry(),
		makeLegalEntry(),
		makeLegalEntry(),
	}

	in[0].Type = fs.TypeFile
	in[1].Type = fs.TypeDirectory
	in[2].Type = fs.TypeSymlink
	in[3].Type = fs.TypeBlockDevice
	in[4].Type = fs.TypeCharDevice
	in[5].Type = fs.TypeNamedPipe

	// Marshal
	d, err := repr.MarshalDir(in)
	AssertEq(nil, err)
	AssertNe(nil, d)

	// Unmarshal
	out, err := repr.UnmarshalDir(d)
	AssertEq(nil, err)
	AssertNe(nil, out)

	// Output
	AssertEq(6, len(out))

	ExpectEq(in[0].Type, out[0].Type)
	ExpectEq(in[1].Type, out[1].Type)
	ExpectEq(in[2].Type, out[2].Type)
	ExpectEq(in[3].Type, out[3].Type)
	ExpectEq(in[4].Type, out[4].Type)
	ExpectEq(in[5].Type, out[5].Type)
}