(t *testing.T)
| 26 | ) |
| 27 | |
| 28 | func TestFileStoreBasics(t *testing.T) { |
| 29 | tempDir := t.TempDir() |
| 30 | |
| 31 | // Creation |
| 32 | tempStore, err := New(tempDir, 0, 0) |
| 33 | assert.NilError(t, err, "temporary store creation should succeed") |
| 34 | |
| 35 | // Lock acquisition |
| 36 | err = tempStore.Lock() |
| 37 | assert.NilError(t, err, "acquiring a lock should succeed") |
| 38 | err = tempStore.Release() |
| 39 | assert.NilError(t, err, "releasing a lock should succeed") |
| 40 | |
| 41 | // Non-existent keys |
| 42 | _ = tempStore.Lock() |
| 43 | defer tempStore.Release() |
| 44 | |
| 45 | _, err = tempStore.Get("nonexistent") |
| 46 | assert.ErrorIs(t, err, ErrNotFound, "getting a non existent key should ErrNotFound") |
| 47 | |
| 48 | err = tempStore.Delete("nonexistent") |
| 49 | assert.ErrorIs(t, err, ErrNotFound, "deleting a non existent key should ErrNotFound") |
| 50 | |
| 51 | _, err = tempStore.List("nonexistent") |
| 52 | assert.ErrorIs(t, err, ErrNotFound, "listing a non existent key should ErrNotFound") |
| 53 | |
| 54 | doesExist, err := tempStore.Exists("nonexistent") |
| 55 | assert.NilError(t, err, "exist should not error") |
| 56 | assert.Assert(t, !doesExist, "should not exist") |
| 57 | |
| 58 | // Listing empty store |
| 59 | result, err := tempStore.List() |
| 60 | assert.NilError(t, err, "listing store root should succeed") |
| 61 | assert.Assert(t, len(result) == 0, "list empty store return zero length slice") |
| 62 | |
| 63 | // Invalid keys |
| 64 | _, err = tempStore.Get("..") |
| 65 | assert.ErrorIs(t, err, filesystem.ErrInvalidPath, "unsupported characters or patterns should return filesystem.ErrInvalidPath") |
| 66 | |
| 67 | err = tempStore.Set([]byte("foo"), "..") |
| 68 | assert.ErrorIs(t, err, filesystem.ErrInvalidPath, "unsupported characters or patterns should return filesystem.ErrInvalidPath") |
| 69 | |
| 70 | err = tempStore.Delete("..") |
| 71 | assert.ErrorIs(t, err, filesystem.ErrInvalidPath, "unsupported characters or patterns should return filesystem.ErrInvalidPath") |
| 72 | |
| 73 | _, err = tempStore.List("..") |
| 74 | assert.ErrorIs(t, err, filesystem.ErrInvalidPath, "unsupported characters or patterns should return filesystem.ErrInvalidPath") |
| 75 | |
| 76 | // Writing, reading, listing, deleting |
| 77 | err = tempStore.Set([]byte("foo"), "something") |
| 78 | assert.NilError(t, err, "write should be successful") |
| 79 | |
| 80 | doesExist, err = tempStore.Exists("something") |
| 81 | assert.NilError(t, err, "exist should not error") |
| 82 | assert.Assert(t, doesExist, "should exist") |
| 83 | |
| 84 | data, err := tempStore.Get("something") |
| 85 | assert.NilError(t, err, "read should be successful") |
nothing calls this directly
no test coverage detected
searching dependent graphs…