(c *C)
| 253 | } |
| 254 | |
| 255 | func (s *NoderSuite) TestRacyGit(c *C) { |
| 256 | td, err := os.MkdirTemp(c.MkDir(), "racy-git") |
| 257 | c.Assert(err, IsNil) |
| 258 | fs := osfs.New(td) |
| 259 | |
| 260 | origContent := []byte("foo") |
| 261 | err = WriteFile(fs, "racyfile", origContent, 0o644) |
| 262 | c.Assert(err, IsNil) |
| 263 | |
| 264 | fi, err := fs.Stat("racyfile") |
| 265 | c.Assert(err, IsNil) |
| 266 | modTime := fi.ModTime() |
| 267 | |
| 268 | fooHasher := plumbing.NewHasher(plumbing.BlobObject, int64(len(origContent))) |
| 269 | _, err = fooHasher.Write(origContent) |
| 270 | c.Assert(err, IsNil) |
| 271 | fooHash := fooHasher.Sum() |
| 272 | |
| 273 | idx := &index.Index{ |
| 274 | Version: 2, |
| 275 | Entries: []*index.Entry{ |
| 276 | { |
| 277 | Name: "racyfile", |
| 278 | Hash: fooHash, |
| 279 | Size: uint32(len(origContent)), |
| 280 | ModifiedAt: modTime, |
| 281 | Mode: filemode.Regular, |
| 282 | }, |
| 283 | }, |
| 284 | ModTime: modTime, |
| 285 | } |
| 286 | |
| 287 | newContent := []byte("bar") |
| 288 | c.Assert(len(origContent), Equals, len(newContent), Commentf("test setup requires same size")) |
| 289 | |
| 290 | err = WriteFile(fs, "racyfile", newContent, 0o644) |
| 291 | c.Assert(err, IsNil) |
| 292 | |
| 293 | err = os.Chtimes(filepath.Join(td, "racyfile"), modTime, modTime) |
| 294 | c.Assert(err, IsNil) |
| 295 | |
| 296 | fi, err = fs.Stat("racyfile") |
| 297 | c.Assert(err, IsNil) |
| 298 | c.Assert(uint32(len(origContent)), Equals, uint32(fi.Size()), Commentf("size should match")) |
| 299 | c.Assert(modTime, Equals, fi.ModTime(), Commentf("mtime should match")) |
| 300 | |
| 301 | actualContent, err := util.ReadFile(fs, "racyfile") |
| 302 | c.Assert(err, IsNil) |
| 303 | c.Assert(actualContent, DeepEquals, newContent, Commentf("content should have changed")) |
| 304 | c.Assert(origContent, Not(DeepEquals), actualContent, Commentf("content should be different")) |
| 305 | |
| 306 | barHasher := plumbing.NewHasher(plumbing.BlobObject, int64(len(newContent))) |
| 307 | _, err = barHasher.Write(newContent) |
| 308 | c.Assert(err, IsNil) |
| 309 | barHash := barHasher.Sum() |
| 310 | c.Assert(fooHash, Not(DeepEquals), barHash, Commentf("hashes should be different")) |
| 311 | |
| 312 | fsNode := NewRootNodeWithOptions(fs, nil, Options{Index: idx}) |
nothing calls this directly
no test coverage detected