Skip to content

Commit

Permalink
chore(tests): use args[n][m] instead of getCall(n).args[m] (#630)
Browse files Browse the repository at this point in the history
  • Loading branch information
vikaspotluri123 authored and acburdine committed Feb 7, 2018
1 parent 9493abd commit 5ae264f
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 106 deletions.
14 changes: 7 additions & 7 deletions extensions/nginx/test/acme-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ describe('Unit: Extensions > Nginx > Acme', function () {
expect(emptyStub.calledOnce).to.be.true;
expect(gotStub.calledOnce).to.be.true;
expect(downloadStub.calledOnce).to.be.true;
expect(downloadStub.getCall(0).args[0]).to.equal(dwUrl);
expect(sudoStub.getCall(0).args[0]).to.match(/mkdir -p/);
expect(sudoStub.getCall(1).args[0]).to.match(/acme\.sh --install/);
expect(downloadStub.args[0][0]).to.equal(dwUrl);
expect(sudoStub.args[0][0]).to.match(/mkdir -p/);
expect(sudoStub.args[1][0]).to.match(/acme\.sh --install/);
});
});

Expand Down Expand Up @@ -175,12 +175,12 @@ describe('Unit: Extensions > Nginx > Acme', function () {

return acme.generate({sudo: sudoStub}, 'domain', 'root', '[email protected]').then(() => {
expect(sudoStub.calledOnce).to.be.true;
expect(sudoStub.getCall(0).args[0]).to.match(expectedSudo);
expect(sudoStub.args[0][0]).to.match(expectedSudo);

return acme.generate({sudo: sudoStub}, 'domain', 'root', '[email protected]', true);
}).then(() => {
expect(sudoStub.calledTwice).to.be.true;
expect(sudoStub.getCall(1).args[0]).to.match(/--issue .{0,} --staging/);
expect(sudoStub.args[1][0]).to.match(/--issue .{0,} --staging/);
});
});

