Skip to content
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
9 changes: 6 additions & 3 deletions src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,12 @@ export class Generate {

// if the devfile has a starter project, we use it for the devWorkspace
if (devfileCopy.starterProjects && devfileCopy.starterProjects.length > 0) {
devWorkspace.spec.template.attributes = {
'controller.devfile.io/use-starter-project': devfileCopy.starterProjects[0].name,
};
if (devWorkspace.spec.template.attributes === undefined) {
devWorkspace.spec.template.attributes = {};
}
const starterProjectName = devfileCopy.starterProjects[0].name;
// add starter projects to the devWorkspace
devWorkspace.spec.template.attributes['controller.devfile.io/use-starter-project'] = starterProjectName;
}

// for now the list of devWorkspace templates is only the editor template
Expand Down
74 changes: 74 additions & 0 deletions tests/generate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,80 @@ metadata:
};
expect(context.devWorkspace).toStrictEqual(expectedDevWorkspace);
});
test('with storage-type attribute', async () => {
const devfileContent = `
schemaVersion: 2.2.0
metadata:
name: starter-project
attributes:
controller.devfile.io/storage-type: ephemeral
starterProjects:
- name: go-starter
description: A Go project
git:
checkoutFrom:
revision: main
remotes:
origin: https://github.com/devfile-samples/devfile-stack-go.git
- name: vertx-http-example
git:
remotes:
origin: https://github.com
`;
const editorContent = `
schemaVersion: 2.2.0
metadata:
name: che-code
`;

const fsWriteFileSpy = jest.spyOn(fs, 'writeFile');
fsWriteFileSpy.mockReturnValue({});

let context = await generate.generate(devfileContent, editorContent);
// expect not to write the file
expect(fsWriteFileSpy).not.toBeCalled();
const expectedDevWorkspace = {
apiVersion: 'workspace.devfile.io/v1alpha2',
kind: 'DevWorkspace',
metadata: {
name: 'starter-project',
},
spec: {
started: true,
routingClass: 'che',
template: {
attributes: {
'controller.devfile.io/storage-type': 'ephemeral',
'controller.devfile.io/use-starter-project': 'go-starter',
},
starterProjects: [
{
name: 'go-starter',
description: 'A Go project',
git: {
checkoutFrom: {
revision: 'main',
},
remotes: {
origin: 'https://github.com/devfile-samples/devfile-stack-go.git',
},
},
},
{
name: 'vertx-http-example',
git: {
remotes: {
origin: 'https://github.com',
},
},
},
],
},
contributions: [{ name: 'editor', kubernetes: { name: 'che-code-starter-project' } }],
},
};
expect(context.devWorkspace).toStrictEqual(expectedDevWorkspace);
});
});

describe('Without writing an output file', () => {
Expand Down