Set workspace path based on platform

This commit is contained in:
Johan Haals
2021-01-27 15:15:52 +01:00
parent 6b541f10f9
commit 06af096c49
2 changed files with 30 additions and 20 deletions
@@ -15,6 +15,8 @@
*/
import fs from 'fs-extra';
import os from 'os';
import { resolve } from 'path';
import { AzurePreparer } from './azure';
import { getVoidLogger, Git } from '@backstage/backend-common';
@@ -34,23 +36,25 @@ describe('AzurePreparer', () => {
token: 'fake-azure-token',
});
const workspacePath = os.platform() === 'win32' ? 'C:\\tmp' : '/tmp';
const checkoutPath = resolve(workspacePath, 'checkout');
const templatePath = resolve(workspacePath, 'template');
const prepareOptions = {
url:
'https://dev.azure.com/backstage-org/backstage-project/_git/template-repo',
workspacePath: '/tmp',
workspacePath,
logger,
};
it('calls the clone command with token from integrations config', async () => {
await preparer.prepare(prepareOptions);
expect(Git.fromAuth).toHaveBeenCalledWith({
logger,
password: 'fake-azure-token',
username: 'notempty',
});
expect(fs.move).toHaveBeenCalledWith('/tmp/checkout', '/tmp/template');
expect(fs.rmdir).toHaveBeenCalledWith('/tmp/template/.git');
expect(fs.move).toHaveBeenCalledWith(checkoutPath, templatePath);
expect(fs.rmdir).toHaveBeenCalledWith(resolve(templatePath, '.git'));
});
it('calls the clone command with the correct arguments for a repository', async () => {
@@ -59,7 +63,7 @@ describe('AzurePreparer', () => {
expect(mockGitClient.clone).toHaveBeenCalledWith({
url:
'https://dev.azure.com/backstage-org/backstage-project/_git/template-repo',
dir: '/tmp/checkout',
dir: checkoutPath,
});
});
@@ -67,31 +71,31 @@ describe('AzurePreparer', () => {
await preparer.prepare({
url:
'https://dev.azure.com/backstage-org/backstage-project/_git/template-repo',
workspacePath: '/tmp',
workspacePath,
logger,
});
expect(mockGitClient.clone).toHaveBeenCalledWith({
url:
'https://dev.azure.com/backstage-org/backstage-project/_git/template-repo',
dir: '/tmp/checkout',
dir: checkoutPath,
});
expect(fs.move).toHaveBeenCalledWith('/tmp/checkout', '/tmp/template');
expect(fs.move).toHaveBeenCalledWith(checkoutPath, templatePath);
});
it('moves the template from path if it is specified', async () => {
const path = './template/test/1/2/3';
const path = './subdir';
await preparer.prepare({
url: `https://dev.azure.com/backstage-org/backstage-project/_git/template-repo?path=${encodeURIComponent(
path,
)}`,
logger,
workspacePath: '/tmp',
workspacePath,
});
expect(fs.move).toHaveBeenCalledWith(
'/tmp/checkout/template/test/1/2/3',
'/tmp/template',
resolve(checkoutPath, 'subdir'),
templatePath,
);
});
});
@@ -17,6 +17,8 @@
import fs from 'fs-extra';
import { BitbucketPreparer } from './bitbucket';
import { getVoidLogger, Git } from '@backstage/backend-common';
import { resolve } from 'path';
import os from 'os';
jest.mock('fs-extra');
@@ -38,20 +40,24 @@ describe('BitbucketPreparer', () => {
appPassword: 'fake-password',
});
const workspacePath = os.platform() === 'win32' ? 'C:\\tmp' : '/tmp';
const checkoutPath = resolve(workspacePath, 'checkout');
const templatePath = resolve(workspacePath, 'template');
const prepareOptions = {
url: 'https://bitbucket.org/backstage-project/backstage-repo',
logger,
workspacePath: '/tmp',
workspacePath,
};
it('calls the clone command with the correct arguments for a repository', async () => {
await preparer.prepare(prepareOptions);
expect(mockGitClient.clone).toHaveBeenCalledWith({
url: 'https://bitbucket.org/backstage-project/backstage-repo',
dir: '/tmp/checkout',
dir: checkoutPath,
});
expect(fs.move).toHaveBeenCalledWith('/tmp/checkout', '/tmp/template');
expect(fs.rmdir).toHaveBeenCalledWith('/tmp/template/.git');
expect(fs.move).toHaveBeenCalledWith(checkoutPath, templatePath);
expect(fs.rmdir).toHaveBeenCalledWith(resolve(templatePath, '.git'));
});
it('calls the clone command with the correct arguments if an app password is provided for a repository', async () => {
@@ -73,7 +79,7 @@ describe('BitbucketPreparer', () => {
await preparer.prepare(prepareOptions);
expect(mockGitClient.clone).toHaveBeenCalledWith({
url: 'https://bitbucket.org/backstage-project/backstage-repo',
dir: '/tmp/checkout',
dir: checkoutPath,
});
});
@@ -81,11 +87,11 @@ describe('BitbucketPreparer', () => {
await preparer.prepare({
url: 'https://bitbucket.org/foo/bar/src/master/1/2/3',
logger,
workspacePath: '/tmp',
workspacePath,
});
expect(fs.move).toHaveBeenCalledWith(
'/tmp/checkout/1/2/3',
'/tmp/template',
resolve(checkoutPath, '1', '2', '3'),
templatePath,
);
});