Expand Down Expand Up @@ -232,7 +232,7 @@ describe('Unit: Extensions > Nginx > Acme', function () {

return acme.remove('ghost.org', {sudo: sudoStub}).then(() => {
expect(sudoStub.calledOnce).to.be.true;
expect(sudoStub.getCall(0).args[0]).to.equal(
expect(sudoStub.args[0][0]).to.equal(
'/etc/letsencrypt/acme.sh --remove --home /etc/letsencrypt --domain ghost.org'
)
});
Expand All @@ -248,7 +248,7 @@ describe('Unit: Extensions > Nginx > Acme', function () {

return acme.remove('ghost.org', {sudo: sudoStub}, '/home/ghost/.acme.sh').then(() => {
expect(sudoStub.calledOnce).to.be.true;
expect(sudoStub.getCall(0).args[0]).to.equal(
expect(sudoStub.args[0][0]).to.equal(
'/home/ghost/.acme.sh/acme.sh --remove --home /home/ghost/.acme.sh --domain ghost.org'
)
});
Expand Down
58 changes: 29 additions & 29 deletions extensions/nginx/test/extension-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ describe('Unit: Extensions > Nginx', function () {
ext.setup(cmd, {});

expect(asStub.calledTwice).to.be.true;
expect(asStub.getCall(0).args[0]).to.equal('nginx');
expect(asStub.getCall(1).args[0]).to.equal('ssl');
expect(asStub.getCall(1).args[2]).to.equal('nginx');
expect(asStub.args[0][0]).to.equal('nginx');
expect(asStub.args[1][0]).to.equal('ssl');
expect(asStub.args[1][2]).to.equal('nginx');
});
});

Expand Down Expand Up @@ -139,7 +139,7 @@ describe('Unit: Extensions > Nginx', function () {

expect(ext.isSupported.calledOnce).to.be.true;
expect(ext.ui.log.calledOnce).to.be.true;
expect(ext.ui.log.getCall(0).args[0]).to.match(/not installed/);
expect(ext.ui.log.args[0][0]).to.match(/not installed/);
expect(task.skip.calledOnce).to.be.true;
});

Expand All @@ -151,7 +151,7 @@ describe('Unit: Extensions > Nginx', function () {

expect(get.calledOnce).to.be.true;
expect(log.calledOnce).to.be.true;
expect(log.getCall(0).args[0]).to.match(/contains a port/);
expect(log.args[0][0]).to.match(/contains a port/);
expect(task.skip.calledOnce).to.be.true;
});

Expand All @@ -165,9 +165,9 @@ describe('Unit: Extensions > Nginx', function () {
const log = ext.ui.log;

expect(existsStub.calledOnce).to.be.true;
expect(existsStub.getCall(0).args[0]).to.equal(expectedFile);
expect(existsStub.args[0][0]).to.equal(expectedFile);
expect(log.calledOnce).to.be.true;
expect(log.getCall(0).args[0]).to.match(/configuration already found/);
expect(log.args[0][0]).to.match(/configuration already found/);
expect(task.skip.calledOnce).to.be.true;
});

Expand Down Expand Up @@ -197,9 +197,9 @@ describe('Unit: Extensions > Nginx', function () {
return ext.setupNginx(null, ctx, task).then(() => {
expect(templateStub.calledOnce).to.be.true;
expect(loadStub.calledOnce).to.be.true;
expect(loadStub.getCall(0).args[0]).to.deep.equal(expectedConfig);
expect(loadStub.args[0][0]).to.deep.equal(expectedConfig);
expect(sudo.calledOnce).to.be.true;
expect(sudo.getCall(0).args[0]).to.match(lnExp);
expect(sudo.args[0][0]).to.match(lnExp);
expect(ext.restartNginx.calledOnce).to.be.true;

// Testing handling of subdirectory installations
Expand All @@ -216,7 +216,7 @@ describe('Unit: Extensions > Nginx', function () {

return ext.setupNginx(null, ctx, task).then(() => {
expect(loadStub.calledOnce).to.be.true;
expect(loadStub.getCall(0).args[0]).to.deep.equal(expectedConfig);
expect(loadStub.args[0][0]).to.deep.equal(expectedConfig);
});
});
});
Expand Down Expand Up @@ -244,7 +244,7 @@ describe('Unit: Extensions > Nginx', function () {

expect(stubs.es.calledOnce).to.be.false;
expect(ext.ui.log.calledOnce).to.be.true;
expect(ext.ui.log.getCall(0).args[0]).to.match(/SSL certs cannot be generated for IP addresses/);
expect(ext.ui.log.args[0][0]).to.match(/SSL certs cannot be generated for IP addresses/);
expect(stubs.skip.calledOnce).to.be.true;
});

Expand All @@ -256,9 +256,9 @@ describe('Unit: Extensions > Nginx', function () {
const log = ext.ui.log;

expect(existsStub.calledOnce).to.be.true;
expect(existsStub.getCall(0).args[0]).to.equal(sslFile);
expect(existsStub.args[0][0]).to.equal(sslFile);
expect(log.calledOnce).to.be.true;
expect(log.getCall(0).args[0]).to.match(/SSL has /);
expect(log.args[0][0]).to.match(/SSL has /);
expect(stubs.skip.calledOnce).to.be.true;
});

Expand All @@ -267,7 +267,7 @@ describe('Unit: Extensions > Nginx', function () {

expect(stubs.es.calledOnce).to.be.true;
expect(ext.ui.log.calledOnce).to.be.true;
expect(ext.ui.log.getCall(0).args[0]).to.match(/SSL email must be provided/);
expect(ext.ui.log.args[0][0]).to.match(/SSL email must be provided/);
expect(stubs.skip.calledOnce).to.be.true;
});

Expand All @@ -287,7 +287,7 @@ describe('Unit: Extensions > Nginx', function () {

expect(stubs.es.calledTwice, '1').to.be.true;
expect(ext.ui.log.calledOnce, '2').to.be.true;
expect(ext.ui.log.getCall(0).args[0]).to.match(/Nginx config file/);
expect(ext.ui.log.args[0][0]).to.match(/Nginx config file/);
expect(stubs.skip.calledOnce, '4').to.be.true;
});
});
Expand All @@ -307,7 +307,7 @@ describe('Unit: Extensions > Nginx', function () {
expect(task.skip.called, 'getTasks: task.skip').to.be.false;
expect(ext.ui.log.called, 'getTasks: ui.log').to.be.false;
expect(ext.ui.listr.calledOnce, 'getTasks: ui.listr').to.be.true;
return ext.ui.listr.getCall(0).args[0];
return ext.ui.listr.args[0][0];
}

beforeEach(function () {
Expand Down Expand Up @@ -349,7 +349,7 @@ describe('Unit: Extensions > Nginx', function () {

return tasks[0].task(ctx).then(() => {
expect(log.called).to.be.true;
expect(log.getCall(0).args[0]).to.match(/domain isn't set up correctly/);
expect(log.args[0][0]).to.match(/domain isn't set up correctly/);
expect(ctx.dnsfail).to.be.true;

DNS.code = 'PEACHESARETASTY';
Expand Down Expand Up @@ -466,7 +466,7 @@ describe('Unit: Extensions > Nginx', function () {

return tasks[4].task().then(() => {
expect(ext.ui.sudo.calledOnce).to.be.true;
expect(ext.ui.sudo.getCall(0).args[0]).to.match(/openssl dhparam/);
expect(ext.ui.sudo.args[0][0]).to.match(/openssl dhparam/);
});
});

Expand Down Expand Up @@ -496,7 +496,7 @@ describe('Unit: Extensions > Nginx', function () {

return tasks[5].task().then(() => {
expect(ext.ui.sudo.calledOnce).to.be.true;
expect(ext.ui.sudo.getCall(0).args[0]).to.match(expectedSudo);
expect(ext.ui.sudo.args[0][0]).to.match(expectedSudo);
});
});

Expand Down Expand Up @@ -539,9 +539,9 @@ describe('Unit: Extensions > Nginx', function () {
return tasks[6].task(ctx).then(() => {
expect(stubs.template.calledTwice).to.be.true;
expect(stubs.templatify.calledOnce).to.be.true;
expect(stubs.templatify.getCall(0).args[0]).to.deep.equal(expectedTemplate);
expect(stubs.templatify.args[0][0]).to.deep.equal(expectedTemplate);
expect(ext.ui.sudo.calledOnce).to.be.true;
expect(ext.ui.sudo.getCall(0).args[0]).to.match(expectedSudo);
expect(ext.ui.sudo.args[0][0]).to.match(expectedSudo);
});
});

Expand All @@ -554,7 +554,7 @@ describe('Unit: Extensions > Nginx', function () {
return tasks[6].task(ctx).then(() => {
expect(stubs.template.calledTwice).to.be.true;
expect(stubs.templatify.calledOnce).to.be.true;
expect(stubs.templatify.getCall(0).args[0]).to.deep.equal(expectedTemplate);
expect(stubs.templatify.args[0][0]).to.deep.equal(expectedTemplate);
});
});
});
Expand Down Expand Up @@ -590,8 +590,8 @@ describe('Unit: Extensions > Nginx', function () {

return ext.uninstall(instance).then(() => {
expect(ext.ui.sudo.calledTwice).to.be.true;
expect(ext.ui.sudo.getCall(0).args[0]).to.match(sudoExp);
expect(ext.ui.sudo.getCall(1).args[0]).to.match(sudoExp);
expect(ext.ui.sudo.args[0][0]).to.match(sudoExp);
expect(ext.ui.sudo.args[1][0]).to.match(sudoExp);
expect(ext.restartNginx.calledOnce).to.be.true;
});
});
Expand All @@ -603,8 +603,8 @@ describe('Unit: Extensions > Nginx', function () {

return ext.uninstall(instance).then(() => {
expect(ext.ui.sudo.calledTwice).to.be.true;
expect(ext.ui.sudo.getCall(0).args[0]).to.match(sudoExp);
expect(ext.ui.sudo.getCall(1).args[0]).to.match(sudoExp);
expect(ext.ui.sudo.args[0][0]).to.match(sudoExp);
expect(ext.ui.sudo.args[1][0]).to.match(sudoExp);
expect(ext.restartNginx.calledOnce).to.be.true;
});
});
Expand Down Expand Up @@ -641,7 +641,7 @@ describe('Unit: Extensions > Nginx', function () {
ext.restartNginx();

expect(sudo.calledOnce).to.be.true;
expect(sudo.getCall(0).args[0]).to.match(/nginx -s reload/);
expect(sudo.args[0][0]).to.match(/nginx -s reload/);
});

it('Throws an Error when nginx does', function () {
Expand All @@ -652,7 +652,7 @@ describe('Unit: Extensions > Nginx', function () {
expect(false, 'An error should have been thrown').to.be.true;
}).catch(function (err) {
expect(sudo.calledOnce).to.be.true;
expect(sudo.getCall(0).args[0]).to.match(/nginx -s reload/);
expect(sudo.args[0][0]).to.match(/nginx -s reload/);
expect(err).to.be.ok;
const expectedError = require('../../../lib/errors');
expect(err).to.be.instanceof(expectedError.ProcessError);
Expand All @@ -669,7 +669,7 @@ describe('Unit: Extensions > Nginx', function () {
ext.isSupported();

expect(shellStub.calledOnce).to.be.true;
expect(shellStub.getCall(0).args[0]).to.match(/dpkg -l \| grep nginx/);
expect(shellStub.args[0][0]).to.match(/dpkg -l \| grep nginx/);
});

it('Returns false when dpkg fails', function () {
Expand Down
2 changes: 1 addition & 1 deletion extensions/nginx/test/migrations-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe('Unit: Extensions > Nginx > Migrations', function () {
expect(readFileSync.calledTwice).to.be.true;
expect(ui.listr.calledOnce).to.be.true;

const tasks = ui.listr.getCall(0).args[0];
const tasks = ui.listr.args[0][0];
expect(tasks).to.have.length(5);

return tasks[0].task(null).then(() => {
Expand Down
18 changes: 9 additions & 9 deletions extensions/systemd/test/systemd-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Unit: Systemd > Process Manager', function () {
ext.start().then(() => {
const expectedCmd = 'systemctl start ghost_ghost_org';
expect(ui.sudo.calledOnce).to.be.true;
expect(ui.sudo.getCall(0).args[0]).to.equal(expectedCmd);
expect(ui.sudo.args[0][0]).to.equal(expectedCmd);
});
});

Expand Down Expand Up @@ -95,7 +95,7 @@ describe('Unit: Systemd > Process Manager', function () {
ext.stop().then(() => {
const expectedCmd = 'systemctl stop ghost_ghost_org';
expect(ui.sudo.calledOnce).to.be.true;
expect(ui.sudo.getCall(0).args[0]).to.equal(expectedCmd);
expect(ui.sudo.args[0][0]).to.equal(expectedCmd);
});
});

Expand Down Expand Up @@ -132,7 +132,7 @@ describe('Unit: Systemd > Process Manager', function () {
ext.restart().then(() => {
const expectedCmd = 'systemctl restart ghost_ghost_org';
expect(ui.sudo.calledOnce).to.be.true;
expect(ui.sudo.getCall(0).args[0]).to.equal(expectedCmd);
expect(ui.sudo.args[0][0]).to.equal(expectedCmd);
});
});

Expand Down Expand Up @@ -172,7 +172,7 @@ describe('Unit: Systemd > Process Manager', function () {

expect(ext.isEnabled()).to.be.true;
expect(execaStub.calledOnce).to.be.true;
expect(execaStub.getCall(0).args[0]).to.equal(expectedCmd);
expect(execaStub.args[0][0]).to.equal(expectedCmd);
});

it('Passes bad errors through', function () {
Expand Down Expand Up @@ -209,7 +209,7 @@ describe('Unit: Systemd > Process Manager', function () {
const ext = makeSystemd(null, ui);
ext.enable().then(() => {
expect(ui.sudo.calledOnce).to.be.true;
expect(ui.sudo.getCall(0).args[0]).to.equal(expectedCmd);
expect(ui.sudo.args[0][0]).to.equal(expectedCmd);
})
});

Expand All @@ -233,7 +233,7 @@ describe('Unit: Systemd > Process Manager', function () {
const ext = makeSystemd(null, ui);
ext.disable().then(() => {
expect(ui.sudo.calledOnce).to.be.true;
expect(ui.sudo.getCall(0).args[0]).to.equal(expectedCmd);
expect(ui.sudo.args[0][0]).to.equal(expectedCmd);
})
});

Expand Down Expand Up @@ -263,7 +263,7 @@ describe('Unit: Systemd > Process Manager', function () {

expect(ext.isRunning()).to.be.true;
expect(execaStub.calledOnce).to.be.true;
expect(execaStub.getCall(0).args[0]).to.equal(expectedCmd);
expect(execaStub.args[0][0]).to.equal(expectedCmd);
});

it('Passes bad errors through', function () {
Expand Down Expand Up @@ -323,7 +323,7 @@ describe('Unit: Systemd > Process Manager', function () {

ext._precheck();
expect(fsStub.calledOnce).to.be.true;
expect(fsStub.getCall(0).args[0]).to.equal(expectedFile);
expect(fsStub.args[0][0]).to.equal(expectedFile);
});

it('Errors if unit file doesn\'t exist', function () {
Expand Down Expand Up @@ -358,7 +358,7 @@ describe('Unit: Systemd > Process Manager', function () {

expect(Systemd.willRun()).to.be.true;
expect(execaStub.calledOnce).to.be.true;
expect(execaStub.getCall(0).args[0]).to.equal(expectedCmd);
expect(execaStub.args[0][0]).to.equal(expectedCmd);
});

it('Always fails', function () {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/commands/config-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,12 @@ describe('Unit: Command > Config', function () {

config.getConfigPrompts.call(ctx, argv);
expect(getStub.calledOnce).to.be.true;
expect(getStub.getCall(0).args[1]).to.match(/_prod/);
expect(getStub.args[0][1]).to.match(/_prod/);

ctx.system.development = true;
config.getConfigPrompts.call(ctx, argv);
expect(getStub.calledTwice).to.be.true;
expect(getStub.getCall(1).args[1]).to.match(/_dev/);
expect(getStub.args[1][1]).to.match(/_dev/);
});
});

Expand Down
Loading

0 comments on commit 5ae264f

Please sign in to comment.