fix tests no overwrite

Signed-off-by: dzdidi <deniszalessky@gmail.com>
This commit is contained in:
dzdidi
2024-01-28 12:18:26 +00:00
parent b18f5ca8fe
commit e8cbdc5e64
4 changed files with 15 additions and 15 deletions

View File

@@ -18,7 +18,7 @@ function shareAppFolder (name, entry) {
let [userId = '*', permissions = 'r', branch = '*'] = entry?.split(':') || []
if (!aclJson.ACL[userId]) aclJson[userId] = { [branch]: permissions }
if (!aclJson.ACL[userId]) aclJson.ACL[userId] = { [branch]: permissions }
fs.writeFileSync(p, JSON.stringify(aclJson))
}
@@ -58,7 +58,7 @@ function isShared (name) {
function getACL (name) {
if (!fs.existsSync(`${APP_HOME}/${name}/.git-daemon-export-ok`)) throw new Error('Repo is not shared')
const aclFile = fs.readFileSync(`${APP_HOME}/${name}/.git-daemon-export-ok`, 'r')
const aclFile = fs.readFileSync(`${APP_HOME}/${name}/.git-daemon-export-ok`, 'utf8')
aclJson = JSON.parse(aclFile || '{ "protectedBranches": [], "ACL": {}}')
return aclJson
}

View File

View File

@@ -9,33 +9,33 @@ test('getAppHome', t => {
})
test('createAppFolder, share, is shared, unshare, isInitialized, list, getCodePath', t => {
home.createAppFolder('test')
home.createAppFolder('test_code')
t.ok(fs.existsSync(path.join(home.APP_HOME, 'test', 'code')))
t.ok(fs.existsSync(path.join(home.APP_HOME, 'test_code', 'code')))
t.absent(home.isShared('test'))
t.absent(fs.existsSync(path.join(home.APP_HOME, 'test', '.git-daemon-export-ok')))
t.absent(home.isShared('test_code'))
t.absent(fs.existsSync(path.join(home.APP_HOME, 'test_code', '.git-daemon-export-ok')))
home.shareAppFolder('test')
home.shareAppFolder('test_code')
t.ok(home.isShared('test'))
t.ok(fs.existsSync(path.join(home.APP_HOME, 'test', '.git-daemon-export-ok')))
t.ok(home.isShared('test_code'))
t.ok(fs.existsSync(path.join(home.APP_HOME, 'test_code', '.git-daemon-export-ok')))
home.unshareAppFolder('test')
home.unshareAppFolder('test_code')
t.absent(home.isShared('test'))
t.absent(fs.existsSync(path.join(home.APP_HOME, 'test', '.git-daemon-export-ok')))
t.absent(home.isShared('test_code'))
t.absent(fs.existsSync(path.join(home.APP_HOME, 'test_code', '.git-daemon-export-ok')))
t.absent(home.isInitialized('test'))
t.absent(home.isInitialized('test_code'))
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.alike(path.resolve(home.getCodePath('test_code')), path.resolve(path.join(home.APP_HOME, 'test_code', 'code')))
t.teardown(() => {
fs.rmSync(path.join(home.APP_HOME, 'test', 'code'), { recursive: true })
fs.rmSync(path.join(home.APP_HOME, 'test_code'), { recursive: true })
})
})

Binary file not shown.