commit
8acaf6bb4c
5 changed files with 85 additions and 14 deletions
29
__test__/entrypoint.sh
Executable file
29
__test__/entrypoint.sh
Executable file
|
@ -0,0 +1,29 @@
|
||||||
|
#!/bin/sh -l
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Save the working directory
|
||||||
|
WORKINGDIR=$PWD
|
||||||
|
|
||||||
|
# Serve remote repo
|
||||||
|
mkdir /git
|
||||||
|
git init --bare /git/test-repo.git
|
||||||
|
git daemon --verbose --enable=receive-pack --base-path=/git --export-all /git/test-repo.git &>/dev/null &
|
||||||
|
|
||||||
|
# Give the daemon time to start
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
# Clone and make an initial commit
|
||||||
|
git clone git://127.0.0.1/test-repo.git /git/test-repo
|
||||||
|
cd /git/test-repo
|
||||||
|
git config --global user.email "you@example.com"
|
||||||
|
git config --global user.name "Your Name"
|
||||||
|
echo "#test-repo" > README.md
|
||||||
|
git add .
|
||||||
|
git commit -m "initial commit"
|
||||||
|
git push -u
|
||||||
|
|
||||||
|
# Restore the working directory
|
||||||
|
cd $WORKINGDIR
|
||||||
|
|
||||||
|
# Execute integration tests
|
||||||
|
jest int
|
|
@ -1,6 +1,4 @@
|
||||||
import * as path from 'path'
|
|
||||||
import {
|
import {
|
||||||
ConfigOption,
|
|
||||||
getRepoPath,
|
getRepoPath,
|
||||||
execGit,
|
execGit,
|
||||||
addConfigOption,
|
addConfigOption,
|
||||||
|
@ -15,7 +13,7 @@ const originalGitHubWorkspace = process.env['GITHUB_WORKSPACE']
|
||||||
describe('git tests', () => {
|
describe('git tests', () => {
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
// GitHub workspace
|
// GitHub workspace
|
||||||
process.env['GITHUB_WORKSPACE'] = __dirname
|
process.env['GITHUB_WORKSPACE'] = '/git/test-repo'
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
|
@ -26,14 +24,7 @@ describe('git tests', () => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
test('getRepoPath', async () => {
|
it('successfully executes a git command', async () => {
|
||||||
expect(getRepoPath()).toEqual(process.env['GITHUB_WORKSPACE'])
|
|
||||||
expect(getRepoPath('foo')).toEqual(
|
|
||||||
path.resolve(process.env['GITHUB_WORKSPACE'] || '', 'foo')
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('execGit', async () => {
|
|
||||||
const repoPath = getRepoPath()
|
const repoPath = getRepoPath()
|
||||||
const result = await execGit(
|
const result = await execGit(
|
||||||
repoPath,
|
repoPath,
|
||||||
|
@ -75,13 +66,13 @@ describe('git tests', () => {
|
||||||
expect(unset).toBeTruthy()
|
expect(unset).toBeTruthy()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('configOptionExists returns true', async () => {
|
it('determines that a config option exists', async () => {
|
||||||
const repoPath = getRepoPath()
|
const repoPath = getRepoPath()
|
||||||
const result = await configOptionExists(repoPath, 'remote.origin.url')
|
const result = await configOptionExists(repoPath, 'remote.origin.url')
|
||||||
expect(result).toBeTruthy()
|
expect(result).toBeTruthy()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('configOptionExists returns false', async () => {
|
it('determines that a config option does not exist', async () => {
|
||||||
const repoPath = getRepoPath()
|
const repoPath = getRepoPath()
|
||||||
const result = await configOptionExists(repoPath, 'this.key.does.not.exist')
|
const result = await configOptionExists(repoPath, 'this.key.does.not.exist')
|
||||||
expect(result).toBeFalsy()
|
expect(result).toBeFalsy()
|
26
__test__/git.unit.test.ts
Normal file
26
__test__/git.unit.test.ts
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
import * as path from 'path'
|
||||||
|
import {getRepoPath} from '../lib/git'
|
||||||
|
|
||||||
|
const originalGitHubWorkspace = process.env['GITHUB_WORKSPACE']
|
||||||
|
|
||||||
|
describe('git tests', () => {
|
||||||
|
beforeAll(() => {
|
||||||
|
// GitHub workspace
|
||||||
|
process.env['GITHUB_WORKSPACE'] = __dirname
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
// Restore GitHub workspace
|
||||||
|
delete process.env['GITHUB_WORKSPACE']
|
||||||
|
if (originalGitHubWorkspace) {
|
||||||
|
process.env['GITHUB_WORKSPACE'] = originalGitHubWorkspace
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
test('getRepoPath', async () => {
|
||||||
|
expect(getRepoPath()).toEqual(process.env['GITHUB_WORKSPACE'])
|
||||||
|
expect(getRepoPath('foo')).toEqual(
|
||||||
|
path.resolve(process.env['GITHUB_WORKSPACE'] || '', 'foo')
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
23
__test__/integration-tests.sh
Executable file
23
__test__/integration-tests.sh
Executable file
|
@ -0,0 +1,23 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
IMAGE="cpr-integration-tests:latest"
|
||||||
|
ARG1=${1:-}
|
||||||
|
|
||||||
|
if [[ "$(docker images -q $IMAGE 2> /dev/null)" == "" || $ARG1 == "build" ]]; then
|
||||||
|
echo "Building Docker image $IMAGE ..."
|
||||||
|
|
||||||
|
cat > Dockerfile << EOF
|
||||||
|
FROM node:12-alpine
|
||||||
|
RUN apk --no-cache add git git-daemon
|
||||||
|
RUN npm install jest --global
|
||||||
|
WORKDIR /cpr
|
||||||
|
COPY __test__/entrypoint.sh /entrypoint.sh
|
||||||
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
|
EOF
|
||||||
|
|
||||||
|
docker build -t $IMAGE .
|
||||||
|
rm Dockerfile
|
||||||
|
fi
|
||||||
|
|
||||||
|
docker run -v $PWD:/cpr $IMAGE
|
|
@ -10,7 +10,9 @@
|
||||||
"format": "prettier --write '**/*.ts'",
|
"format": "prettier --write '**/*.ts'",
|
||||||
"format-check": "prettier --check '**/*.ts'",
|
"format-check": "prettier --check '**/*.ts'",
|
||||||
"lint": "eslint src/**/*.ts",
|
"lint": "eslint src/**/*.ts",
|
||||||
"test": "jest --passWithNoTests",
|
"test:unit": "jest unit",
|
||||||
|
"test:int": "__test__/integration-tests.sh",
|
||||||
|
"test": "npm run test:unit && npm run test:int",
|
||||||
"pack-assets": "mkdir -p dist/cpr && cp -rv src/cpr/* dist/cpr",
|
"pack-assets": "mkdir -p dist/cpr && cp -rv src/cpr/* dist/cpr",
|
||||||
"vendor-deps": "pip download -r src/cpr/requirements.txt --no-binary=:all: -d dist/vendor",
|
"vendor-deps": "pip download -r src/cpr/requirements.txt --no-binary=:all: -d dist/vendor",
|
||||||
"package": "npm run build && npm run pack-assets && npm run vendor-deps"
|
"package": "npm run build && npm run pack-assets && npm run vendor-deps"
|
||||||
|
|
Loading…
Reference in a new issue