TestUserCleanFs verifies that Clean builds the user filesystem according to the followExternalSymlinks flag and that FullPath resolves correctly for either implementation.
(t *testing.T)
| 12 | // followExternalSymlinks flag and that FullPath resolves correctly for either |
| 13 | // implementation. |
| 14 | func TestUserCleanFs(t *testing.T) { |
| 15 | base := t.TempDir() |
| 16 | want := filepath.Join(base, "data", "x") |
| 17 | |
| 18 | t.Run("default builds a symlink-confining ScopedFs", func(t *testing.T) { |
| 19 | u := &User{Username: "u", Password: "p", Scope: "data"} |
| 20 | if err := u.Clean(base, false); err != nil { |
| 21 | t.Fatal(err) |
| 22 | } |
| 23 | if _, ok := u.Fs.(*files.ScopedFs); !ok { |
| 24 | t.Fatalf("expected *files.ScopedFs, got %T", u.Fs) |
| 25 | } |
| 26 | if got := u.FullPath("/x"); got != want { |
| 27 | t.Fatalf("FullPath: got %q, want %q", got, want) |
| 28 | } |
| 29 | }) |
| 30 | |
| 31 | t.Run("followExternalSymlinks builds a bare BasePathFs", func(t *testing.T) { |
| 32 | u := &User{Username: "u", Password: "p", Scope: "data"} |
| 33 | if err := u.Clean(base, true); err != nil { |
| 34 | t.Fatal(err) |
| 35 | } |
| 36 | if _, ok := u.Fs.(*afero.BasePathFs); !ok { |
| 37 | t.Fatalf("expected *afero.BasePathFs, got %T", u.Fs) |
| 38 | } |
| 39 | if got := u.FullPath("/x"); got != want { |
| 40 | t.Fatalf("FullPath: got %q, want %q", got, want) |
| 41 | } |
| 42 | }) |
| 43 | } |