Skip to content

Commit

Permalink
Check outputFormat when it is not provided as input. (#13186)
Browse files Browse the repository at this point in the history
* Check outputFormat when it is not provided as input.

* Test cases and addressed comments
  • Loading branch information
koushdey authored Jun 26, 2020
1 parent e2ae64d commit 541a14e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
21 changes: 19 additions & 2 deletions Tasks/KubernetesV1/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('Kubernetes Suite', function() {
beforeEach(() => {
process.env[shared.isKubectlPresentOnMachine] = "true";
process.env[shared.endpointAuthorizationType] = "Kubeconfig";
process.env[shared.TestEnvVars.outputFormat] = 'json';
delete process.env[shared.TestEnvVars.command];
delete process.env[shared.TestEnvVars.containerType];
delete process.env[shared.TestEnvVars.connectionType];
Expand All @@ -33,7 +34,6 @@ describe('Kubernetes Suite', function() {
delete process.env[shared.TestEnvVars.useConfigMapFile];
delete process.env[shared.TestEnvVars.configMapFile];
delete process.env[shared.TestEnvVars.configMapArguments];
delete process.env[shared.TestEnvVars.outputFormat];
delete process.env[shared.TestEnvVars.configuration];
delete process.env["chmodShouldThrowError"];
});
Expand Down Expand Up @@ -488,6 +488,24 @@ describe('Kubernetes Suite', function() {
assert(tr.invokedToolCount == 1, 'should have invoked tool one times. actual: ' + tr.invokedToolCount);
assert(tr.stderr.length == 0 || tr.errorIssues.length, 'should not have written to stderr');
assert(tr.succeeded, 'task should have succeeded');
assert(tr.stdout.indexOf(`Skipping -o in args as outputFormat is 'none' or empty.`) != -1, 'outputFormat skipped');
assert(tr.stdout.indexOf(`[command]kubectl create secrets my-secret`) != -1, "kubectl create should run");
console.log(tr.stderr);
done();
});

it('Runs successfully for kubectl create and skip print for empty outputFormat', (done:MochaDone) => {
let tp = path.join(__dirname, 'TestSetup.js');
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
process.env[shared.TestEnvVars.command] = shared.Commands.create;
process.env[shared.TestEnvVars.arguments] = "secrets my-secret";
process.env[shared.TestEnvVars.outputFormat] = '';
tr.run();

assert(tr.invokedToolCount == 1, 'should have invoked tool one times. actual: ' + tr.invokedToolCount);
assert(tr.stderr.length == 0 || tr.errorIssues.length, 'should not have written to stderr');
assert(tr.succeeded, 'task should have succeeded');
assert(tr.stdout.indexOf(`Skipping -o in args as outputFormat is 'none' or empty.`) != -1, 'outputFormat skipped');
assert(tr.stdout.indexOf(`[command]kubectl create secrets my-secret`) != -1, "kubectl create should run");
console.log(tr.stderr);
done();
Expand All @@ -509,7 +527,6 @@ describe('Kubernetes Suite', function() {
done();
});


it('Runs successfully for checking whether secrets, configmaps and kubectl commands are run in a consecutive manner', (done:MochaDone) => {
let tp = path.join(__dirname, 'TestSetup.js');
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
Expand Down
2 changes: 1 addition & 1 deletion Tasks/KubernetesV1/Tests/TestSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ tr.setInput('versionOrLocation', process.env[shared.TestEnvVars.versionOrLocatio
tr.setInput('versionSpec', process.env[shared.TestEnvVars.versionSpec] || "1.13.2");
tr.setInput('checkLatest', process.env[shared.TestEnvVars.checkLatest] || "false");
tr.setInput('specifyLocation', process.env[shared.TestEnvVars.specifyLocation] || "");
tr.setInput('outputFormat', process.env[shared.TestEnvVars.outputFormat] || 'json');
tr.setInput('outputFormat', process.env[shared.TestEnvVars.outputFormat]);
tr.setInput('dockerRegistryEndpoint', 'dockerhubendpoint');
tr.setInput('kubernetesServiceEndpoint', 'kubernetesEndpoint');
tr.setInput('azureSubscriptionEndpoint', 'AzureRMSpn');
Expand Down
1 change: 1 addition & 0 deletions Tasks/KubernetesV1/src/kubernetescommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function getCommandOutputFormat(kubecommand: string): string[] {
var args: string[] = [];
var outputFormat = tl.getInput("outputFormat", false);
switch (outputFormat) {
case null:
case '':
case 'none':
tl.debug(`Skipping -o in args as outputFormat is 'none' or empty.`);
Expand Down
2 changes: 1 addition & 1 deletion Tasks/KubernetesV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 1,
"Minor": 171,
"Patch": 0
"Patch": 1
},
"demands": [],
"releaseNotes": "What's new in Version 1.0:<br/>&nbsp;Added new service connection type input for easy selection of Azure AKS cluster.<br/>&nbsp;Replaced output variable input with output variables section that we had added in all tasks.",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/KubernetesV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 1,
"Minor": 171,
"Patch": 0
"Patch": 1
},
"demands": [],
"releaseNotes": "ms-resource:loc.releaseNotes",
Expand Down

0 comments on commit 541a14e

Please sign in to comment.