fileinfo_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Rufs - Remote Union File System
  3. *
  4. * Copyright 2017 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the MIT
  7. * License, If a copy of the MIT License was not distributed with this
  8. * file, You can obtain one at https://opensource.org/licenses/MIT.
  9. */
  10. package rufs
  11. import (
  12. "io/ioutil"
  13. "os"
  14. "testing"
  15. "time"
  16. )
  17. func TestFileInfo(t *testing.T) {
  18. oldUnitTestModes := unitTestModes
  19. unitTestModes = false
  20. defer func() {
  21. unitTestModes = oldUnitTestModes
  22. }()
  23. fi := &FileInfo{"test", 500, os.FileMode(0764), time.Time{}, "123", false, ""}
  24. if fi.String() != "test 123 [500] -rwxrw-r-- (0001-01-01 00:00:00 +0000 UTC) - <nil>" {
  25. t.Error("Unexpected result:", fi)
  26. return
  27. }
  28. fi = &FileInfo{"test", 500, os.FileMode(0764), time.Time{}, "", false, ""}
  29. if fi.String() != "test [500] -rwxrw-r-- (0001-01-01 00:00:00 +0000 UTC) - <nil>" {
  30. t.Error("Unexpected result:", fi)
  31. return
  32. }
  33. ioutil.WriteFile("foo.txt", []byte("bar"), 0660)
  34. defer os.Remove("foo.txt")
  35. fi = &FileInfo{"foo.txt", 500, os.ModeSymlink, time.Time{}, "", false, ""}
  36. fi = WrapFileInfo("./", fi).(*FileInfo)
  37. if fi.String() != "foo.txt [3] -rw-rw---- (0001-01-01 00:00:00 +0000 UTC) - <nil>" &&
  38. fi.String() != "foo.txt [3] -rw-r----- (0001-01-01 00:00:00 +0000 UTC) - <nil>" &&
  39. fi.String() != "foo.txt [3] -rw-rw-rw- (0001-01-01 00:00:00 +0000 UTC) - <nil>" {
  40. t.Error("Unexpected result:", fi)
  41. return
  42. }
  43. }