mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-28 10:14:13 +00:00
feature(cloudcmd) add ability to set packer with: --packer: "tar" or "zip"
This commit is contained in:
parent
a4d8c19247
commit
689dd037c1
23 changed files with 235 additions and 41 deletions
BIN
test/fixture/pack.zip
Normal file
BIN
test/fixture/pack.zip
Normal file
Binary file not shown.
|
|
@ -14,8 +14,13 @@ const warp = (fn, ...a) => (...b) => fn(...b, ...a);
|
|||
|
||||
const _pullout = promisify(pullout);
|
||||
|
||||
const pathFixture = path.join(__dirname, '..', 'fixture/pack.tar.gz');
|
||||
const fixture = fs.readFileSync(pathFixture);
|
||||
const pathTarFixture = path.join(__dirname, '..', 'fixture/pack.tar.gz');
|
||||
const pathZipFixture = path.join(__dirname, '..', 'fixture/pack.zip');
|
||||
|
||||
const fixture = {
|
||||
tar: fs.readFileSync(pathTarFixture),
|
||||
zip: fs.readFileSync(pathZipFixture),
|
||||
};
|
||||
|
||||
const get = promisify((url, fn) => {
|
||||
fn(null, request(url));
|
||||
|
|
@ -25,12 +30,13 @@ const put = promisify((options, fn) => {
|
|||
fn(null, request.put(options));
|
||||
});
|
||||
|
||||
test('cloudcmd: rest: pack: get', (t) => {
|
||||
before((port, after) => {
|
||||
test('cloudcmd: rest: pack: tar: get', (t) => {
|
||||
const options = {packer: 'tar'};
|
||||
before(options, (port, after) => {
|
||||
get(`http://localhost:${port}/api/v1/pack/fixture/pack`)
|
||||
.then(_pullout)
|
||||
.then((pack) => {
|
||||
t.ok(fixture.compare(pack), 'should pack data');
|
||||
t.ok(fixture.tar.compare(pack), 'should pack data');
|
||||
t.end();
|
||||
after();
|
||||
})
|
||||
|
|
@ -40,8 +46,9 @@ test('cloudcmd: rest: pack: get', (t) => {
|
|||
});
|
||||
});
|
||||
|
||||
test('cloudcmd: rest: pack: put: file', (t) => {
|
||||
before((port, after) => {
|
||||
test('cloudcmd: rest: pack: tar: put: file', (t) => {
|
||||
const options = {packer: 'tar'};
|
||||
before(options, (port, after) => {
|
||||
const name = String(Math.random()) + '.tar.gz';
|
||||
const options = getPackOptions(port, name);
|
||||
|
||||
|
|
@ -51,7 +58,7 @@ test('cloudcmd: rest: pack: put: file', (t) => {
|
|||
const file = fs.readFileSync(__dirname + '/../' + name);
|
||||
|
||||
fs.unlinkSync(`${__dirname}/../${name}`);
|
||||
t.ok(fixture.compare(file), 'should create archive');
|
||||
t.ok(fixture.tar.compare(file), 'should create archive');
|
||||
|
||||
t.end();
|
||||
after();
|
||||
|
|
@ -62,8 +69,9 @@ test('cloudcmd: rest: pack: put: file', (t) => {
|
|||
});
|
||||
});
|
||||
|
||||
test('cloudcmd: rest: pack: put: response', (t) => {
|
||||
before((port, after) => {
|
||||
test('cloudcmd: rest: pack: tar: put: response', (t) => {
|
||||
const options = {packer: 'tar'};
|
||||
before(options, (port, after) => {
|
||||
const name = String(Math.random()) + '.tar.gz';
|
||||
const options = getPackOptions(port, name);
|
||||
|
||||
|
|
@ -83,8 +91,91 @@ test('cloudcmd: rest: pack: put: response', (t) => {
|
|||
});
|
||||
});
|
||||
|
||||
test('cloudcmd: rest: pack: put: error', (t) => {
|
||||
before((port, after) => {
|
||||
test('cloudcmd: rest: pack: tar: put: error', (t) => {
|
||||
const options = {packer: 'tar'};
|
||||
before(options, (port, after) => {
|
||||
const options = getPackOptions(port, 'name', [
|
||||
'not found'
|
||||
]);
|
||||
|
||||
put(options)
|
||||
.then(warp(_pullout, 'string'))
|
||||
.then((msg) => {
|
||||
t.ok(/^ENOENT: no such file or directory/.test(msg), 'should return error');
|
||||
|
||||
t.end();
|
||||
after();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('cloudcmd: rest: pack: zip: get', (t) => {
|
||||
const options = {packer: 'zip'};
|
||||
before(options, (port, after) => {
|
||||
get(`http://localhost:${port}/api/v1/pack/fixture/pack`)
|
||||
.then(_pullout)
|
||||
.then((pack) => {
|
||||
t.ok(fixture.zip.compare(pack), 'should pack data');
|
||||
t.end();
|
||||
after();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('cloudcmd: rest: pack: zip: put: file', (t) => {
|
||||
const options = {packer: 'zip'};
|
||||
before(options, (port, after) => {
|
||||
const name = String(Math.random()) + '.zip';
|
||||
const options = getPackOptions(port, name);
|
||||
|
||||
put(options)
|
||||
.then(warp(_pullout, 'string'))
|
||||
.then(() => {
|
||||
const file = fs.readFileSync(__dirname + '/../' + name);
|
||||
|
||||
fs.unlinkSync(`${__dirname}/../${name}`);
|
||||
t.ok(fixture.zip.compare(file), 'should create archive');
|
||||
|
||||
t.end();
|
||||
after();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('cloudcmd: rest: pack: zip: put: response', (t) => {
|
||||
const options = {packer: 'zip'};
|
||||
before(options, (port, after) => {
|
||||
const name = String(Math.random()) + '.zip';
|
||||
const options = getPackOptions(port, name);
|
||||
|
||||
put(options)
|
||||
.then(warp(_pullout, 'string'))
|
||||
.then((msg) => {
|
||||
t.equal(msg, 'pack: ok("fixture")', 'should return result message');
|
||||
|
||||
fs.unlinkSync(`${__dirname}/../${name}`);
|
||||
|
||||
t.end();
|
||||
after();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('cloudcmd: rest: pack: zip: put: error', (t) => {
|
||||
const options = {packer: 'zip'};
|
||||
before(options, (port, after) => {
|
||||
const options = getPackOptions(port, 'name', [
|
||||
'not found'
|
||||
]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue