| 494 | } |
| 495 | |
| 496 | func TestScanOwnershipPOSIX(t *testing.T) { |
| 497 | // This test works on all operating systems because the FakeFS is always POSIXy. |
| 498 | |
| 499 | fakeFS := fs.NewFilesystem(fs.FilesystemTypeFake, "TestScanOwnership") |
| 500 | current := make(fakeCurrentFiler) |
| 501 | |
| 502 | fakeFS.Create("root-owned") |
| 503 | fakeFS.Create("user-owned") |
| 504 | fakeFS.Lchown("user-owned", "1234", "5678") |
| 505 | fakeFS.Mkdir("user-owned-dir", 0o755) |
| 506 | fakeFS.Lchown("user-owned-dir", "2345", "6789") |
| 507 | |
| 508 | expected := []struct { |
| 509 | name string |
| 510 | uid, gid int |
| 511 | }{ |
| 512 | {"root-owned", 0, 0}, |
| 513 | {"user-owned", 1234, 5678}, |
| 514 | {"user-owned-dir", 2345, 6789}, |
| 515 | } |
| 516 | |
| 517 | files := walkDir(fakeFS, ".", current, nil, 0) |
| 518 | if len(files) != len(expected) { |
| 519 | t.Fatalf("expected %d items, not %d", len(expected), len(files)) |
| 520 | } |
| 521 | for i := range expected { |
| 522 | if files[i].Name != expected[i].name { |
| 523 | t.Errorf("expected %s, got %s", expected[i].name, files[i].Name) |
| 524 | continue |
| 525 | } |
| 526 | |
| 527 | if files[i].Platform.Unix == nil { |
| 528 | t.Error("failed to load POSIX data on", files[i].Name) |
| 529 | continue |
| 530 | } |
| 531 | if files[i].Platform.Unix.UID != expected[i].uid { |
| 532 | t.Errorf("expected %d, got %d", expected[i].uid, files[i].Platform.Unix.UID) |
| 533 | } |
| 534 | if files[i].Platform.Unix.GID != expected[i].gid { |
| 535 | t.Errorf("expected %d, got %d", expected[i].gid, files[i].Platform.Unix.GID) |
| 536 | } |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | func TestScanOwnershipWindows(t *testing.T) { |
| 541 | if !build.IsWindows { |