You can swap real storage drivers with FakeDisk instances to facilitate testing. When you call .fake(service), any subsequent calls to .use(service) will return the fake instance instead of the real one.
Requirement: You must include a fakes property in your DriveManagerOptions when initializing the manager, otherwise calling .fake() will throw a RuntimeException.
To return to the real storage implementation after a test, call .restore(service).
// 1. Setup manager with fakes config
const drive = new DriveManager({
default: 'local',
services: { local: () => localDriver },
fakes: { /* fake driver settings */ }
})
// 2. Deploy the fake
const fakeDisk = drive.fake('local')
// 3. Subsequent calls to .use() return the fake
const disk = drive.use('local') // returns FakeDisk
// 4. Restore the real disk
drive.restore('local')
const realDisk = drive.use('local') // returns real Disk