Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
fix: [devworkpsce-handler] Move project section from editor devfile t…
Browse files Browse the repository at this point in the history
…o user devfile

Signed-off-by: Igor Vinokur <ivinokur@redhat.com>
  • Loading branch information
vinokurig authored and benoitf committed Dec 9, 2021
1 parent 68f1e4e commit 2e8c3fd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
4 changes: 2 additions & 2 deletions tools/devworkspace-handler/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ export class Generate {
const editorDevfile = await this.pluginRegistryResolver.loadDevfilePlugin(editorEntry);

if (project) {
editorDevfile.projects = [{ name: project.name, zip: { location: project.location } }];
devfile.projects = [{ name: project.name, zip: { location: project.location } }];
} else {
editorDevfile.projects = [
devfile.projects = [
{
name: githubUrl.getRepoName(),
git: { remotes: { origin: githubUrl.getCloneUrl() }, checkoutFrom: { revision: githubUrl.getBranchName() } },
Expand Down
20 changes: 7 additions & 13 deletions tools/devworkspace-handler/tests/generate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('Test Generate', () => {
loadDevfilePlugin: pluginRegistryResolverLoadDevfilePluginMethod,
} as any;

let editorDevfile = {};
let devfile = {};

const devfileUrl = 'https://github.com/org/devfile-repo/tree/branch';
const fakeoutputDir = '/fake-output';
Expand All @@ -80,13 +80,16 @@ describe('Test Generate', () => {
container.bind(GithubResolver).toConstantValue(githubResolver);
githubResolverResolveMethod.mockReturnValue(githubUrlMock);

editorDevfile = {
devfile = {
schemaVersion: '2.1.0',
metadata: {
name: 'theia-ide',
},
commands: [],
};
pluginRegistryResolverLoadDevfilePluginMethod.mockResolvedValue(devfile);
const jsYmalSpy = jest.spyOn(jsYaml, 'load');
jsYmalSpy.mockReturnValue(devfile);

urlFetcherFetchTextMethod.mockResolvedValue(jsYaml.dump({ metadata: {} }));
fsWriteFileSpy = jest.spyOn(fs, 'writeFile');
Expand All @@ -96,8 +99,6 @@ describe('Test Generate', () => {
});

test('basics', async () => {
pluginRegistryResolverLoadDevfilePluginMethod.mockResolvedValue(editorDevfile);

const rawDevfileUrl = 'https://content-of-devfile.url';
getContentUrlMethod.mockReturnValue(rawDevfileUrl);
getBranchNameMethod.mockReturnValue('HEAD');
Expand All @@ -111,9 +112,6 @@ describe('Test Generate', () => {

test('generate template with default project', async () => {
//given
const pluginRegistryResolverSpy = jest.spyOn(pluginRegistryResolver, 'loadDevfilePlugin');
pluginRegistryResolverSpy.mockResolvedValue(editorDevfile);

getCloneUrlMethod.mockReturnValue('https://github.com/org/repo.git');
getRepoNameMethod.mockReturnValue('test-repo');
getBranchNameMethod.mockReturnValue('test-branch');
Expand All @@ -122,7 +120,7 @@ describe('Test Generate', () => {
await generate.generate(devfileUrl, editor, SidecarPolicy.USE_DEV_CONTAINER, fakeoutputDir);

//then
expect((editorDevfile as V1alpha2DevWorkspaceTemplateSpec).projects).toStrictEqual([
expect((devfile as V1alpha2DevWorkspaceTemplateSpec).projects).toStrictEqual([
{
name: 'test-repo',
git: { remotes: { origin: 'https://github.com/org/repo.git' }, checkoutFrom: { revision: 'test-branch' } },
Expand All @@ -131,18 +129,14 @@ describe('Test Generate', () => {
});

test('generate template with defined project', async () => {
//given
const pluginRegistryResolverSpy = jest.spyOn(pluginRegistryResolver, 'loadDevfilePlugin');
pluginRegistryResolverSpy.mockResolvedValue(editorDevfile);

//when
await generate.generate(devfileUrl, editor, SidecarPolicy.USE_DEV_CONTAINER, fakeoutputDir, {
name: 'test-name',
location: 'test-location',
});

//then
expect((editorDevfile as V1alpha2DevWorkspaceTemplateSpec).projects).toStrictEqual([
expect((devfile as V1alpha2DevWorkspaceTemplateSpec).projects).toStrictEqual([
{ name: 'test-name', zip: { location: 'test-location' } },
]);
});
Expand Down

0 comments on commit 2e8c3fd

Please sign in to comment.