2
0

filestorage_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package storage
  2. import (
  3. "os"
  4. "path/filepath"
  5. "testing"
  6. )
  7. func TestFileStorageListDirectoriesSymlink(t *testing.T) {
  8. storageBaseDir := t.TempDir()
  9. subdirName := "sub"
  10. slFileName := "sl"
  11. symlinkTargetDir := t.TempDir()
  12. if err := os.MkdirAll(filepath.Join(storageBaseDir, subdirName), 0700); err != nil {
  13. t.Fatalf("failed to construct subdir: %s", err)
  14. }
  15. if err := os.Symlink(symlinkTargetDir, filepath.Join(storageBaseDir, subdirName, slFileName)); err != nil {
  16. t.Fatalf("failed to create symlink at '%s' which points to '%s': %s", filepath.Join(storageBaseDir, subdirName, slFileName), symlinkTargetDir, err)
  17. }
  18. store := FileStorage{baseDir: storageBaseDir}
  19. dirs, err := store.ListDirectories(subdirName)
  20. if err != nil {
  21. t.Fatalf("failed to list directories: %s", err)
  22. }
  23. if len(dirs) != 1 {
  24. t.Fatalf("dirs should have 1 entry")
  25. }
  26. dir := dirs[0]
  27. // This condition is important -- the returned path should be relative to
  28. // the storage base dir, not the symlink's target dir.
  29. if dir.Name != filepath.Join(subdirName, slFileName) {
  30. t.Errorf("Expected dir.Name to be '%s' but it was '%s'", filepath.Join(subdirName, slFileName), dir.Name)
  31. }
  32. }
  33. func TestFileStorage_ReadToLocalFile(t *testing.T) {
  34. storeBaseDir := t.TempDir()
  35. store := NewFileStorage(storeBaseDir)
  36. TestStorageReadToLocalFile(t, store)
  37. }
  38. func TestFileStorage_ReadStream(t *testing.T) {
  39. storeBaseDir := t.TempDir()
  40. store := NewFileStorage(storeBaseDir)
  41. TestStorageReadStream(t, store)
  42. }