Skip to content

Commit

Permalink
Fix test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dgolovin committed Jul 22, 2019
1 parent 80b1d60 commit 99233ff
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import open = require("open");
import { Build } from './k8s/build';

let clusterExplorer: k8s.ClusterExplorerV1 | undefined = undefined;
import { Odo, OdoImpl } from './odo';
import { OdoImpl } from './odo';

export let contextGlobalState: vscode.ExtensionContext;

Expand Down
8 changes: 4 additions & 4 deletions src/k8s/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export class Build {
protected static readonly odo: Odo = OdoImpl.Instance;

static async getQuickPicks(cmd: string, errorMessage: string): Promise<QuickPickItem[]> {
const names: string[] = [];
const result = await Build.odo.execute(cmd);
const json: JSON = JSON.parse(result.stdout);
if (json['items'].length === 0) {
Expand All @@ -113,7 +112,7 @@ export class Build {
}

static async selectBuild(context: any, text: string): Promise<string> {
let build: string;
let build: string = null;
if (context) {
build = context.impl.name;
} else {
Expand All @@ -133,7 +132,7 @@ export class Build {

static async startBuild(context: { id: any; }): Promise<string> {
let buildName: string = context ? context.id : undefined;
let result: Promise<string>;
let result: Promise<string> = null;
if (!buildName) buildName = await Build.selectBuldConfig("Select a BuildConfig to start a build");
if (buildName) {
result = Progress.execFunctionWithProgress(`Starting build`, () => Build.odo.execute(Command.startBuild(buildName)))
Expand All @@ -143,11 +142,12 @@ export class Build {
return result;
}

static async showLog(context: { impl: any; }): Promise<void> {
static async showLog(context: { impl: any; }): Promise<string> {
const build = await Build.selectBuild(context, "Select a build too see the logs");
if (build) {
Build.odo.executeInTerminal(Command.showLog(build, '-build'));
}
return build;
}

static async rebuild(context: { id?: string; impl: any; }): Promise<string> {
Expand Down
1 change: 0 additions & 1 deletion test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import packagejson = require('../package.json');
import { OpenShiftExplorer } from '../src/explorer';
import path = require('path');
import { OdoImpl, ContextType, OpenShiftObjectImpl } from '../src/odo';
import { TestItem } from './openshift/testOSItem';

const expect = chai.expect;
chai.use(sinonChai);
Expand Down
37 changes: 29 additions & 8 deletions test/k8s/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ suite('K8s/build', () => {
resourceId: "bc/nodejs-comp-nodejs-app"
};

const noBcData = `{
"apiVersion": "v1",
"items": [],
"kind": "List",
"metadata": {
"resourceVersion": "",
"selfLink": ""
}
}`;

const mockData = `{
"apiVersion": "v1",
"items": [
Expand Down Expand Up @@ -115,7 +125,7 @@ suite('K8s/build', () => {
setup(() => {
execStub.resolves({ error: undefined, stdout: mockData, stderr: '' });
quickPickStub = sandbox.stub(vscode.window, 'showQuickPick');
quickPickStub.resolves("nodejs-comp-nodejs-app");
quickPickStub.resolves({label: "nodejs-comp-nodejs-app"});
});

test('works from context menu', async () => {
Expand All @@ -132,7 +142,7 @@ suite('K8s/build', () => {
expect(execStub).calledWith(Command.startBuild(context.id));
});

test('returns null when no build selected', async () => {
test('returns null when no BuildConfig selected', async () => {
quickPickStub.resolves();
const result = await Build.startBuild(null);
expect(result).null;
Expand All @@ -147,15 +157,26 @@ suite('K8s/build', () => {
expect(err).equals(`Failed to start build with error '${errorMessage}'`);
}
});

test('throws error if there is no BuildConfigs to select', async () => {
execStub.resolves({ error: undefined, stdout: noBcData, stderr: '' });
try {
await Build.startBuild(null);
} catch (err) {
expect(err).equals(`Failed to start build with error '${errorMessage}'`);
}
});
});

suite('Show Log', () => {

setup(() => {
execStub.resolves({ error: null, stdout: buildData, stderr: '' });
sandbox.stub(Build, 'getBuildNames').resolves("nodejs-copm-nodejs-comp");
const buidConfig = {label: "nodejs-copm-nodejs-comp"};
sandbox.stub(Build, 'getBuildConfigNames').resolves([buidConfig]);
quickPickStub = sandbox.stub(vscode.window, 'showQuickPick');
quickPickStub.onFirstCall().resolves("nodejs-copm-nodejs-comp-8");
quickPickStub.onFirstCall().resolves(buidConfig);
quickPickStub.onSecondCall().resolves({label: "nodejs-copm-nodejs-comp-8"});
});

test('works from context menu', async () => {
Expand All @@ -169,7 +190,7 @@ suite('K8s/build', () => {
});

test('returns null when no build selected', async () => {
quickPickStub.onFirstCall().resolves();
quickPickStub.onSecondCall().resolves();
const result = await Build.showLog(null);
expect(result).null;
});
Expand All @@ -180,7 +201,7 @@ suite('K8s/build', () => {
setup(() => {
sandbox.stub(Build, 'getBuildNames').resolves("nodejs-copm-nodejs-comp");
quickPickStub = sandbox.stub(vscode.window, 'showQuickPick');
quickPickStub.resolves("nodejs-copm-nodejs-comp-8");
quickPickStub.resolves({label: "nodejs-copm-nodejs-comp-8"});

});

Expand Down Expand Up @@ -212,7 +233,7 @@ suite('K8s/build', () => {
execStub.resolves({ error: null, stdout: buildData, stderr: '' });
sandbox.stub(Build, 'getBuildNames').resolves("nodejs-copm-nodejs-comp");
quickPickStub = sandbox.stub(vscode.window, 'showQuickPick');
quickPickStub.resolves("nodejs-copm-nodejs-comp-8");
quickPickStub.resolves({label: "nodejs-copm-nodejs-comp-8"});
});

test('works from context menu', async () => {
Expand All @@ -237,7 +258,7 @@ suite('K8s/build', () => {
execStub.resolves({ error: null, stdout: buildData, stderr: '' });
sandbox.stub(Build, 'getBuildNames').resolves("nodejs-copm-nodejs-comp");
quickPickStub = sandbox.stub(vscode.window, 'showQuickPick');
quickPickStub.resolves("nodejs-copm-nodejs-comp-8");
quickPickStub.resolves({label: "nodejs-copm-nodejs-comp-8"});
});

test('works from context menu', async () => {
Expand Down

0 comments on commit 99233ff

Please sign in to comment.