|
11 | 11 | */ |
12 | 12 |
|
13 | 13 | import { dump } from 'js-yaml'; |
| 14 | +import cloneDeep from 'lodash/cloneDeep'; |
14 | 15 |
|
15 | 16 | import { prepareDevfile } from '@/components/WorkspaceProgress/CreatingSteps/Apply/Devfile/prepareDevfile'; |
16 | 17 | import devfileApi from '@/services/devfileApi'; |
@@ -228,107 +229,140 @@ describe('FactoryLoaderContainer/prepareDevfile', () => { |
228 | 229 | }); |
229 | 230 |
|
230 | 231 | describe('has parent', () => { |
231 | | - describe('with registryUrl', () => { |
232 | | - it('with storage-type attribute', () => { |
233 | | - // mute console logs |
234 | | - console.warn = jest.fn(); |
235 | | - const devfile = { |
236 | | - schemaVersion: '2.2.0', |
237 | | - metadata: { |
238 | | - name: 'wksp-test', |
239 | | - }, |
240 | | - parent: { |
241 | | - id: 'nodejs', |
242 | | - registryUrl: 'https://registry.devfile.io/', |
243 | | - }, |
244 | | - } as devfileApi.Devfile; |
| 232 | + let devfile: devfileApi.Devfile; |
| 233 | + let parentDevfile: devfileApi.Devfile; |
| 234 | + // mute console logs |
| 235 | + console.warn = jest.fn(); |
| 236 | + |
| 237 | + beforeEach(() => { |
| 238 | + devfile = { |
| 239 | + schemaVersion: '2.2.2', |
| 240 | + metadata: { |
| 241 | + generateName: 'nodejs', |
| 242 | + }, |
| 243 | + parent: {}, |
| 244 | + } as devfileApi.Devfile; |
245 | 245 |
|
246 | | - const newDevfile = prepareDevfile(devfile, factoryId, 'ephemeral', false, { |
247 | | - schemaVersion: '2.2.2', |
248 | | - metadata: { |
249 | | - generateName: 'nodejs', |
| 246 | + parentDevfile = { |
| 247 | + schemaVersion: '2.2.0', |
| 248 | + metadata: { |
| 249 | + name: 'sample-using-parent', |
| 250 | + }, |
| 251 | + components: [ |
| 252 | + { |
| 253 | + name: 'tools', |
| 254 | + container: { |
| 255 | + env: [ |
| 256 | + { |
| 257 | + name: 'DEVFILE_ENV_VAR', |
| 258 | + value: 'true', |
| 259 | + }, |
| 260 | + ], |
| 261 | + }, |
250 | 262 | }, |
251 | | - attributes: { |
252 | | - 'controller.devfile.io/storage-type': 'ephemeral', |
| 263 | + ], |
| 264 | + commands: [ |
| 265 | + { |
| 266 | + id: 'parent-command', |
| 267 | + exec: { |
| 268 | + label: '2. This command from the parent', |
| 269 | + component: 'tools', |
| 270 | + commandLine: 'echo "Hello from parent"', |
| 271 | + }, |
253 | 272 | }, |
254 | | - } as devfileApi.Devfile); |
| 273 | + ], |
| 274 | + } as devfileApi.Devfile; |
| 275 | + }); |
255 | 276 |
|
| 277 | + describe('with registryUrl', () => { |
| 278 | + it('with storage-type attribute', () => { |
| 279 | + devfile.parent!.id = 'nodejs'; |
| 280 | + devfile.parent!.registryUrl = 'https://registry.devfile.io/'; |
| 281 | + const _devfile = cloneDeep(devfile); |
| 282 | + |
| 283 | + parentDevfile.attributes = { |
| 284 | + 'controller.devfile.io/storage-type': 'ephemeral', |
| 285 | + }; |
| 286 | + const _parentDevfile = cloneDeep(parentDevfile); |
| 287 | + |
| 288 | + const newDevfile = prepareDevfile( |
| 289 | + _devfile, |
| 290 | + factoryId, |
| 291 | + 'ephemeral', |
| 292 | + false, |
| 293 | + _parentDevfile, |
| 294 | + ); |
| 295 | + |
| 296 | + expect(_devfile).toEqual(devfile); |
| 297 | + expect(_parentDevfile).toEqual(parentDevfile); |
256 | 298 | expect(console.warn).toHaveBeenCalledWith( |
257 | 299 | 'Unable to apply controller.devfile.io/storage-type attribute.', |
258 | 300 | ); |
259 | 301 | expect(newDevfile.attributes?.[DEVWORKSPACE_STORAGE_TYPE_ATTR]).toBeUndefined(); |
260 | 302 | }); |
261 | 303 |
|
262 | 304 | it('without storage-type attribute', () => { |
263 | | - const devfile = { |
264 | | - schemaVersion: '2.2.0', |
265 | | - metadata: { |
266 | | - name: 'wksp-test', |
267 | | - }, |
268 | | - parent: { |
269 | | - id: 'nodejs', |
270 | | - registryUrl: 'https://registry.devfile.io/', |
271 | | - }, |
272 | | - } as devfileApi.Devfile; |
273 | | - |
274 | | - const newDevfile = prepareDevfile(devfile, factoryId, 'ephemeral', false, { |
275 | | - schemaVersion: '2.2.2', |
276 | | - metadata: { |
277 | | - generateName: 'nodejs', |
278 | | - }, |
279 | | - } as devfileApi.Devfile); |
| 305 | + devfile.parent!.id = 'nodejs'; |
| 306 | + devfile.parent!.registryUrl = 'https://registry.devfile.io/'; |
| 307 | + const _devfile = cloneDeep(devfile); |
| 308 | + |
| 309 | + const _parentDevfile = cloneDeep(parentDevfile); |
| 310 | + |
| 311 | + const newDevfile = prepareDevfile( |
| 312 | + _devfile, |
| 313 | + factoryId, |
| 314 | + 'ephemeral', |
| 315 | + false, |
| 316 | + _parentDevfile, |
| 317 | + ); |
280 | 318 |
|
| 319 | + expect(_devfile).toEqual(devfile); |
| 320 | + expect(_parentDevfile).toEqual(parentDevfile); |
281 | 321 | expect(newDevfile.attributes?.[DEVWORKSPACE_STORAGE_TYPE_ATTR]).toEqual('ephemeral'); |
282 | 322 | }); |
283 | 323 | }); |
284 | 324 | describe('with uri', () => { |
285 | 325 | it('with storage-type attribute', () => { |
286 | | - // mute console logs |
287 | | - console.warn = jest.fn(); |
288 | | - const devfile = { |
289 | | - schemaVersion: '2.2.0', |
290 | | - metadata: { |
291 | | - name: 'wksp-test', |
292 | | - }, |
293 | | - parent: { |
294 | | - uri: 'https://raw.githubusercontent.com/test/devfile.yaml', |
295 | | - }, |
296 | | - } as devfileApi.Devfile; |
297 | | - |
298 | | - const newDevfile = prepareDevfile(devfile, factoryId, 'ephemeral', false, { |
299 | | - schemaVersion: '2.2.2', |
300 | | - metadata: { |
301 | | - generateName: 'nodejs', |
302 | | - }, |
303 | | - attributes: { |
304 | | - 'controller.devfile.io/storage-type': 'ephemeral', |
305 | | - }, |
306 | | - } as devfileApi.Devfile); |
| 326 | + devfile.parent!.uri = 'https://raw.githubusercontent.com/test/devfile.yaml'; |
| 327 | + const _devfile = cloneDeep(devfile); |
| 328 | + |
| 329 | + parentDevfile.attributes = { |
| 330 | + 'controller.devfile.io/storage-type': 'ephemeral', |
| 331 | + }; |
| 332 | + const _parentDevfile = cloneDeep(parentDevfile); |
| 333 | + |
| 334 | + const newDevfile = prepareDevfile( |
| 335 | + _devfile, |
| 336 | + factoryId, |
| 337 | + 'ephemeral', |
| 338 | + false, |
| 339 | + _parentDevfile, |
| 340 | + ); |
307 | 341 |
|
| 342 | + expect(_devfile).toEqual(devfile); |
| 343 | + expect(_parentDevfile).toEqual(parentDevfile); |
308 | 344 | expect(console.warn).toHaveBeenCalledWith( |
309 | 345 | 'Unable to apply controller.devfile.io/storage-type attribute.', |
310 | 346 | ); |
311 | 347 | expect(newDevfile.attributes?.[DEVWORKSPACE_STORAGE_TYPE_ATTR]).toBeUndefined(); |
312 | 348 | }); |
313 | 349 |
|
314 | 350 | it('without storage-type attribute', () => { |
315 | | - const devfile = { |
316 | | - schemaVersion: '2.2.0', |
317 | | - metadata: { |
318 | | - name: 'wksp-test', |
319 | | - }, |
320 | | - parent: { |
321 | | - uri: 'https://raw.githubusercontent.com/test/devfile.yaml', |
322 | | - }, |
323 | | - } as devfileApi.Devfile; |
| 351 | + devfile.parent!.uri = 'https://raw.githubusercontent.com/test/devfile.yaml'; |
| 352 | + const _devfile = cloneDeep(devfile); |
324 | 353 |
|
325 | | - const newDevfile = prepareDevfile(devfile, factoryId, 'ephemeral', false, { |
326 | | - schemaVersion: '2.2.2', |
327 | | - metadata: { |
328 | | - generateName: 'nodejs', |
329 | | - }, |
330 | | - } as devfileApi.Devfile); |
| 354 | + const _parentDevfile = cloneDeep(parentDevfile); |
| 355 | + |
| 356 | + const newDevfile = prepareDevfile( |
| 357 | + _devfile, |
| 358 | + factoryId, |
| 359 | + 'ephemeral', |
| 360 | + false, |
| 361 | + _parentDevfile, |
| 362 | + ); |
331 | 363 |
|
| 364 | + expect(_devfile).toEqual(devfile); |
| 365 | + expect(_parentDevfile).toEqual(parentDevfile); |
332 | 366 | expect(newDevfile.attributes?.[DEVWORKSPACE_STORAGE_TYPE_ATTR]).toEqual('ephemeral'); |
333 | 367 | }); |
334 | 368 | }); |
|
0 commit comments