diff --git a/src/generate.ts b/src/generate.ts index 4754b0a..12cbc40 100644 --- a/src/generate.ts +++ b/src/generate.ts @@ -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 diff --git a/tests/generate.spec.ts b/tests/generate.spec.ts index 00a4639..e2dcb51 100644 --- a/tests/generate.spec.ts +++ b/tests/generate.spec.ts @@ -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', () => {