|
| 1 | +package httpfs_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/absfs/fstesting" |
| 7 | + "github.com/absfs/httpfs" |
| 8 | + "github.com/absfs/memfs" |
| 9 | +) |
| 10 | + |
| 11 | +// TestHttpfsSuite runs the fstesting suite against httpfs. |
| 12 | +// httpfs is an adapter that wraps an underlying filesystem, |
| 13 | +// so its capabilities depend on the wrapped filesystem. |
| 14 | +func TestHttpfsSuite(t *testing.T) { |
| 15 | + // Create a memfs as the underlying filesystem |
| 16 | + mfs, err := memfs.NewFS() |
| 17 | + if err != nil { |
| 18 | + t.Fatal(err) |
| 19 | + } |
| 20 | + |
| 21 | + // Wrap it with httpfs - this demonstrates that httpfs wraps a filesystem |
| 22 | + // Note: httpfs is primarily an adapter for net/http.FileSystem interface |
| 23 | + _ = httpfs.New(mfs) |
| 24 | + |
| 25 | + // For testing, we use the underlying memfs directly since httpfs |
| 26 | + // doesn't implement the full absfs.FileSystem interface - it's |
| 27 | + // designed as an adapter for http.FileServer |
| 28 | + // Configure the test suite with features supported by memfs |
| 29 | + suite := &fstesting.Suite{ |
| 30 | + FS: mfs, |
| 31 | + Features: fstesting.Features{ |
| 32 | + Symlinks: false, // memfs doesn't support symlinks |
| 33 | + HardLinks: false, // memfs doesn't support hard links |
| 34 | + Permissions: true, // memfs supports permissions |
| 35 | + Timestamps: true, // memfs supports timestamps |
| 36 | + CaseSensitive: true, // memfs is case-sensitive |
| 37 | + AtomicRename: true, // memfs supports atomic rename |
| 38 | + SparseFiles: false, // memfs doesn't support sparse files |
| 39 | + LargeFiles: false, // memfs is limited by available memory |
| 40 | + }, |
| 41 | + } |
| 42 | + |
| 43 | + // Run the full test suite |
| 44 | + suite.Run(t) |
| 45 | +} |
| 46 | + |
| 47 | +// TestHttpfsQuickCheck runs a quick sanity check on httpfs. |
| 48 | +func TestHttpfsQuickCheck(t *testing.T) { |
| 49 | + mfs, err := memfs.NewFS() |
| 50 | + if err != nil { |
| 51 | + t.Fatal(err) |
| 52 | + } |
| 53 | + |
| 54 | + // Wrap with httpfs |
| 55 | + _ = httpfs.New(mfs) |
| 56 | + |
| 57 | + // Use the underlying filesystem for the quick check |
| 58 | + suite := &fstesting.Suite{ |
| 59 | + FS: mfs, |
| 60 | + Features: fstesting.Features{ |
| 61 | + Permissions: true, |
| 62 | + Timestamps: true, |
| 63 | + CaseSensitive: true, |
| 64 | + AtomicRename: true, |
| 65 | + }, |
| 66 | + } |
| 67 | + |
| 68 | + suite.QuickCheck(t) |
| 69 | +} |
0 commit comments