|
| 1 | +/*----------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Red Hat, Inc. All rights reserved. |
| 3 | + * Licensed under the MIT License. See LICENSE file in the project root for license information. |
| 4 | + *-----------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import { expect } from 'chai'; |
| 7 | +import { getInstance } from '../../src/odo'; |
| 8 | +import { Command } from '../../src/odo/command'; |
| 9 | +import { Command as ProjectCommand } from '../../src/openshift/project'; |
| 10 | + |
| 11 | +suite('openshift/project.ts', function () { |
| 12 | + |
| 13 | + const clusterUrl = process.env.CLUSTER_URL || 'https://api.crc.testing:6443'; |
| 14 | + const username = process.env.CLUSTER_USER || 'developer'; |
| 15 | + const password = process.env.CLUSTER_PASSWORD || 'developer'; |
| 16 | + |
| 17 | + const TEST_PROJECT_1 = 'test-project-1'; |
| 18 | + const TEST_PROJECT_2 = 'test-project-2'; |
| 19 | + |
| 20 | + const ODO = getInstance(); |
| 21 | + |
| 22 | + suiteSetup(async function () { |
| 23 | + if (await ODO.requireLogin()) { |
| 24 | + await ODO.execute(Command.odoLoginWithUsernamePassword(clusterUrl, username, password)); |
| 25 | + } |
| 26 | + try { |
| 27 | + await ODO.deleteProject(TEST_PROJECT_1); |
| 28 | + } catch (e) { |
| 29 | + // do nothing |
| 30 | + } |
| 31 | + try { |
| 32 | + await ODO.deleteProject(TEST_PROJECT_2); |
| 33 | + } catch (e) { |
| 34 | + // do nothing |
| 35 | + } |
| 36 | + await ODO.createProject(TEST_PROJECT_1); |
| 37 | + await ODO.createProject(TEST_PROJECT_2); |
| 38 | + }); |
| 39 | + |
| 40 | + suiteTeardown(async function () { |
| 41 | + try { |
| 42 | + await ODO.deleteProject(TEST_PROJECT_1); |
| 43 | + } catch (e) { |
| 44 | + // do nothing |
| 45 | + } |
| 46 | + try { |
| 47 | + await ODO.deleteProject(TEST_PROJECT_2); |
| 48 | + } catch (e) { |
| 49 | + // do nothing |
| 50 | + } |
| 51 | + }); |
| 52 | + |
| 53 | + test('Command.setActiveProject()', async function () { |
| 54 | + await ODO.execute(ProjectCommand.setActiveProject(TEST_PROJECT_2)); |
| 55 | + let activeProject = await ODO.getActiveProject(); |
| 56 | + expect(activeProject).to.equal(TEST_PROJECT_2); |
| 57 | + |
| 58 | + await ODO.execute(ProjectCommand.setActiveProject(TEST_PROJECT_1)); |
| 59 | + activeProject = await ODO.getActiveProject(); |
| 60 | + expect(activeProject).to.equal(TEST_PROJECT_1); |
| 61 | + }); |
| 62 | + |
| 63 | + test('Command.getAll()', async function() { |
| 64 | + const res = await ODO.execute(ProjectCommand.getAll(TEST_PROJECT_1)); |
| 65 | + expect(JSON.parse(res.stdout).items).to.have.length(0); |
| 66 | + }); |
| 67 | + |
| 68 | + test('Command.deleteProject()', async function() { |
| 69 | + await ODO.execute(ProjectCommand.deleteProject(TEST_PROJECT_1)); |
| 70 | + const projects = await ODO.getProjects(); |
| 71 | + expect(projects).not.to.contain(TEST_PROJECT_1); |
| 72 | + }); |
| 73 | + |
| 74 | +}); |
0 commit comments