Skip to content

Commit 7692ff6

Browse files
authored
Check outputFormat when it is not provided as input. (#13188)
1 parent c9a6131 commit 7692ff6

File tree

5 files changed

+35
-17
lines changed

5 files changed

+35
-17
lines changed

Tasks/KubernetesV1/Tests/L0.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ describe('Kubernetes Suite', function() {
1313
beforeEach(() => {
1414
process.env[shared.isKubectlPresentOnMachine] = "true";
1515
process.env[shared.endpointAuthorizationType] = "Kubeconfig";
16+
process.env[shared.TestEnvVars.outputFormat] = 'json';
1617
delete process.env[shared.TestEnvVars.command];
1718
delete process.env[shared.TestEnvVars.containerType];
1819
delete process.env[shared.TestEnvVars.connectionType];
@@ -33,7 +34,6 @@ describe('Kubernetes Suite', function() {
3334
delete process.env[shared.TestEnvVars.useConfigMapFile];
3435
delete process.env[shared.TestEnvVars.configMapFile];
3536
delete process.env[shared.TestEnvVars.configMapArguments];
36-
delete process.env[shared.TestEnvVars.outputFormat];
3737
delete process.env[shared.TestEnvVars.configuration];
3838
delete process.env["chmodShouldThrowError"];
3939
});
@@ -485,6 +485,23 @@ describe('Kubernetes Suite', function() {
485485
process.env[shared.TestEnvVars.outputFormat] = 'none';
486486
tr.run();
487487

488+
assert(tr.invokedToolCount == 1, 'should have invoked tool one times. actual: ' + tr.invokedToolCount);
489+
assert(tr.stderr.length == 0 || tr.errorIssues.length, 'should not have written to stderr');
490+
assert(tr.succeeded, 'task should have succeeded');
491+
assert(tr.stdout.indexOf(`Skipping -o in args as outputFormat is 'none' or empty.`) != -1, 'outputFormat skipped');
492+
assert(tr.stdout.indexOf(`[command]kubectl create secrets my-secret`) != -1, "kubectl create should run");
493+
console.log(tr.stderr);
494+
done();
495+
});
496+
497+
it('Runs successfully for kubectl create and skip print for empty outputFormat', (done:MochaDone) => {
498+
let tp = path.join(__dirname, 'TestSetup.js');
499+
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
500+
process.env[shared.TestEnvVars.command] = shared.Commands.create;
501+
process.env[shared.TestEnvVars.arguments] = "secrets my-secret";
502+
process.env[shared.TestEnvVars.outputFormat] = '';
503+
tr.run();
504+
488505
assert(tr.invokedToolCount == 1, 'should have invoked tool one times. actual: ' + tr.invokedToolCount);
489506
assert(tr.stderr.length == 0 || tr.errorIssues.length, 'should not have written to stderr');
490507
assert(tr.succeeded, 'task should have succeeded');
@@ -509,7 +526,6 @@ describe('Kubernetes Suite', function() {
509526
done();
510527
});
511528

512-
513529
it('Runs successfully for checking whether secrets, configmaps and kubectl commands are run in a consecutive manner', (done:MochaDone) => {
514530
let tp = path.join(__dirname, 'TestSetup.js');
515531
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);

Tasks/KubernetesV1/Tests/TestSetup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ tr.setInput('versionOrLocation', process.env[shared.TestEnvVars.versionOrLocatio
3939
tr.setInput('versionSpec', process.env[shared.TestEnvVars.versionSpec] || "1.13.2");
4040
tr.setInput('checkLatest', process.env[shared.TestEnvVars.checkLatest] || "false");
4141
tr.setInput('specifyLocation', process.env[shared.TestEnvVars.specifyLocation] || "");
42-
tr.setInput('outputFormat', process.env[shared.TestEnvVars.outputFormat] || 'json');
42+
tr.setInput('outputFormat', process.env[shared.TestEnvVars.outputFormat]);
4343
tr.setInput('dockerRegistryEndpoint', 'dockerhubendpoint');
4444
tr.setInput('kubernetesServiceEndpoint', 'kubernetesEndpoint');
4545
tr.setInput('azureSubscriptionEndpoint', 'AzureRMSpn');

Tasks/KubernetesV1/src/kubernetescommand.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,21 @@ export function run(connection: ClusterConnection, kubecommand: string, outputUp
2525
function getCommandOutputFormat(kubecommand: string): string[] {
2626
var args: string[] = [];
2727
var outputFormat = tl.getInput("outputFormat", false);
28-
switch (outputFormat) {
29-
case '':
30-
case 'none':
31-
tl.debug(`Skipping -o in args as outputFormat is 'none' or empty.`);
32-
return args;
33-
case 'json':
34-
case 'yaml':
35-
if (!isJsonOrYamlOutputFormatSupported(kubecommand)) {
28+
if (outputFormat) {
29+
switch (outputFormat) {
30+
case '':
31+
case 'none':
32+
tl.debug(`Skipping -o in args as outputFormat is 'none' or empty.`);
3633
return args;
37-
}
38-
default:
39-
args[0] = "-o";
40-
args[1] = outputFormat;
34+
case 'json':
35+
case 'yaml':
36+
if (!isJsonOrYamlOutputFormatSupported(kubecommand)) {
37+
return args;
38+
}
39+
default:
40+
args[0] = "-o";
41+
args[1] = outputFormat;
42+
}
4143
}
4244
return args;
4345
}

Tasks/KubernetesV1/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 1,
1616
"Minor": 171,
17-
"Patch": 0
17+
"Patch": 1
1818
},
1919
"demands": [],
2020
"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.",

Tasks/KubernetesV1/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 1,
1616
"Minor": 171,
17-
"Patch": 0
17+
"Patch": 1
1818
},
1919
"demands": [],
2020
"releaseNotes": "ms-resource:loc.releaseNotes",

0 commit comments

Comments
 (0)