mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-18 00:47:01 +00:00
test(rest) cloudcmd -> rest
This commit is contained in:
parent
0ac7aabf9a
commit
9e11f02a45
3 changed files with 45 additions and 6 deletions
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
const http = require('http');
|
||||
|
||||
const express = require('express');
|
||||
|
|
|
|||
33
test/rest/fs.js
Normal file
33
test/rest/fs.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
'use strict';
|
||||
|
||||
const test = require('tape');
|
||||
const promisify = require('es6-promisify');
|
||||
const pullout = require('pullout');
|
||||
const request = require('request');
|
||||
|
||||
const before = require('../before');
|
||||
|
||||
const warp = (fn, ...a) => (...b) => fn(...b, ...a);
|
||||
|
||||
const _pullout = promisify(pullout);
|
||||
|
||||
const get = promisify((url, fn) => {
|
||||
fn(null, request(url));
|
||||
});
|
||||
|
||||
test('cloudcmd: rest: fs: path', (t) => {
|
||||
before((port, after) => {
|
||||
get(`http://localhost:${port}/api/v1/fs`)
|
||||
.then(warp(_pullout, 'string'))
|
||||
.then(JSON.parse)
|
||||
.then((dir) => {
|
||||
t.equal('/', dir.path, 'should dir path be "/"');
|
||||
t.end();
|
||||
after();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -1,16 +1,22 @@
|
|||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const test = require('tape');
|
||||
const promisify = require('es6-promisify');
|
||||
const pullout = require('pullout');
|
||||
const request = require('request');
|
||||
|
||||
const before = require('./before');
|
||||
const before = require('../before');
|
||||
|
||||
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 get = promisify((url, fn) => {
|
||||
fn(null, request(url));
|
||||
});
|
||||
|
|
@ -40,7 +46,6 @@ test('cloudcmd: rest: pack: get', (t) => {
|
|||
get(`http://localhost:${port}/api/v1/pack/fixture/pack`)
|
||||
.then(_pullout)
|
||||
.then((pack) => {
|
||||
const fixture = fs.readFileSync(__dirname + '/fixture/pack.tar.gz');
|
||||
t.ok(fixture.compare(pack), 'should pack data');
|
||||
t.end();
|
||||
after();
|
||||
|
|
@ -59,10 +64,9 @@ test('cloudcmd: rest: pack: put: file', (t) => {
|
|||
put(options)
|
||||
.then(warp(_pullout, 'string'))
|
||||
.then(() => {
|
||||
const file = fs.readFileSync(__dirname + '/' + name);
|
||||
const fixture = fs.readFileSync(__dirname + '/fixture/pack.tar.gz');
|
||||
const file = fs.readFileSync(__dirname + '/../' + name);
|
||||
|
||||
fs.unlinkSync(`${__dirname}/${name}`);
|
||||
fs.unlinkSync(`${__dirname}/../${name}`);
|
||||
t.ok(fixture.compare(file), 'should create archive');
|
||||
|
||||
t.end();
|
||||
|
|
@ -84,7 +88,7 @@ test('cloudcmd: rest: pack: put: response', (t) => {
|
|||
.then((msg) => {
|
||||
t.equal(msg, 'pack: ok("fixture")', 'should return result message');
|
||||
|
||||
fs.unlinkSync(`${__dirname}/${name}`);
|
||||
fs.unlinkSync(`${__dirname}/../${name}`);
|
||||
|
||||
t.end();
|
||||
after();
|
||||
Loading…
Add table
Add a link
Reference in a new issue