Skip to content

Commit f5dfdbc

Browse files
mohitsumandgolovin
authored andcommitted
fix open browser call if url creation is halted/cancelled (#702)
1 parent 6a771c0 commit f5dfdbc

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

src/openshift/component.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,22 +175,26 @@ export class Component extends OpenShiftItem {
175175
if (!component) return null;
176176
const app: OpenShiftObject = component.getParent();
177177
const namespace: string = app.getParent().getName();
178-
const routeCheck = await Component.odo.execute(Command.getRouteHostName(namespace, component.getName()));
179-
let value = 'Create';
180-
if (routeCheck.stdout.trim() === '') {
181-
value = await vscode.window.showInformationMessage(`No URL for Component '${component.getName()}' in Application '${app.getName()}'. Do you want to create a URL and open it?`, 'Create', 'Cancel');
178+
if (await Component.checkRouteCreated(namespace, component)) {
179+
const value = await vscode.window.showInformationMessage(`No URL for Component '${component.getName()}' in Application '${app.getName()}'. Do you want to create a URL and open it?`, 'Create', 'Cancel');
182180
if (value === 'Create') {
183181
await vscode.commands.executeCommand('openshift.url.create', component);
184182
}
185183
}
186-
if (value === 'Create') {
184+
185+
if (! await Component.checkRouteCreated(namespace, component)) {
187186
const hostName = await Component.odo.execute(Command.getRouteHostName(namespace, component.getName()));
188187
const checkTls = await Component.odo.execute(Command.getRouteTls(namespace, component.getName()));
189188
const tls = checkTls.stdout.trim().length === 0 ? "http://" : "https://";
190189
return opn(`${tls}${hostName.stdout}`);
191190
}
192191
}
193192

193+
static async checkRouteCreated(namespace: string, component: OpenShiftObject): Promise<boolean> {
194+
const routeCheck = await Component.odo.execute(Command.getRouteHostName(namespace, component.getName()));
195+
return routeCheck.stdout.trim() === '';
196+
}
197+
194198
static async createFromLocal(context: OpenShiftObject): Promise<string> {
195199
let application: OpenShiftObject = context;
196200
if (!application) application = await Component.getOpenshiftData(context);

test/openshift/component.test.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -741,19 +741,21 @@ suite('OpenShift/Component', () => {
741741
});
742742

743743
test('gets url for component and opens it in browser', async () => {
744-
execStub.onFirstCall().resolves({error: undefined, stdout: 'url', stderr: ''});
745-
execStub.onSecondCall().resolves({error: undefined, stdout: 'url', stderr: ''});
746-
execStub.onThirdCall().resolves({error: undefined, stdout: 'tlsEnabled', stderr: ''});
744+
execStub.onCall(0).resolves({error: undefined, stdout: 'url', stderr: ''});
745+
execStub.onCall(1).resolves({error: undefined, stdout: 'url', stderr: ''});
746+
execStub.onCall(2).resolves({error: undefined, stdout: 'url', stderr: ''});
747+
execStub.onCall(3).resolves({error: undefined, stdout: 'tlsEnabled', stderr: ''});
747748
await Component.openUrl(null);
748749
expect(opnStub).calledOnceWith('https://url');
749750
});
750751

751-
test('request to create url for component if it does not exist, creates it if confirmed by user and opens in in browser.' , async () => {
752+
test('request to create url for component if it does not exist, creates the route if confirmed by user and opens it in browser.' , async () => {
752753
sandbox.stub(vscode.window, 'showInformationMessage').resolves('Create');
753754
sandbox.stub(vscode.commands, 'executeCommand').resolves();
754-
execStub.onFirstCall().resolves({error: undefined, stdout: '', stderr: ''});
755-
execStub.onSecondCall().resolves({error: undefined, stdout: 'url', stderr: ''});
756-
execStub.onThirdCall().resolves({error: undefined, stdout: 'tlsEnabled', stderr: ''});
755+
execStub.onCall(0).resolves({error: undefined, stdout: '', stderr: ''});
756+
execStub.onCall(1).resolves({error: undefined, stdout: 'url', stderr: ''});
757+
execStub.onCall(2).resolves({error: undefined, stdout: 'url', stderr: ''});
758+
execStub.onCall(3).resolves({error: undefined, stdout: 'tlsEnabled', stderr: ''});
757759
await Component.openUrl(null);
758760
expect(opnStub).calledOnceWith('https://url');
759761
});

0 commit comments

Comments
 (0)