Fix #605: add migration tests for Filer 0.43
This commit is contained in:
parent
b7312bfa1e
commit
f738cbc17d
|
@ -22,6 +22,7 @@
|
||||||
"lint": "eslint src tests",
|
"lint": "eslint src tests",
|
||||||
"lint:fix": "eslint --fix src tests",
|
"lint:fix": "eslint --fix src tests",
|
||||||
"test:manual": "parcel tests/index.html --out-dir tests/dist",
|
"test:manual": "parcel tests/index.html --out-dir tests/dist",
|
||||||
|
"test:migrations": "mocha tests/filesystems/migrations",
|
||||||
"pretest": "npm run lint",
|
"pretest": "npm run lint",
|
||||||
"test": "npm run karma-mocha",
|
"test": "npm run karma-mocha",
|
||||||
"prebuild": "parcel build --global Filer src/index.js --no-minify --out-file filer.js",
|
"prebuild": "parcel build --global Filer src/index.js --no-minify --out-file filer.js",
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
The following images are JSON filesystem images created with
|
||||||
|
`tools/fs-image.js`, and named with the filesystem dir used
|
||||||
|
as the source of the image, and the version of Filer used to
|
||||||
|
generate them:
|
||||||
|
|
||||||
|
1. `tiny-fs.0.43.json` was created from `tests/filesystem/tiny-fs/` with https://github.com/filerjs/filer/blob/d66114e20c7f0235698d9933dbd90217ba86fa4e/dist/filer.min.js
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
{"00000000-0000-0000-0000-000000000000":{"id":"00000000-0000-0000-0000-000000000000","mode":"META","atime":1545098425757,"ctime":1545098425757,"mtime":1545098425757,"rnode":"A63180BA-9BCE-4245-86E8-8613726587CA"},"A63180BA-9BCE-4245-86E8-8613726587CA":{"id":"A63180BA-9BCE-4245-86E8-8613726587CA","mode":"DIRECTORY","size":0,"atime":1545098425770,"ctime":1545098425770,"mtime":1545098425770,"flags":[],"xattrs":{},"nlinks":1,"version":0,"nblocks":1,"data":"3A41160B-1F39-4162-85BD-473F16ABF35F"},"3A41160B-1F39-4162-85BD-473F16ABF35F":{"dir":{"id":"E1634C88-337D-4D1E-9155-81B099BC7E7C","type":"DIRECTORY"},"file.txt":{"id":"DD338D5C-34FF-4AF7-AFBB-C01E8214125F","type":"FILE"}},"E1634C88-337D-4D1E-9155-81B099BC7E7C":{"id":"E1634C88-337D-4D1E-9155-81B099BC7E7C","mode":"DIRECTORY","size":0,"atime":1545098425778,"ctime":1545098425778,"mtime":1545098425778,"flags":[],"xattrs":{},"nlinks":1,"version":0,"nblocks":1,"data":"C8BB5894-9B0C-4CDC-B014-3944FB40DA77"},"C8BB5894-9B0C-4CDC-B014-3944FB40DA77":{"file2.txt":{"id":"EEB56FEC-DABE-48BF-88A5-B9F37723A0BC","type":"FILE"}},"DD338D5C-34FF-4AF7-AFBB-C01E8214125F":{"id":"DD338D5C-34FF-4AF7-AFBB-C01E8214125F","mode":"FILE","size":16,"atime":1545098327877.7542,"ctime":1545098313562.6824,"mtime":1545098313562.6824,"flags":[],"xattrs":{},"nlinks":1,"version":1,"nblocks":1,"data":"BDEE2339-6992-4D8F-AFAA-81813C30592C"},"BDEE2339-6992-4D8F-AFAA-81813C30592C":{"type":"Buffer","data":[84,104,105,115,32,105,115,32,97,32,102,105,108,101,46,10]},"EEB56FEC-DABE-48BF-88A5-B9F37723A0BC":{"id":"EEB56FEC-DABE-48BF-88A5-B9F37723A0BC","mode":"FILE","size":23,"atime":1545098327877.7542,"ctime":1545098313562.6824,"mtime":1545098313562.6824,"flags":[],"xattrs":{},"nlinks":1,"version":1,"nblocks":1,"data":"62262B53-32BC-43F6-983B-4127302C2483"},"62262B53-32BC-43F6-983B-4127302C2483":{"type":"Buffer","data":[84,104,105,115,32,105,115,32,97,32,115,101,99,111,110,100,32,102,105,108,101,46,10]}}
|
|
@ -0,0 +1,92 @@
|
||||||
|
const expect = require('chai').expect;
|
||||||
|
const Filer = require('../../../src');
|
||||||
|
const SerializableMemoryProvider = require('../../lib/serializable-memory-provider');
|
||||||
|
const nodeFs = require('fs');
|
||||||
|
const nodePath = require('path');
|
||||||
|
|
||||||
|
describe('Migration tests from Filer 0.43 to current', () => {
|
||||||
|
|
||||||
|
let filerFs;
|
||||||
|
|
||||||
|
before(done => {
|
||||||
|
// Let the provider parse the JSON
|
||||||
|
const imagePath = nodePath.resolve(__dirname, '../images/tiny-fs.0.43.json');
|
||||||
|
nodeFs.readFile(imagePath, 'utf8', (err, data) => {
|
||||||
|
if(err) throw err;
|
||||||
|
|
||||||
|
new Filer.FileSystem({
|
||||||
|
provider: new SerializableMemoryProvider('0.43', data)
|
||||||
|
}, (err, fs) => {
|
||||||
|
if(err) throw err;
|
||||||
|
|
||||||
|
filerFs = fs;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a root directory', done => {
|
||||||
|
filerFs.stat('/', (err, stats) => {
|
||||||
|
if(err) throw err;
|
||||||
|
|
||||||
|
expect(stats).to.be.an('object');
|
||||||
|
expect(stats.isDirectory()).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have expected entries in root dir', done => {
|
||||||
|
filerFs.readdir('/', (err, entries) => {
|
||||||
|
if(err) throw err;
|
||||||
|
|
||||||
|
expect(entries).to.be.an('array');
|
||||||
|
expect(entries.length).to.equal(3);
|
||||||
|
expect(entries).to.contain('README.md');
|
||||||
|
expect(entries).to.contain('file.txt');
|
||||||
|
expect(entries).to.contain('dir');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have correct contents for /file.txt (read as String)', done => {
|
||||||
|
const fileTxtPath = nodePath.resolve(__dirname, '../tiny-fs/file.txt');
|
||||||
|
|
||||||
|
nodeFs.readFile(fileTxtPath, 'utf8', (err, nodeData) => {
|
||||||
|
if(err) throw err;
|
||||||
|
|
||||||
|
filerFs.readFile('/file.txt', 'utf8', (err, filerData) => {
|
||||||
|
if(err) throw err;
|
||||||
|
|
||||||
|
expect(nodeData).to.equal(filerData);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have expected entries in /dir', done => {
|
||||||
|
filerFs.readdir('/dir', (err, entries) => {
|
||||||
|
if(err) throw err;
|
||||||
|
|
||||||
|
expect(entries).to.be.an('array');
|
||||||
|
expect(entries.length).to.equal(1);
|
||||||
|
expect(entries).to.contain('file2.txt');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have correct contents for /dir/file2.txt (read as Buffer)', done => {
|
||||||
|
const file2TxtPath = nodePath.resolve(__dirname, '../tiny-fs/dir/file2.txt');
|
||||||
|
|
||||||
|
nodeFs.readFile(file2TxtPath, null, (err, nodeData) => {
|
||||||
|
if(err) throw err;
|
||||||
|
|
||||||
|
filerFs.readFile('/dir/file.txt', null, (err, filerData) => {
|
||||||
|
if(err) throw err;
|
||||||
|
|
||||||
|
expect(nodeData).to.equal(filerData);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
|
@ -0,0 +1 @@
|
||||||
|
This is a second file.
|
|
@ -0,0 +1 @@
|
||||||
|
This is a file.
|
Loading…
Reference in New Issue