mirror of
https://github.com/aljazceru/gitpear.git
synced 2025-12-17 14:14:22 +01:00
fix tests, rename appHome to home
Signed-off-by: dzdidi <deniszalessky@gmail.com>
This commit is contained in:
36
src/cli.js
36
src/cli.js
@@ -8,7 +8,7 @@ const program = new commander.Command()
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
const appHome = require('./appHome')
|
||||
const home = require('./home')
|
||||
const git = require('./git')
|
||||
|
||||
const pkg = require('../package.json')
|
||||
@@ -30,12 +30,12 @@ program
|
||||
}
|
||||
|
||||
const name = fullPath.split(path.sep).pop()
|
||||
if ((appHome.isInitialized(name))) {
|
||||
if ((home.isInitialized(name))) {
|
||||
console.error(`${name} is already initialized`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
appHome.createAppFolder(name)
|
||||
home.createAppFolder(name)
|
||||
console.log(`Added project "${name}" to gitpear`)
|
||||
await git.createBareRepo(name)
|
||||
console.log(`Created bare repo for "${name}"`)
|
||||
@@ -43,7 +43,7 @@ program
|
||||
console.log(`Added git remote for "${name}" as "pear"`)
|
||||
|
||||
if (options.share) {
|
||||
appHome.shareAppFolder(name)
|
||||
home.shareAppFolder(name)
|
||||
console.log(`Shared "${name}" project`)
|
||||
// push?
|
||||
}
|
||||
@@ -55,8 +55,8 @@ program
|
||||
.addArgument(new commander.Argument('[p]', 'path to the repo').default('.'))
|
||||
.action(async (p, options) => {
|
||||
const name = path.resolve(p).split(path.sep).pop()
|
||||
if ((appHome.isInitialized(name))) {
|
||||
appHome.shareAppFolder(name)
|
||||
if ((home.isInitialized(name))) {
|
||||
home.shareAppFolder(name)
|
||||
console.log(`Shared "${name}" project`)
|
||||
return
|
||||
}
|
||||
@@ -71,8 +71,8 @@ program
|
||||
.addArgument(new commander.Argument('[p]', 'path to the repo').default('.'))
|
||||
.action((p, options) => {
|
||||
const name = path.resolve(p).split(path.sep).pop()
|
||||
if ((appHome.isInitialized(name))) {
|
||||
appHome.unshareAppFolder(name)
|
||||
if ((home.isInitialized(name))) {
|
||||
home.unshareAppFolder(name)
|
||||
console.log(`Unshared "${name}" project`)
|
||||
|
||||
return
|
||||
@@ -87,14 +87,14 @@ program
|
||||
.description('list all gitpear repos')
|
||||
.option('-s, --shared', 'list only shared repos')
|
||||
.action((p, options) => {
|
||||
appHome.list(options.opts().shared).forEach(name => console.log(name))
|
||||
home.list(options.opts().shared).forEach(name => console.log(name))
|
||||
})
|
||||
|
||||
program
|
||||
.command('key')
|
||||
.description('get a public key of gitpear')
|
||||
.action((p, options) => {
|
||||
console.log('Public key:', appHome.readPk())
|
||||
console.log('Public key:', home.readPk())
|
||||
})
|
||||
|
||||
program
|
||||
@@ -104,8 +104,8 @@ program
|
||||
.option('-k, --stop', 'stop daemon')
|
||||
.action((p, options) => {
|
||||
if (options.opts().start) {
|
||||
if (appHome.getDaemonPid()) {
|
||||
console.error('Daemon already running with PID:', appHome.getDaemonPid())
|
||||
if (home.getDaemonPid()) {
|
||||
console.error('Daemon already running with PID:', home.getDaemonPid())
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
@@ -113,23 +113,23 @@ program
|
||||
detached: true,
|
||||
stdio: [
|
||||
'ignore',
|
||||
appHome.getOutStream(),
|
||||
appHome.getErrStream()
|
||||
home.getOutStream(),
|
||||
home.getErrStream()
|
||||
]
|
||||
})
|
||||
console.log('Daemon started. Process ID:', daemon.pid)
|
||||
appHome.storeDaemonPid(daemon.pid)
|
||||
home.storeDaemonPid(daemon.pid)
|
||||
daemon.unref()
|
||||
} else if (options.opts().stop) {
|
||||
if (!appHome.getDaemonPid()) {
|
||||
if (!home.getDaemonPid()) {
|
||||
console.error('Daemon not running')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const pid = appHome.getDaemonPid()
|
||||
const pid = home.getDaemonPid()
|
||||
process.kill(pid)
|
||||
|
||||
appHome.removeDaemonPid()
|
||||
home.removeDaemonPid()
|
||||
console.log('Daemon stopped. Process ID:', pid)
|
||||
} else {
|
||||
console.error('No option provided')
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { getCodePath } = require('./appHome')
|
||||
const { getCodePath } = require('./home')
|
||||
const { spawn } = require('child_process')
|
||||
|
||||
async function lsPromise (url) {
|
||||
|
||||
@@ -5,12 +5,12 @@ const crypto = require('hypercore-crypto')
|
||||
|
||||
const RPC = require('./rpc.js')
|
||||
const setState = require('./state.js')
|
||||
const appHome = require('./appHome.js')
|
||||
const home = require('./home.js')
|
||||
|
||||
const Corestore = require('corestore')
|
||||
|
||||
;(async () => {
|
||||
const keyPair = appHome.getKeyPair()
|
||||
const keyPair = home.getKeyPair()
|
||||
const swarm = new Hyperswarm({ keyPair })
|
||||
|
||||
const store = new Corestore(RAM)
|
||||
@@ -18,7 +18,7 @@ const Corestore = require('corestore')
|
||||
swarm.join(crypto.discoveryKey(keyPair.publicKey))
|
||||
await swarm.flush()
|
||||
|
||||
console.log('Public key:', appHome.readPk())
|
||||
console.log('Public key:', home.readPk())
|
||||
|
||||
let state = await setState(store)
|
||||
let { announcedRefs, repositories, drives } = state
|
||||
@@ -28,7 +28,7 @@ const Corestore = require('corestore')
|
||||
|
||||
let rpc = new RPC(announcedRefs, repositories, drives)
|
||||
|
||||
appHome.watch(async (event, path) => {
|
||||
home.watch(async (event, path) => {
|
||||
state = await setState(store, drives)
|
||||
announcedRefs = state.announcedRefs
|
||||
repositories = state.repositories
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
const Hyperdrive = require('hyperdrive')
|
||||
|
||||
const git = require('./git.js')
|
||||
const appHome = require('./appHome.js')
|
||||
const home = require('./home.js')
|
||||
|
||||
module.exports = async function setState (store, drives = {}) {
|
||||
const repos = appHome.list(true)
|
||||
const repos = home.list(true)
|
||||
|
||||
const announcedRefs = {}
|
||||
const repositories = {}
|
||||
@@ -15,14 +15,14 @@ module.exports = async function setState (store, drives = {}) {
|
||||
await drives[repo].ready()
|
||||
}
|
||||
|
||||
const ls = await git.lsPromise(appHome.getCodePath(repo))
|
||||
const ls = await git.lsPromise(home.getCodePath(repo))
|
||||
|
||||
repositories[repo] = {}
|
||||
for (const ref in ls) {
|
||||
repositories[repo][ref] = ls[ref]
|
||||
announcedRefs[ls[ref]] = repo
|
||||
|
||||
const localPackStream = git.uploadPack(appHome.getCodePath(repo), ls[ref])
|
||||
const localPackStream = git.uploadPack(home.getCodePath(repo), ls[ref])
|
||||
const driveStream = drives[repo].createWriteStream(`/packs/${ls[ref]}.pack`)
|
||||
localPackStream.on('ready', () => localPackStream.stdout.pipe(driveStream))
|
||||
}
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
const { test } = require('brittle')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const appHome = require('../src/appHome')
|
||||
|
||||
test('getAppHome', t => {
|
||||
t.ok(appHome.APP_HOME)
|
||||
})
|
||||
|
||||
test('createAppFolder, share, is shared, unshare, isInitialized, list, getCodePath', t => {
|
||||
appHome.createAppFolder('appHome-test')
|
||||
|
||||
t.ok(fs.existsSync(path.join(appHome.APP_HOME, 'appHome-test', 'code')))
|
||||
|
||||
t.absent(appHome.isShared('appHome-test'))
|
||||
t.absent(fs.existsSync(path.join(appHome.APP_HOME, 'appHome-test', '.git-daemon-export-ok')))
|
||||
|
||||
appHome.shareAppFolder('appHome-test')
|
||||
|
||||
t.ok(appHome.isShared('appHome-test'))
|
||||
t.ok(fs.existsSync(path.join(appHome.APP_HOME, 'appHome-test', '.git-daemon-export-ok')))
|
||||
|
||||
appHome.unshareAppFolder('appHome-test')
|
||||
|
||||
t.absent(appHome.isShared('appHome-test'))
|
||||
t.absent(fs.existsSync(path.join(appHome.APP_HOME, 'appHome-test', '.git-daemon-export-ok')))
|
||||
|
||||
t.absent(appHome.isInitialized('appHome-test'))
|
||||
t.ok(appHome.isInitialized('foo'))
|
||||
|
||||
t.alike(new Set(appHome.list()), new Set(['foo', 'bar', 'zar', 'appHome-test']))
|
||||
t.alike(new Set(appHome.list(true)), new Set(['foo', 'bar', 'zar']))
|
||||
|
||||
t.alike(path.resolve(appHome.getCodePath('appHome-test')), path.resolve(path.join(appHome.APP_HOME, 'appHome-test', 'code')))
|
||||
|
||||
t.teardown(() => {
|
||||
fs.rmdirSync(path.join(appHome.APP_HOME, 'appHome-test', 'code'), { recursive: true })
|
||||
})
|
||||
})
|
||||
|
||||
test('readPk, getKeyPair', t => {
|
||||
t.ok(appHome.readPk())
|
||||
t.ok(appHome.getKeyPair())
|
||||
})
|
||||
|
||||
test('getOutStream, getErrStream', t => {
|
||||
t.absent(fs.existsSync(path.join(appHome.APP_HOME, 'out.log')))
|
||||
t.ok(appHome.getOutStream())
|
||||
t.ok(fs.existsSync(path.join(appHome.APP_HOME, 'out.log')))
|
||||
|
||||
t.absent(fs.existsSync(path.join(appHome.APP_HOME, 'err.log')))
|
||||
t.ok(appHome.getErrStream())
|
||||
t.ok(fs.existsSync(path.join(appHome.APP_HOME, 'err.log')))
|
||||
|
||||
t.teardown(() => {
|
||||
fs.unlinkSync(path.join(appHome.APP_HOME, 'out.log'))
|
||||
fs.unlinkSync(path.join(appHome.APP_HOME, 'err.log'))
|
||||
})
|
||||
})
|
||||
|
||||
test('getDaemonPid, removeDaemonPid', t => {
|
||||
t.absent(appHome.getDaemonPid())
|
||||
appHome.storeDaemonPid(123)
|
||||
t.alike(appHome.getDaemonPid(), 123)
|
||||
appHome.removeDaemonPid()
|
||||
t.absent(appHome.getDaemonPid())
|
||||
})
|
||||
@@ -2,7 +2,7 @@ const test = require('brittle')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const appHome = require('../src/appHome.js')
|
||||
const home = require('../src/home.js')
|
||||
|
||||
const git = require('../src/git.js')
|
||||
|
||||
@@ -51,15 +51,15 @@ test('git - uploadPack (w have)', { skip: true }, async t => {
|
||||
})
|
||||
|
||||
test('git - createBareRepo', async t => {
|
||||
t.absent(fs.existsSync(path.join(appHome.APP_HOME, 'test-git', 'code')))
|
||||
appHome.createAppFolder('test-git')
|
||||
t.absent(fs.existsSync(path.join(home.APP_HOME, 'test-git', 'code')))
|
||||
home.createAppFolder('test-git')
|
||||
|
||||
t.absent(fs.existsSync(path.join(appHome.APP_HOME, 'test-git', 'code', 'HEAD')))
|
||||
t.absent(fs.existsSync(path.join(home.APP_HOME, 'test-git', 'code', 'HEAD')))
|
||||
await git.createBareRepo('test-git')
|
||||
|
||||
t.ok(fs.existsSync(path.join(appHome.APP_HOME, 'test-git', 'code', 'HEAD')))
|
||||
t.ok(fs.existsSync(path.join(home.APP_HOME, 'test-git', 'code', 'HEAD')))
|
||||
|
||||
t.teardown(() => {
|
||||
fs.rmdirSync(path.join(appHome.APP_HOME, 'test-git'), { recursive: true })
|
||||
fs.rmSync(path.join(home.APP_HOME, 'test-git'), { recursive: true })
|
||||
})
|
||||
})
|
||||
|
||||
68
test/home.test.js
Normal file
68
test/home.test.js
Normal file
@@ -0,0 +1,68 @@
|
||||
const { test } = require('brittle')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const home = require('../src/home')
|
||||
|
||||
test('getAppHome', t => {
|
||||
t.ok(home.APP_HOME)
|
||||
})
|
||||
|
||||
test('createAppFolder, share, is shared, unshare, isInitialized, list, getCodePath', t => {
|
||||
home.createAppFolder('test')
|
||||
|
||||
t.ok(fs.existsSync(path.join(home.APP_HOME, 'test', 'code')))
|
||||
|
||||
t.absent(home.isShared('test'))
|
||||
t.absent(fs.existsSync(path.join(home.APP_HOME, 'test', '.git-daemon-export-ok')))
|
||||
|
||||
home.shareAppFolder('test')
|
||||
|
||||
t.ok(home.isShared('test'))
|
||||
t.ok(fs.existsSync(path.join(home.APP_HOME, 'test', '.git-daemon-export-ok')))
|
||||
|
||||
home.unshareAppFolder('test')
|
||||
|
||||
t.absent(home.isShared('test'))
|
||||
t.absent(fs.existsSync(path.join(home.APP_HOME, 'test', '.git-daemon-export-ok')))
|
||||
|
||||
t.absent(home.isInitialized('test'))
|
||||
t.ok(home.isInitialized('foo'))
|
||||
|
||||
t.alike(new Set(home.list()), new Set(['foo', 'bar', 'zar']))
|
||||
t.alike(new Set(home.list(true)), new Set(['foo', 'bar']))
|
||||
|
||||
t.alike(path.resolve(home.getCodePath('test')), path.resolve(path.join(home.APP_HOME, 'test', 'code')))
|
||||
|
||||
t.teardown(() => {
|
||||
fs.rmSync(path.join(home.APP_HOME, 'test', 'code'), { recursive: true })
|
||||
})
|
||||
})
|
||||
|
||||
test('readPk, getKeyPair', t => {
|
||||
t.ok(home.readPk())
|
||||
t.ok(home.getKeyPair())
|
||||
})
|
||||
|
||||
test('getOutStream, getErrStream', t => {
|
||||
t.absent(fs.existsSync(path.join(home.APP_HOME, 'out.log')))
|
||||
t.ok(home.getOutStream())
|
||||
t.ok(fs.existsSync(path.join(home.APP_HOME, 'out.log')))
|
||||
|
||||
t.absent(fs.existsSync(path.join(home.APP_HOME, 'err.log')))
|
||||
t.ok(home.getErrStream())
|
||||
t.ok(fs.existsSync(path.join(home.APP_HOME, 'err.log')))
|
||||
|
||||
t.teardown(() => {
|
||||
fs.unlinkSync(path.join(home.APP_HOME, 'out.log'))
|
||||
fs.unlinkSync(path.join(home.APP_HOME, 'err.log'))
|
||||
})
|
||||
})
|
||||
|
||||
test('getDaemonPid, removeDaemonPid', t => {
|
||||
t.absent(home.getDaemonPid())
|
||||
home.storeDaemonPid(123)
|
||||
t.alike(home.getDaemonPid(), 123)
|
||||
home.removeDaemonPid()
|
||||
t.absent(home.getDaemonPid())
|
||||
})
|
||||
@@ -3,7 +3,7 @@ const setState = require('../src/state.js')
|
||||
const Corestore = require('corestore')
|
||||
const RAM = require('random-access-memory')
|
||||
|
||||
const repoNames = ['foo', 'bar', 'zar']
|
||||
const repoNames = ['foo', 'bar']
|
||||
|
||||
test('setState', async t => {
|
||||
const res = await setState(new Corestore(RAM))
|
||||
|
||||
BIN
test_home.tar.gz
BIN
test_home.tar.gz
Binary file not shown.
Reference in New Issue
Block a user