Skip to content

Commit 4e46cbe

Browse files
authored
Fix: adding starterProjects attributes (#173)
* fix: adding starterProjects attributes Signed-off-by: Oleksii Orel <[email protected]> * fixup! fix: adding starterProjects attributes Signed-off-by: Oleksii Orel <[email protected]> --------- Signed-off-by: Oleksii Orel <[email protected]>
1 parent c0c8ebc commit 4e46cbe

File tree

2 files changed

+80
-3
lines changed

2 files changed

+80
-3
lines changed

src/generate.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,12 @@ export class Generate {
125125

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

133136
// for now the list of devWorkspace templates is only the editor template

tests/generate.spec.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,80 @@ metadata:
160160
};
161161
expect(context.devWorkspace).toStrictEqual(expectedDevWorkspace);
162162
});
163+
test('with storage-type attribute', async () => {
164+
const devfileContent = `
165+
schemaVersion: 2.2.0
166+
metadata:
167+
name: starter-project
168+
attributes:
169+
controller.devfile.io/storage-type: ephemeral
170+
starterProjects:
171+
- name: go-starter
172+
description: A Go project
173+
git:
174+
checkoutFrom:
175+
revision: main
176+
remotes:
177+
origin: https://github.com/devfile-samples/devfile-stack-go.git
178+
- name: vertx-http-example
179+
git:
180+
remotes:
181+
origin: https://github.com
182+
`;
183+
const editorContent = `
184+
schemaVersion: 2.2.0
185+
metadata:
186+
name: che-code
187+
`;
188+
189+
const fsWriteFileSpy = jest.spyOn(fs, 'writeFile');
190+
fsWriteFileSpy.mockReturnValue({});
191+
192+
let context = await generate.generate(devfileContent, editorContent);
193+
// expect not to write the file
194+
expect(fsWriteFileSpy).not.toBeCalled();
195+
const expectedDevWorkspace = {
196+
apiVersion: 'workspace.devfile.io/v1alpha2',
197+
kind: 'DevWorkspace',
198+
metadata: {
199+
name: 'starter-project',
200+
},
201+
spec: {
202+
started: true,
203+
routingClass: 'che',
204+
template: {
205+
attributes: {
206+
'controller.devfile.io/storage-type': 'ephemeral',
207+
'controller.devfile.io/use-starter-project': 'go-starter',
208+
},
209+
starterProjects: [
210+
{
211+
name: 'go-starter',
212+
description: 'A Go project',
213+
git: {
214+
checkoutFrom: {
215+
revision: 'main',
216+
},
217+
remotes: {
218+
origin: 'https://github.com/devfile-samples/devfile-stack-go.git',
219+
},
220+
},
221+
},
222+
{
223+
name: 'vertx-http-example',
224+
git: {
225+
remotes: {
226+
origin: 'https://github.com',
227+
},
228+
},
229+
},
230+
],
231+
},
232+
contributions: [{ name: 'editor', kubernetes: { name: 'che-code-starter-project' } }],
233+
},
234+
};
235+
expect(context.devWorkspace).toStrictEqual(expectedDevWorkspace);
236+
});
163237
});
164238

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

0 commit comments

Comments
 (0)