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
40 changes: 14 additions & 26 deletions src/openshift/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*-----------------------------------------------------------------------------------------------*/

import { OpenShiftItem } from './openshiftItem';
import { OpenShiftObject } from '../odo';
import { OpenShiftObject, OdoImpl } from '../odo';
import * as vscode from 'vscode';
import { Progress } from '../util/progress';
import opn = require('opn');
Expand Down Expand Up @@ -163,15 +163,10 @@ export class Component extends OpenShiftItem {

if (!componentTypeVersion) return null;
const project = application.getParent();
return Progress.execWithProgress({
cancellable: false,
location: vscode.ProgressLocation.Notification,
title: `Creating new component '${componentName}'`
}, [{command: `odo create ${componentTypeName}:${componentTypeVersion} ${componentName} --local ${folder.uri.fsPath} --app ${application.getName()} --project ${project.getName()}`, increment: 50},
{command: `odo push ${componentName} --local ${folder.uri.fsPath} --app ${application.getName()} --project ${project.getName()}`, increment: 50}
], Component.odo)
.then(() => Component.explorer.refresh(application))
.then(() => `Component '${componentName}' successfully created`);
return Progress.execCmdWithProgress(`Creating new component '${componentName}'`, `odo create ${componentTypeName}:${componentTypeVersion} ${componentName} --local ${folder.uri.fsPath} --app ${application.getName()} --project ${project.getName()}`)
.then(() => Component.explorer.refresh(application))
.then(() => Component.odo.executeInTerminal(`odo push ${componentName} --local ${folder.uri.fsPath} --app ${application.getName()} --project ${project.getName()}`))
.then(() => `Component '${componentName}' successfully created`);
}

private static async createFromGit(application: OpenShiftObject): Promise<string> {
Expand Down Expand Up @@ -209,14 +204,11 @@ export class Component extends OpenShiftItem {
});

const project = application.getParent();
return Progress.execWithProgress({
cancellable: false,
location: vscode.ProgressLocation.Notification,
title: `Creating new component '${componentName}'`
}, [{command: `odo create ${componentTypeName}:${componentTypeVersion} ${componentName} --git ${repoURI} --app ${application.getName()} --project ${project.getName()}`, increment: 100}
], Component.odo)
.then(() => Component.explorer.refresh(application))
.then(() => `Component '${componentName}' successfully created`);
return Promise.resolve()
.then(() => Component.odo.executeInTerminal(`odo create ${componentTypeName}:${componentTypeVersion} ${componentName} --git ${repoURI} --app ${application.getName()} --project ${project.getName()}`))
.then(() => Component.wait())
.then(() => Component.explorer.refresh(application))
.then(() => `Component '${componentName}' successfully created`);
}

