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) }
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) }
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) }
func (t *DependencyResolverTest) NoChildren() { var err error // Set up an empty listing. listing := []*fs.FileInfo{} serialized, err := repr.MarshalDir(listing) AssertEq(nil, err) score, err := t.store(serialized) AssertEq(nil, err) // Set up the node. n := &node{ RelPath: "taco/burrito", Info: fs.FileInfo{ Type: fs.TypeDirectory, Scores: []blob.Score{score}, }, } // Call deps, err := t.call(n) AssertEq(nil, err) ExpectThat(deps, ElementsAre()) ExpectThat(n.Children, ElementsAre()) }
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) }
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) }
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) }
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]) }
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) }
func (t *DirsTest) SymlinkWithScores() { // Set up a listing with a symlink that unexpectedly has associated scores. t.listing = []*fs.FileInfo{ &fs.FileInfo{ Type: fs.TypeSymlink, Name: "foo", Scores: []blob.Score{ blob.ComputeScore([]byte("0")), }, }, } var err error t.contents, err = repr.MarshalDir(t.listing) AssertEq(nil, err) t.score = blob.ComputeScore(t.contents) t.allScores = append(t.allScores, t.score) t.node = makeNode(true, t.score) // Load ExpectCall(t.blobStore, "Load")(Any(), Any()). WillOnce(Return(t.contents, nil)) // Call _, err = t.call(t.node) ExpectThat(err, Error(HasSubstr(t.score.Hex()))) ExpectThat(err, Error(HasSubstr("symlink"))) ExpectThat(err, Error(HasSubstr("scores"))) ExpectThat(t.getRecords(), ElementsAre()) }
func (t *DirsTest) UnknownEntryType() { // Set up a listing with an unsupported entry type. t.listing = []*fs.FileInfo{ &fs.FileInfo{ Type: fs.TypeCharDevice, Name: "foo", Scores: []blob.Score{ blob.ComputeScore([]byte("0")), }, }, } var err error t.contents, err = repr.MarshalDir(t.listing) AssertEq(nil, err) t.score = blob.ComputeScore(t.contents) t.allScores = append(t.allScores, t.score) t.node = makeNode(true, t.score) // Load ExpectCall(t.blobStore, "Load")(Any(), Any()). WillOnce(Return(t.contents, nil)) // Call _, err = t.call(t.node) ExpectThat(err, Error(HasSubstr("entry type"))) ExpectThat(err, Error(HasSubstr(fmt.Sprintf("%d", fs.TypeCharDevice)))) ExpectThat(t.getRecords(), ElementsAre()) }
func (t *DirsTest) SetUp(ti *TestInfo) { // Set up canned data for a valid listing. t.listing = []*fs.FileInfo{ &fs.FileInfo{ Type: fs.TypeFile, Name: "foo", Scores: []blob.Score{ blob.ComputeScore([]byte("0")), blob.ComputeScore([]byte("1")), }, }, &fs.FileInfo{ Type: fs.TypeDirectory, Name: "bar", Scores: []blob.Score{ blob.ComputeScore([]byte("2")), }, }, &fs.FileInfo{ Type: fs.TypeSymlink, Name: "baz", Target: "asdf", }, } var err error t.contents, err = repr.MarshalDir(t.listing) AssertEq(nil, err) t.score = blob.ComputeScore(t.contents) t.node = makeNode(true, t.score) t.allScores = append(t.allScores, t.score) // Set up canned nodes. t.knownNode = Node{ Dir: true, Score: blob.ComputeScore([]byte("knownNode")), } t.unknownNode = Node{ Dir: true, Score: blob.ComputeScore([]byte("unknownNode")), } t.allScores = append(t.allScores, t.knownNode.Score) // Call through. t.superTest.setUp(ti) }
func (t *DependencyResolverTest) SomeChildren() { var err error // Set up a listing. listing := []*fs.FileInfo{ &fs.FileInfo{ Type: fs.TypeFile, Name: "foo", Permissions: 0754, MTime: time.Now().Round(time.Millisecond), }, &fs.FileInfo{ Type: fs.TypeDirectory, Name: "bar", Scores: []blob.Score{blob.ComputeScore([]byte(""))}, MTime: time.Now().Round(time.Millisecond), }, } serialized, err := repr.MarshalDir(listing) AssertEq(nil, err) score, err := t.store(serialized) AssertEq(nil, err) // Set up the node. n := &node{ RelPath: "taco/burrito", Info: fs.FileInfo{ Type: fs.TypeDirectory, Scores: []blob.Score{score}, }, } // Call deps, err := t.call(n) AssertEq(nil, err) AssertEq(2, len(deps)) AssertThat(n.Children, DeepEquals(deps)) var child *node child = n.Children[0] ExpectEq("taco/burrito/foo", child.RelPath) ExpectThat(child.Info, DeepEquals(*listing[0])) child = n.Children[1] ExpectEq("taco/burrito/bar", child.RelPath) ExpectThat(child.Info, DeepEquals(*listing[1])) }
func (t *RoundtripTest) UnknownType() { // Input in := []*fs.FileInfo{ makeLegalEntry(), makeLegalEntry(), makeLegalEntry(), } in[1].Type = 17 // Marshal _, err := repr.MarshalDir(in) ExpectThat(err, Error(HasSubstr("EntryType"))) ExpectThat(err, Error(HasSubstr("17"))) }
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()) }
func (t *MarshalTest) LeavesOutDeviceNumberForNonDevices() { // Input entries := []*fs.FileInfo{ &fs.FileInfo{Type: fs.TypeFile}, &fs.FileInfo{Type: fs.TypeDirectory}, } // Call data, err := repr.MarshalDir(entries) AssertEq(nil, err) data = data[:len(data)-1] listingProto := new(repr_proto.DirectoryListingProto) err = proto.Unmarshal(data, listingProto) AssertEq(nil, err) AssertThat(listingProto.Entry, ElementsAre(Any(), Any())) ExpectEq(nil, listingProto.Entry[0].DeviceNumber) ExpectEq(nil, listingProto.Entry[1].DeviceNumber) }
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) }