Skip to content

Commit

Permalink
Fix issue for file name with space. (#299)
Browse files Browse the repository at this point in the history
* Fix issue for file name with space.
  • Loading branch information
sudhirverma committed May 25, 2020
1 parent 651ed2d commit a6382f6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
15 changes: 10 additions & 5 deletions src/tekton/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import * as vscode from 'vscode';
import { contextGlobalState } from '../extension';
import { tektonYaml } from '../yaml-support/tkn-yaml';
import { pipelineExplorer } from '../pipeline/pipelineExplorer';
import { getStderrString, Command, newK8sCommand } from '../tkn';

import { getStderrString, Command } from '../tkn';
import { Platform } from '../util/platform';

function checkDeploy(): boolean {
return vscode.workspace
Expand All @@ -34,7 +34,8 @@ export async function updateTektonResource(document: vscode.TextDocument): Promi
contextGlobalState.workspaceState.update(document.uri.fsPath, true);
}
if (verifyTknYaml && (/Deploy/.test(value) || contextGlobalState.workspaceState.get(document.uri.fsPath))) {
const result = await cli.execute(Command.create(document.uri.fsPath));
const quote = Platform.OS === 'win32' ? '"' : '\'';
const result = await cli.execute(Command.create(`${quote}${document.uri.fsPath}${quote}`));
if (result.error) {
const tempPath = os.tmpdir();
if (!tempPath) {
Expand All @@ -45,7 +46,11 @@ export async function updateTektonResource(document: vscode.TextDocument): Promi
let yamlData = '';
const resourceCheckRegex = /^(Task|PipelineResource|Pipeline|Condition|ClusterTask|EventListener|TriggerBinding)$/ as RegExp;
const fileContents = await fs.readFile(document.uri.fsPath, 'utf8');
const data: object[] = yaml.safeLoadAll(fileContents).filter((obj: {kind: string}) => resourceCheckRegex.test(obj.kind));
const data: object[] = yaml.safeLoadAll(fileContents).filter((obj: {kind: string}) => {
if (obj) {
return resourceCheckRegex.test(obj.kind)
}
});
if (data.length === 0) return;
data.map(value => {
const yamlStr = yaml.safeDump(value);
Expand All @@ -55,7 +60,7 @@ export async function updateTektonResource(document: vscode.TextDocument): Promi
} catch (err) {
// ignore
}
const apply = await cli.execute(newK8sCommand(`apply -f ${fsPath}`));
const apply = await cli.execute(Command.apply(`${quote}${fsPath}${quote}`));
await fs.unlink(fsPath);
if (apply.error) {
vscode.window.showErrorMessage(`Fail to deploy Resources: ${getStderrString(apply.error)}`);
Expand Down
3 changes: 3 additions & 0 deletions src/tkn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ export class Command {
static create(file: string): CliCommand {
return newK8sCommand('create', '--save-config','-f', file);
}
static apply(file: string): CliCommand {
return newK8sCommand('apply','-f', file);
}
}

export class TektonNodeImpl implements TektonNode {
Expand Down
10 changes: 7 additions & 3 deletions test/tekton/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ import { updateTektonResource } from '../../src/tekton/deploy';
import { contextGlobalState } from '../../src/extension';
import { tektonYaml } from '../../src/yaml-support/tkn-yaml';
import { pipelineExplorer } from '../../src/pipeline/pipelineExplorer';
import { Platform } from '../../src/util/platform';

const expect = chai.expect;
chai.use(sinonChai);

suite('Deploy File', () => {
const sandbox = sinon.createSandbox();
let execStub: sinon.SinonStub;
let quote: string;
let osStub: sinon.SinonStub;
let unlinkStub: sinon.SinonStub;
let writeFileStub: sinon.SinonStub;
Expand Down Expand Up @@ -123,6 +125,8 @@ suite('Deploy File', () => {
execStub = sandbox.stub(cli, 'execute').resolves();
sandbox.stub(pipelineExplorer, 'refresh').resolves();
sandbox.stub(tektonYaml, 'isTektonYaml').resolves('ClusterTask');
quote = Platform.OS === 'win32' ? '"' : '\'';

});

teardown(() => {
Expand All @@ -140,7 +144,7 @@ suite('Deploy File', () => {
workspaceStateGetStub.onFirstCall().returns(undefined);
showWarningMessageStub.onFirstCall().resolves('Deploy Once');
await updateTektonResource(textDocument);
expect(execStub).calledOnceWith(Command.create('workspace.yaml'));
expect(execStub).calledOnceWith(Command.create(`${quote}workspace.yaml${quote}`));
unlinkStub.calledOnce;
osStub.calledOnce;
readFileStub.calledOnce;
Expand All @@ -158,7 +162,7 @@ suite('Deploy File', () => {
});
workspaceStateGetStub.onFirstCall().returns('path');
await updateTektonResource(textDocument);
expect(execStub).calledOnceWith(Command.create('workspace.yaml'));
expect(execStub).calledOnceWith(Command.create(`${quote}workspace.yaml${quote}`));
showInformationMessageStub.calledOnce;
showWarningMessageStub.calledOnce;
workspaceStateGetStub.calledOnce;
Expand Down Expand Up @@ -211,7 +215,7 @@ suite('Deploy File', () => {
showWarningMessageStub.onFirstCall().resolves('Deploy');
workspaceStateUpdateStub.onFirstCall().resolves('path');
await updateTektonResource(textDocument);
expect(execStub).calledOnceWith(Command.create('workspace.yaml'));
expect(execStub).calledOnceWith(Command.create(`${quote}workspace.yaml${quote}`));
showInformationMessageStub.calledOnce;
showWarningMessageStub.calledOnce;
workspaceStateGetStub.calledOnce;
Expand Down

0 comments on commit a6382f6

Please sign in to comment.