Files: 18024992bfb2fc4f955daa3aeaf04a6f7dc68e01 / test / index.js
2422 bytesRaw
1 | var path = require('path') |
2 | var proc = require('child_process') |
3 | var mktemp = require('mktemp') |
4 | var rimraf = require('rimraf') |
5 | var fs = require('fs') |
6 | var tape = require('tape') |
7 | |
8 | var tmpDirTemplate = path.join(require('os').tmpdir(), 'XXXXXXX') |
9 | var tmpDirs = [] |
10 | |
11 | tape.onFinish(function () { |
12 | tmpDirs.forEach(function (dir) { |
13 | rimraf.sync(dir) |
14 | }) |
15 | }) |
16 | |
17 | function Git(cb) { |
18 | var env = Object.create(process.env) |
19 | env.PATH = path.join(__dirname, 'bin') + ':' + env.PATH |
20 | var tmpDir = mktemp.createDirSync(tmpDirTemplate) |
21 | tmpDirs.push(tmpDir) |
22 | |
23 | function git() { |
24 | var args = [].slice.call(arguments) |
25 | var doneCb = args.pop() |
26 | return proc.spawn('git', args, { |
27 | env: env, |
28 | cwd: tmpDir, |
29 | stdio: ['ignore', 'inherit', 'inherit'] |
30 | }) |
31 | .on('close', doneCb) |
32 | } |
33 | |
34 | git('init', function (code) { |
35 | if (code) return cb(new Error('git failed: ' + code)) |
36 | git('config', 'user.name', 'name', function (code) { |
37 | if (code) return cb(new Error('git failed: ' + code)) |
38 | git('config', 'user.email', 'email', function (code) { |
39 | if (code) return cb(new Error('git failed: ' + code)) |
40 | cb(null, git) |
41 | }) |
42 | }) |
43 | }) |
44 | } |
45 | |
46 | tape('clone empty repo', function (t) { |
47 | Git(function (err, git) { |
48 | t.error(err, 'init') |
49 | |
50 | git('clone', '.', '1', function (code) { |
51 | t.equals(code, 0, 'clone') |
52 | t.end() |
53 | }) |
54 | }) |
55 | }) |
56 | |
57 | tape('clone empty repo with airpaste', function (t) { |
58 | t.plan(3) |
59 | |
60 | Git(function (err, git) { |
61 | t.error(err, 'init') |
62 | |
63 | var ns = 'test-' + Math.random() |
64 | |
65 | git('airpaste', ns, function (code) { |
66 | t.equals(code, 0, 'served') |
67 | }) |
68 | |
69 | git('clone', 'airpaste://' + ns, '2', function (code) { |
70 | t.equals(code, 0, 'cloned') |
71 | }) |
72 | }) |
73 | }) |
74 | |
75 | tape('push', function (t) { |
76 | t.plan(5) |
77 | |
78 | Git(function (err, git1) { |
79 | t.error(err, 'init1') |
80 | |
81 | Git(function (err, git2) { |
82 | t.error(err, 'init2') |
83 | |
84 | var ns = 'test-' + Math.random() |
85 | |
86 | git2('commit', '--allow-empty', '-m', 'first', function (code) { |
87 | t.equals(code, 0, 'commit') |
88 | |
89 | git2('push', 'airpaste://' + ns, 'master', function (code) { |
90 | // this fails for some reason but still woks |
91 | // t.equals(code, 0, 'push') |
92 | }) |
93 | |
94 | git1('airpaste', ns, function (code) { |
95 | t.equals(code, 0, 'served') |
96 | |
97 | git1('log', '-1', function (code) { |
98 | t.equals(code, 0, 'got the commit') |
99 | }) |
100 | }) |
101 | }) |
102 | }) |
103 | }) |
104 | }) |
105 |
Built with git-ssb-web