Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bbc0a4b

Browse files
committed
Rework GPG tests to use the new utility
1 parent e1e314c commit bbc0a4b

File tree

1 file changed

+32
-40
lines changed

1 file changed

+32
-40
lines changed

test/git-strategies.test.js

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -633,70 +633,62 @@ import {fsStat} from '../lib/helpers';
633633
{
634634
command: 'commit',
635635
progressiveTense: 'committing',
636+
usesPromptServerAlready: false,
636637
action: () => git.commit('message'),
637638
},
638639
{
639640
command: 'merge',
640641
progressiveTense: 'merging',
642+
usesPromptServerAlready: false,
641643
action: () => git.merge('some-branch'),
642644
},
643645
{
644646
command: 'pull',
645647
progressiveTense: 'pulling',
648+
usesPromptServerAlready: true,
646649
action: () => git.pull('some-branch'),
647650
},
648651
];
649652

650653
operations.forEach(op => {
651654
it(`temporarily overrides gpg.program when ${op.progressiveTense}`, async function() {
652-
const execStub = sinon.stub(git, 'exec');
653-
if (op.configureStub) {
654-
op.configureStub(git);
655-
}
656-
execStub.returns(Promise.resolve());
655+
const execStub = sinon.stub(GitProcess, 'exec');
656+
execStub.returns(Promise.resolve({stdout: '', stderr: '', exitCode: 0}));
657657

658658
await op.action();
659659

660-
const callArgs = execStub.getCall(0).args;
661-
const execArgs = callArgs[0];
662-
assert.equal(execArgs[0], '-c');
663-
assert.match(execArgs[1], /^gpg\.program=.*gpg-no-tty\.sh$/);
664-
assert.isNotOk(callArgs[1].stdin);
665-
assert.isNotOk(callArgs[1].useGitPromptServer);
666-
});
660+
const [args, workingDir, options] = execStub.getCall(0).args;
667661

668-
it(`retries a ${op.command} with a GitPromptServer when GPG signing fails`, async function() {
669-
const gpgErr = new GitError('Mock GPG failure');
670-
gpgErr.stdErr = 'stderr includes "gpg failed"';
671-
gpgErr.code = 128;
662+
assertGitConfigSetting(args, op.command, 'gpg.program', '.*gpg-no-tty\\.sh$');
672663

673-
const execStub = sinon.stub(git, 'exec');
674-
if (op.configureStub) {
675-
op.configureStub(execStub, git);
676-
}
677-
execStub.onCall(0).returns(Promise.reject(gpgErr));
678-
execStub.returns(Promise.resolve());
664+
assert.equal(options.env.ATOM_GITHUB_SOCK_PATH === undefined, !op.usesPromptServerAlready);
665+
assert.equal(workingDir, git.workingDir);
666+
});
679667

680-
try {
668+
if (!op.usesPromptServerAlready) {
669+
it(`retries a ${op.command} with a GitPromptServer when GPG signing fails`, async function() {
670+
const execStub = sinon.stub(GitProcess, 'exec');
671+
execStub.onCall(0).returns(Promise.resolve({
672+
stdout: '',
673+
stderr: 'stderr includes "gpg failed"',
674+
exitCode: 128,
675+
}));
676+
execStub.returns(Promise.resolve({stdout: '', stderr: '', exitCode: 0}));
677+
678+
// Should not throw
681679
await op.action();
682-
} catch (err) {
683-
assert.fail('expected op.action() not to throw the mock error');
684-
}
685680

686-
const callArgs0 = execStub.getCall(0).args;
687-
const execArgs0 = callArgs0[0];
688-
assert.equal(execArgs0[0], '-c');
689-
assert.match(execArgs0[1], /^gpg\.program=.*gpg-no-tty\.sh$/);
690-
assert.isNotOk(callArgs0[1].stdin);
691-
assert.isNotOk(callArgs0[1].useGitPromptServer);
692-
693-
const callArgs1 = execStub.getCall(0 + 1).args;
694-
const execArgs1 = callArgs1[0];
695-
assert.equal(execArgs1[0], '-c');
696-
assert.match(execArgs1[1], /^gpg\.program=.*gpg-no-tty\.sh$/);
697-
assert.isNotOk(callArgs1[1].stdin);
698-
assert.isTrue(callArgs1[1].useGitPromptServer);
699-
});
681+
const [args0, workingDir0, options0] = execStub.getCall(0).args;
682+
assertGitConfigSetting(args0, op.command, 'gpg.program', '.*gpg-no-tty\\.sh$');
683+
assert.equal(options0.env.ATOM_GITHUB_SOCK_PATH === undefined, !op.usesPromptServerAlready);
684+
assert.equal(workingDir0, git.workingDir);
685+
686+
const [args1, workingDir1, options1] = execStub.getCall(1).args;
687+
assertGitConfigSetting(args1, op.command, 'gpg.program', '.*gpg-no-tty\\.sh$');
688+
assert.isDefined(options1.env.ATOM_GITHUB_SOCK_PATH);
689+
assert.equal(workingDir1, git.workingDir);
690+
});
691+
}
700692
});
701693
});
702694

0 commit comments

Comments
 (0)