Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[api refactor test] Accept --ram in jitsu cloud. Refactor `drones…
…` to be `--drones`. Test all possible argv combinations in the current directory and not for `jitsu cloud`.
  • Loading branch information
indexzero committed Feb 6, 2013
1 parent 7e2c5ab commit 661ab58
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 164 deletions.
34 changes: 19 additions & 15 deletions lib/jitsu/commands/apps.js
Expand Up @@ -801,23 +801,31 @@ apps.setdrones.usage = [
// Views or sets the cloud information for the specified application defaulting
// to the app in the current directory.
//
apps.cloud = function (name, provider, datacenter, drones) {
apps.cloud = function (name, provider, datacenter) {
var providers = ['joyent', 'telefonica'],
args = utile.args(arguments),
callback = args.callback;
callback = args.callback,
drones = jitsu.argv.drones,
ram = jitsu.argv.ram;

//
// If `name` is one of the known providers then curry
// arguments and read package.json from `process.cwd()`.
//
if (providers.indexOf(name) !== -1) {
datacenter = typeof drones !== 'function'
? drones
: provider;
datacenter = provider;
provider = name;
name = null;
}

//
// If `datacenter` was not passed it will
// be the callback.
//
datacenter = typeof datacenter !== 'function'
? datacenter
: null;

//
// Print the cloud information for the app and respond.
//
Expand All @@ -833,18 +841,14 @@ apps.cloud = function (name, provider, datacenter, drones) {
// 3. Start the app in the specified cloud.
//
function setCloud(app) {
drones = typeof drones !== 'function'
? drones
: null;

if (!drones) {
drones = app.maxDrones;
}

drones = drones || app.maxDrones;
ram = ram || app.config.cloud[0].ram;

var cloud = {
datacenter: datacenter,
provider: provider,
drones: drones
drones: drones,
ram: ram
};

if (app.state === 'started') {
Expand Down Expand Up @@ -896,7 +900,7 @@ apps.cloud = function (name, provider, datacenter, drones) {
jitsu.log.help('Try running ' + 'jitsu deploy'.magenta);
return callback({});
}

return provider && datacenter
? setCloud(app)
: viewCloud(app);
Expand Down
244 changes: 95 additions & 149 deletions test/commands/apps-test.js
Expand Up @@ -31,7 +31,85 @@ var fixturesDir = path.join(__dirname, '..', 'fixtures'),
loggedOutFile = path.join(fixturesDir, 'logged-out-jitsuconf')
loggedOutConf = fs.readFileSync(loggedOutFile, 'utf8');

vows.describe('jitsu/commands/apps')/*.addBatch({
//
// Test macro which calls `.addBatch` for every possible
// argv combination of `--ram` and `--drones`.
//
function shouldAcceptAllCloudOptions(suite, command) {
['with no options',
'--drones 2',
'--ram 512',
'--drones 2 --ram 512'
].forEach(function (argv) {
var drones = /--drones\s(\d{1})/.exec(argv),
ram = /--ram\s(\d{3})/.exec(argv),
context = {},
options;

context[argv] = {};

options = {
drones: drones ? parseInt(drones[1], 10) : 1,
ram: ram ? parseInt(ram[1], 10) : 256
};

context[argv][command] = shouldNodejitsuOk(
function setup() {
jitsu.argv.drones = options.drones;
jitsu.argv.ram = options.ram;

//
// Accomodate for `cloud joyent us-east-1`.
//
if (jitsu.argv._[1] === 'joyent') {
useAppFixture();
}

nock('https://api.mockjitsu.com')
.get('/apps/tester/example-app')
.reply(200, {
app: {
name: 'example-app',
maxDrones: options.drones,
subdomain: 'example-app',
config: {
cloud: [{
provider: 'joyent',
datacenter: 'us-east-1',
drones: options.drones,
ram: 256
}]
}
}
}, { 'x-powered-by': 'Nodejitsu' })
.get('/endpoints')
.reply(200, endpoints, { 'x-powered-by': 'Nodejitsu' })
.post('/apps/tester/example-app/cloud', [{
datacenter: 'us-east-1',
provider: 'joyent',
drones: options.drones,
ram: options.ram
}]).reply(200, {
datacenter: 'us-east-1',
provider: 'joyent',
drones: options.drones,
ram: options.ram
}, { 'x-powered-by': 'Nodejitsu' })
},
'should show cloud info',
function assertion (err, ignore) {
process.chdir(mainDirectory);
assert.isNull(err);
}
);

suite.addBatch(context);
});

return suite;
}

var suite = vows.describe('jitsu/commands/apps').addBatch({
'apps list': shouldNodejitsuOk(function setup() {
nock('https://api.mockjitsu.com')
.get('/apps/tester')
Expand Down Expand Up @@ -557,7 +635,7 @@ vows.describe('jitsu/commands/apps')/*.addBatch({
fs.writeFileSync(loggedOutFile, loggedOutConf, 'utf8');
}
)
})*/.addBatch({
}).addBatch({
'cloud example-app': shouldNodejitsuOk(
function setup() {
nock('https://api.mockjitsu.com')
Expand Down Expand Up @@ -605,29 +683,6 @@ vows.describe('jitsu/commands/apps')/*.addBatch({
assert.isNull(err);
}
)
}).addBatch({
'cloud example-app joyent': shouldNodejitsuOk(
function setup() {
nock('https://api.mockjitsu.com')
.get('/apps/tester/example-app')
.reply(200, {
app: {
config: {
cloud: [{
provider: 'joyent',
datacenter: 'us-east-1',
drones: 2
}]
}
}
}, { 'x-powered-by': 'Nodejitsu' });
},
'should show cloud info',
function assertion (err, ignore) {
process.chdir(mainDirectory);
assert.isNull(err);
}
)
}).addBatch({
'cloud joyent': shouldNodejitsuOk(
function setup() {
Expand All @@ -654,86 +709,13 @@ vows.describe('jitsu/commands/apps')/*.addBatch({
}
)
}).addBatch({
'cloud example-app joyent us-east-1': shouldNodejitsuOk(
function setup() {
nock('https://api.mockjitsu.com')
.get('/apps/tester/example-app')
.reply(200, {
app: {
name: 'example-app',
maxDrones: 2,
subdomain: 'example-app',
config: {
cloud: [{
provider: 'joyent',
datacenter: 'us-east-1',
drones: 2
}]
}
}
}, { 'x-powered-by': 'Nodejitsu' })
.get('/endpoints')
.reply(200, endpoints, { 'x-powered-by': 'Nodejitsu' })
.post('/apps/tester/example-app/cloud', [{
datacenter: 'us-east-1',
provider: 'joyent',
drones: 2
}]).reply(200, cloud, { 'x-powered-by': 'Nodejitsu' })
},
'should show cloud info',
function assertion (err, ignore) {
process.chdir(mainDirectory);
assert.isNull(err);
}
)
}).addBatch({
'cloud example-app joyent us-east-1 1': shouldNodejitsuOk(
function setup() {
cloud.drones = 1; // Fit to the arguments and test
nock('https://api.mockjitsu.com')
.get('/apps/tester/example-app')
.reply(200, {
app: {
name: 'example-app',
maxDrones: 2,
subdomain: 'example-app',
config: {
cloud: [{
provider: 'joyent',
datacenter: 'us-east-1',
drones: 2
}]
}
}
}, { 'x-powered-by': 'Nodejitsu' })
.get('/endpoints')
.reply(200, endpoints, { 'x-powered-by': 'Nodejitsu' })
.post('/apps/tester/example-app/cloud', [{
datacenter: 'us-east-1',
provider: 'joyent',
drones: '1'
}]).reply(200, cloud, { 'x-powered-by': 'Nodejitsu' })
},
'should show cloud info',
function assertion (err, ignore) {
process.chdir(mainDirectory);
assert.isNull(err);
// restore value
cloud.drones = 2;
}
)
}).addBatch({
'cloud joyent us-east-1': shouldNodejitsuOk(
'cloud example-app joyent': shouldNodejitsuOk(
function setup() {
useAppFixture();

nock('https://api.mockjitsu.com')
.get('/apps/tester/example-app')
.reply(200, {
app: {
name: 'example-app',
maxDrones: 2,
subdomain: 'example-app',
config: {
cloud: [{
provider: 'joyent',
Expand All @@ -742,54 +724,7 @@ vows.describe('jitsu/commands/apps')/*.addBatch({
}]
}
}
}, { 'x-powered-by': 'Nodejitsu' })
.get('/endpoints')
.reply(200, endpoints, { 'x-powered-by': 'Nodejitsu' })
.post('/apps/tester/example-app/cloud', [{
datacenter: 'us-east-1',
provider: 'joyent',
drones: 2
}]).reply(200, cloud, { 'x-powered-by': 'Nodejitsu' })
},
'should show cloud info',
function assertion (err, ignore) {
process.chdir(mainDirectory);
assert.isNull(err);
}
)
}).addBatch({
'cloud joyent us-east-1 2': shouldNodejitsuOk(
function setup() {
useAppFixture();

nock('https://api.mockjitsu.com')
.get('/apps/tester/example-app')
.reply(200, {
app: {
name: 'example-app',
maxDrones: 2,
subdomain: 'example-app',
config: {
cloud: [{
provider: 'joyent',
datacenter: 'us-east-1',
drones: 1
}]
}
}
}, { 'x-powered-by': 'Nodejitsu' })
.get('/endpoints')
.reply(200, endpoints, { 'x-powered-by': 'Nodejitsu' })
.post('/apps/tester/example-app/cloud', [{
datacenter: 'us-east-1',
provider: 'joyent',
drones: 2
}]).reply(200, cloud, { 'x-powered-by': 'Nodejitsu' })
},
'should show cloud info',
function assertion (err, ignore) {
process.chdir(mainDirectory);
assert.isNull(err);
}, { 'x-powered-by': 'Nodejitsu' });
}
)
}).addBatch({
Expand Down Expand Up @@ -820,7 +755,18 @@ vows.describe('jitsu/commands/apps')/*.addBatch({
function assertion (err, ignore) {
process.chdir(mainDirectory);
assert.ok(!!err);

}
)
}).export(module);
});

shouldAcceptAllCloudOptions(
suite,
'cloud example-app joyent us-east-1'
);

shouldAcceptAllCloudOptions(
suite,
'cloud joyent us-east-1'
);

suite.export(module);

0 comments on commit 661ab58

Please sign in to comment.