Skip to content

Commit

Permalink
test: test interop with original git-evtag
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Jul 7, 2016
1 parent 81500dc commit 92a6879
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 32 deletions.
22 changes: 22 additions & 0 deletions test/ev-tag-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

const tape = require('tape');

const fixtures = require('./fixtures');

const cli = fixtures.cli;
const cmd = fixtures.cmd;

tape('evtag interop', (t) => {
fixtures.clone('git://github.com/cgwalters/git-evtag.git');

// Verify tags
const node = process.execPath;
t.doesNotThrow(() => cmd(node, [ cli, '--insecure', '-v', 'v2016.1' ]),
'valid evtag #1');
t.doesNotThrow(() => cmd(node, [ cli, '--insecure', '-v', 'v2015.2' ]),
'valid evtag #2');

fixtures.destroy();
t.end();
});
53 changes: 53 additions & 0 deletions test/fixtures/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

const fs = require('fs');
const path = require('path');
const spawnSync = require('child_process').spawnSync;

const rimraf = require('rimraf');

const gst = require('../../');
const GIT = gst.GIT;

const cli = path.join(__dirname, '..', '..', 'bin', 'git-secure-tag');
exports.cli = cli;

const repo = path.join(__dirname, 'repo');
exports.repo = repo;

function cmd(name, args, noCwd) {
const p = spawnSync(name, args, {
stdio: [ null, 'pipe', 'pipe' ],
cwd: noCwd ? undefined : repo
});
if (p.status !== 0) {
const msg = `${name} ${args.join(' ')} failed`;
throw new Error(msg + '\n' + p.stdout + '\n' + p.stderr);
}
}
exports.cmd = cmd;

function write(file, content) {
fs.writeFileSync(path.join(repo, file), content);
}
exports.write = write;

// Initialize repo
exports.init = function init() {
rimraf.sync(repo);
fs.mkdirSync(repo);

cmd(GIT, [ 'init' ]);
cmd(GIT, [ 'config', 'user.email', 'john@doe.org' ]);
cmd(GIT, [ 'config', 'user.name', 'John Doe' ]);
};

// Clone repo
exports.clone = function clone(url) {
rimraf.sync(repo);
cmd(GIT, [ 'clone', url, repo ], true);
};

exports.destroy = function destroy() {
rimraf.sync(repo);
};
39 changes: 7 additions & 32 deletions test/scenario-test.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,20 @@
'use strict';

const crypto = require('crypto');
const fs = require('fs');
const path = require('path');
const spawnSync = require('child_process').spawnSync;

const tape = require('tape');
const rimraf = require('rimraf');

const gst = require('../');
const GIT = gst.GIT;

const cli = path.join(__dirname, '..', 'bin', 'git-secure-tag');
const fixtures = require('./fixtures');

const repo = path.join(__dirname, 'fixtures', 'scenario');
const cli = fixtures.cli;
const cmd = fixtures.cmd;
const write = fixtures.write;

function cmd(name, args) {
const p = spawnSync(name, args, {
stdio: [ null, 'pipe', 'pipe' ],
cwd: repo
});
if (p.status !== 0) {
const msg = `${name} ${args.join(' ')} failed`;
throw new Error(msg + '\n' + p.stdout + '\n' + p.stderr);
}
}

function write(file, content) {
fs.writeFileSync(path.join(repo, file), content);
}

tape('v8 inspect', (t) => {
// Initialize repo
// TODO(indutny): move it to fixtures?
rimraf.sync(repo);
fs.mkdirSync(repo);

cmd(GIT, [ 'init' ]);
cmd(GIT, [ 'config', 'user.email', 'john@doe.org' ]);
cmd(GIT, [ 'config', 'user.name', 'John Doe' ]);
tape('git secure tag', (t) => {
fixtures.init();

write('file.txt', 'hello');
cmd(GIT, [ 'add', 'file.txt' ]);
Expand Down Expand Up @@ -82,7 +58,6 @@ tape('v8 inspect', (t) => {
/No.*found/,
'no hash at all');

// Deinitialize repo
rimraf.sync(repo);
fixtures.destroy();
t.end();
});

0 comments on commit 92a6879

Please sign in to comment.