private static async createFromBinary(application: OpenShiftObject): Promise<string> {
Expand All @@ -243,13 +235,9 @@ export class Component extends OpenShiftItem {
if (!componentTypeVersion) return null;

const project = application.getParent();
return Progress.execWithProgress({
cancellable: false,
location: vscode.ProgressLocation.Notification,
title: `Creating new component '${componentName}'`
}, [{command: `odo create ${componentTypeName}:${componentTypeVersion} ${componentName} --binary ${binaryFile[0].fsPath} --app ${application.getName()} --project ${project.getName()}`, increment: 100}
], Component.odo)
.then(() => Component.explorer.refresh(application))
.then(() => `Component '${componentName}' successfully created`);
return Progress.execCmdWithProgress(`Creating new component '${componentName}'`,
`odo create ${componentTypeName}:${componentTypeVersion} ${componentName} --binary ${binaryFile[0].fsPath} --app ${application.getName()} --project ${project.getName()}`)
.then(() => Component.explorer.refresh(application))
.then(() => `Component '${componentName}' successfully created`);
}
}
1 change: 1 addition & 0 deletions src/openshift/openshiftItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export abstract class OpenShiftItem {

static create(context: OpenShiftObject): Promise<String> { return Promise.reject(); }
static del(context: OpenShiftObject): Promise<String> { return Promise.reject(); }
static wait(timeout: number = 2500): Promise<void> { return new Promise((res)=>setTimeout(res, timeout)); }
}
15 changes: 5 additions & 10 deletions src/openshift/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,8 @@ export class Service extends OpenShiftItem {
});
if (serviceName) {
const project = application.getParent();
return Promise.resolve().then(() =>
Progress.execWithProgress({
cancellable: false,
location: vscode.ProgressLocation.Notification,
title: `Creating new service '${serviceName}'`
}, [{command: `odo service create ${serviceTemplateName} --plan ${serviceTemplatePlanName} ${serviceName.trim()} --app ${application.getName()} --project ${project.getName()}`, increment: 100}
], Service.odo))
return Progress.execCmdWithProgress(`Creating new service '${serviceName}'`,
`odo service create ${serviceTemplateName} --plan ${serviceTemplatePlanName} ${serviceName.trim()} --app ${application.getName()} --project ${project.getName()}`)
.then(() => Service.explorer.refresh(application))
.then(() => `Service '${serviceName}' successfully created`)
.catch((err) => Promise.reject(`Failed to create service with error '${err}'`));
Expand All @@ -54,9 +49,9 @@ export class Service extends OpenShiftItem {
if (!componentToLink) return null;

return Promise.resolve()
.then(() => Service.odo.execute(`odo link ${context.getName()} --app ${app.getName()} --project ${project.getName()} --component ${componentToLink.getName()}`))
.then(() => `service '${context.getName()}' successfully linked with component '${componentToLink.getName()}'`)
.catch((err) => Promise.reject(`Failed to link service with error '${err}'`));
.then(() => Service.odo.execute(`odo link ${context.getName()} --app ${app.getName()} --project ${project.getName()} --component ${componentToLink.getName()}`))
.then(() => `service '${context.getName()}' successfully linked with component '${componentToLink.getName()}'`)
.catch((err) => Promise.reject(`Failed to link service with error '${err}'`));
}

static async del(treeItem: OpenShiftObject): Promise<string> {
Expand Down
29 changes: 15 additions & 14 deletions test/openshift/component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ suite('Openshift/Component', () => {
sandbox.stub(OdoImpl.prototype, 'getProjects').resolves([]);
sandbox.stub(OdoImpl.prototype, 'getApplications').resolves([]);
sandbox.stub(OdoImpl.prototype, 'getComponents').resolves([]);
sandbox.stub(Component, 'wait').resolves();
});

teardown(() => {
Expand All @@ -37,7 +38,10 @@ suite('Openshift/Component', () => {
const componentType = 'nodejs';
const version = 'latest';
const folder = { uri: { fsPath: 'folder' } };
let quickPickStub: sinon.SinonStub, inputStub: sinon.SinonStub, progressStub: sinon.SinonStub;
let quickPickStub: sinon.SinonStub,
inputStub: sinon.SinonStub,
progressStub: sinon.SinonStub,
progressCmdStub: sinon.SinonStub;

setup(() => {
quickPickStub = sandbox.stub(vscode.window, 'showQuickPick');
Expand All @@ -46,6 +50,7 @@ suite('Openshift/Component', () => {
quickPickStub.onThirdCall().resolves(version);
inputStub = sandbox.stub(vscode.window, 'showInputBox');
progressStub = sandbox.stub(Progress, 'execWithProgress').resolves();
progressCmdStub = sandbox.stub(Progress, 'execCmdWithProgress').resolves();
});

test('returns null when cancelled', async () => {
Expand Down Expand Up @@ -75,14 +80,13 @@ suite('Openshift/Component', () => {
});

test('happy path works', async () => {
const steps = [
{command: `odo create ${componentType}:${version} ${componentItem.getName()} --local ${folder.uri.fsPath} --app ${appItem.getName()} --project ${projectItem.getName()}`, increment: 50},
{command: `odo push ${componentItem.getName()} --local ${folder.uri.fsPath} --app ${appItem.getName()} --project ${projectItem.getName()}`, increment: 50}
];
const result = await Component.create(appItem);

expect(result).equals(`Component '${componentItem.getName()}' successfully created`);
expect(progressStub).calledOnceWith(sinon.match.object, steps);
expect(progressCmdStub).calledOnceWith(
`Creating new component '${componentItem.getName()}'`,
`odo create ${componentType}:${version} ${componentItem.getName()} --local ${folder.uri.fsPath} --app ${appItem.getName()} --project ${projectItem.getName()}`);
expect(termStub).calledOnceWith(`odo push ${componentItem.getName()} --local ${folder.uri.fsPath} --app ${appItem.getName()} --project ${projectItem.getName()}`);
});

test('returns null when no folder selected', async () => {
Expand Down Expand Up @@ -126,13 +130,10 @@ suite('Openshift/Component', () => {
});

test('happy path works', async () => {
const steps = [
{command: `odo create ${componentType}:${version} ${componentItem.getName()} --git ${uri} --app ${appItem.getName()} --project ${projectItem.getName()}`, increment: 100}
];
const result = await Component.create(appItem);

expect(result).equals(`Component '${componentItem.getName()}' successfully created`);
expect(progressStub).calledOnceWith(sinon.match.object, steps);
expect(termStub).calledOnceWith(`odo create ${componentType}:${version} ${componentItem.getName()} --git ${uri} --app ${appItem.getName()} --project ${projectItem.getName()}`);
});

test('returns null when no git repo selected', async () => {
Expand Down Expand Up @@ -183,13 +184,13 @@ suite('Openshift/Component', () => {
});

test('happy path works', async () => {
const steps = [
{command: `odo create ${componentType}:${version} ${componentItem.getName()} --binary ${files[0].fsPath} --app ${appItem.getName()} --project ${projectItem.getName()}`, increment: 100}
];

const result = await Component.create(appItem);

expect(result).equals(`Component '${componentItem.getName()}' successfully created`);
expect(progressStub).calledOnceWith(sinon.match.object, steps);
expect(progressCmdStub).calledOnceWith(
`Creating new component '${componentItem.getName()}'`,
`odo create ${componentType}:${version} ${componentItem.getName()} --binary ${files[0].fsPath} --app ${appItem.getName()} --project ${projectItem.getName()}`);
});

test('returns null when no binary file selected', async () => {
Expand Down
11 changes: 4 additions & 7 deletions test/openshift/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,15 @@ suite('Openshift/Service', () => {
quickPickStub.onFirstCall().resolves(templateName);
quickPickStub.onSecondCall().resolves(templatePlan);
inputStub = sandbox.stub(vscode.window, 'showInputBox').resolves(serviceItem.getName());
progressStub = sandbox.stub(Progress, 'execWithProgress').resolves();
progressStub = sandbox.stub(Progress, 'execCmdWithProgress').resolves();
});

test('works with correct inputs', async () => {
const result = await Service.create(appItem);
const steps = [{
command: `odo service create ${templateName} --plan ${templatePlan} ${serviceItem.getName()} --app ${appItem.getName()} --project ${projectItem.getName()}`,
increment: 100
}];

expect(result).equals(`Service '${serviceItem.getName()}' successfully created`);
expect(progressStub).calledOnceWith(sinon.match.object, steps);
expect(progressStub).calledOnceWith(
`Creating new service '${serviceItem.getName()}'`,
`odo service create ${templateName} --plan ${templatePlan} ${serviceItem.getName()} --app ${appItem.getName()} --project ${projectItem.getName()}`);
});

test('returns null with no template selected', async () => {
Expand Down