-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
50 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,16 @@ | |
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
/* tslint:disable */ | ||
|
||
import Git from '@elastic/nodegit'; | ||
import assert from 'assert'; | ||
import { execSync } from 'child_process'; | ||
import fs from 'fs'; | ||
import * as mkdirp from 'mkdirp'; | ||
import os from 'os'; | ||
import path from 'path'; | ||
import rimraf from 'rimraf'; | ||
import { getDefaultBranch, GitOperations } from '../git_operations'; | ||
import * as mkdirp from "mkdirp"; | ||
import Git from '@elastic/nodegit'; | ||
import { createTestServerOption } from '../test_utils'; | ||
|
||
describe('git_operations', () => { | ||
|
@@ -42,31 +42,36 @@ describe('git_operations', () => { | |
async function prepareProject(repoPath: string) { | ||
mkdirp.sync(repoPath); | ||
const repo = await Git.Repository.init(repoPath, 0); | ||
const content = ""; | ||
fs.writeFileSync(path.join(repo.workdir(), "1"), content, 'utf8'); | ||
const content = ''; | ||
fs.writeFileSync(path.join(repo.workdir(), '1'), content, 'utf8'); | ||
const subFolder = 'src'; | ||
fs.mkdirSync(path.join(repo.workdir(), subFolder)); | ||
fs.writeFileSync(path.join(repo.workdir(), "src/2"), content, 'utf8'); | ||
fs.writeFileSync(path.join(repo.workdir(), "src/3"), content, 'utf8'); | ||
fs.writeFileSync(path.join(repo.workdir(), 'src/2'), content, 'utf8'); | ||
fs.writeFileSync(path.join(repo.workdir(), 'src/3'), content, 'utf8'); | ||
|
||
const index = await repo.refreshIndex(); | ||
await index.addByPath("1"); | ||
await index.addByPath("src/2"); | ||
await index.addByPath("src/3"); | ||
await index.addByPath('1'); | ||
await index.addByPath('src/2'); | ||
await index.addByPath('src/3'); | ||
index.write(); | ||
const treeId = await index.writeTree(); | ||
const committer = Git.Signature.create("tester", | ||
"[email protected]", Date.now() / 1000, 60); | ||
const commit = await repo.createCommit("HEAD", committer, committer, "commit for test", treeId, []); | ||
const committer = Git.Signature.create('tester', '[email protected]', Date.now() / 1000, 60); | ||
const commit = await repo.createCommit( | ||
'HEAD', | ||
committer, | ||
committer, | ||
'commit for test', | ||
treeId, | ||
[] | ||
); | ||
// tslint:disable-next-line:no-console | ||
console.log(`created commit ${commit.tostrS()}`); | ||
return repo; | ||
} | ||
|
||
// @ts-ignore | ||
before(async () => { | ||
await prepareProject( | ||
path.join(serverOptions.repoPath, repoUri) | ||
); | ||
await prepareProject(path.join(serverOptions.repoPath, repoUri)); | ||
}); | ||
const repoUri = 'github.com/test/test_repo'; | ||
|
||
|
@@ -76,25 +81,23 @@ describe('git_operations', () => { | |
const g = new GitOperations(serverOptions.repoPath); | ||
let count = 0; | ||
const iterator = await g.iterateRepo(repoUri, 'HEAD'); | ||
for await (let value of iterator) { | ||
if(count=== 0) { | ||
assert.strictEqual("1", value.name); | ||
assert.strictEqual("1",value.path) | ||
} else if(count=== 1) { | ||
assert.strictEqual("2", value.name); | ||
assert.strictEqual("src/2",value.path) | ||
} else if(count=== 2) { | ||
assert.strictEqual("3", value.name); | ||
assert.strictEqual("src/3",value.path) | ||
for await (const value of iterator) { | ||
if (count === 0) { | ||
assert.strictEqual('1', value.name); | ||
assert.strictEqual('1', value.path); | ||
} else if (count === 1) { | ||
assert.strictEqual('2', value.name); | ||
assert.strictEqual('src/2', value.path); | ||
} else if (count === 2) { | ||
assert.strictEqual('3', value.name); | ||
assert.strictEqual('src/3', value.path); | ||
} else { | ||
assert.fail("this repo should contains exactly 2 files") | ||
assert.fail('this repo should contains exactly 2 files'); | ||
} | ||
count++; | ||
} | ||
const totalFiles = await g.countRepoFiles(repoUri, 'HEAD'); | ||
assert.strictEqual(count, 3, "this repo should contains exactly 2 files"); | ||
assert.strictEqual(totalFiles, 3, "this repo should contains exactly 2 files"); | ||
}) | ||
assert.strictEqual(count, 3, 'this repo should contains exactly 2 files'); | ||
assert.strictEqual(totalFiles, 3, 'this repo should contains exactly 2 files'); | ||
}); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters