diff --git a/src/openshift/component.ts b/src/openshift/component.ts index dd27f0a00..9f7db068a 100644 --- a/src/openshift/component.ts +++ b/src/openshift/component.ts @@ -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'); @@ -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 { @@ -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 { @@ -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`); } } \ No newline at end of file diff --git a/src/openshift/openshiftItem.ts b/src/openshift/openshiftItem.ts index 970e19b55..43501a303 100644 --- a/src/openshift/openshiftItem.ts +++ b/src/openshift/openshiftItem.ts @@ -12,4 +12,5 @@ export abstract class OpenShiftItem { static create(context: OpenShiftObject): Promise { return Promise.reject(); } static del(context: OpenShiftObject): Promise { return Promise.reject(); } + static wait(timeout: number = 2500): Promise { return new Promise((res)=>setTimeout(res, timeout)); } } \ No newline at end of file diff --git a/src/openshift/service.ts b/src/openshift/service.ts index c7a144443..8a44394e2 100644 --- a/src/openshift/service.ts +++ b/src/openshift/service.ts @@ -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}'`)); @@ -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 { diff --git a/test/openshift/component.test.ts b/test/openshift/component.test.ts index 4cab88dde..0d3d682ec 100644 --- a/test/openshift/component.test.ts +++ b/test/openshift/component.test.ts @@ -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(() => { @@ -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'); @@ -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 () => { @@ -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 () => { @@ -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 () => { @@ -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 () => { diff --git a/test/openshift/service.test.ts b/test/openshift/service.test.ts index 60a32f807..32359b6ef 100644 --- a/test/openshift/service.test.ts +++ b/test/openshift/service.test.ts @@ -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 () => {