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

fix: [devworkpsce-handler] Move project section from editor devfile to user devfile #1271

Merged
merged 1 commit into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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