sharedpullerstate_test.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package model
  7. import (
  8. "testing"
  9. "github.com/syncthing/syncthing/lib/fs"
  10. "github.com/syncthing/syncthing/lib/sync"
  11. )
  12. // Test creating temporary file inside read-only directory
  13. func TestReadOnlyDir(t *testing.T) {
  14. testOs := &fatalOs{t}
  15. // Create a read only directory, clean it up afterwards.
  16. testOs.Mkdir("testdata/read_only_dir", 0555)
  17. defer func() {
  18. testOs.Chmod("testdata/read_only_dir", 0755)
  19. testOs.RemoveAll("testdata/read_only_dir")
  20. }()
  21. s := sharedPullerState{
  22. fs: fs.NewFilesystem(fs.FilesystemTypeBasic, "testdata"),
  23. tempName: "read_only_dir/.temp_name",
  24. mut: sync.NewRWMutex(),
  25. }
  26. fd, err := s.tempFile()
  27. if err != nil {
  28. t.Fatal(err)
  29. }
  30. if fd == nil {
  31. t.Fatal("Unexpected nil fd")
  32. }
  33. s.fail("Test done", nil)
  34. s.finalClose()
  35. }