Skip to content

Commit c5225dc

Browse files
AzureTestPlanTask: Implemented support for Go Language (#20006)
* Added change * Added go new changes * Added final status for goinvoker * Added GoTestName in tl.debug --------- Co-authored-by: triptijain2112 <[email protected]>
1 parent c51b91b commit c5225dc

19 files changed

+190
-43
lines changed
+28-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
11
import tl = require('azure-pipelines-task-lib/task');
22
import utils = require('../utils');
33
import constants = require('../constants');
4+
import tr = require("azure-pipelines-task-lib/toolrunner");
5+
import { executeGoCommand } from '../testLibExecutor';
46

7+
//GO command like "gotestsum --junitfile TEST-Go<i>-junit.xml -- <filepath> -v -run ^<TestName>$"
58
export async function executeGoTests(testsToBeExecuted: string[]): Promise<number> {
69

7-
//Go execution will be added
8-
/*executable = go;
9-
args = test, ./...
10-
spawn*/
11-
12-
console.log("Go changes1");
13-
return 1;
14-
}
10+
let finalStatus = 0;
11+
let goPath = tl.which("go", true);
12+
await executeGoCommand(goPath, constants.INSTALL_GOTESTSUM);
13+
tl.debug("Installed Gotestsum");
1514

15+
//testsToBeExecuted: go.mod/01-normal/normal.Test1,go.mod/01-normal/normal.Test11,go.mod/04-testmain.Test1,go.mod/05-parallel.TestSumParalel
16+
goPath = tl.which("gotestsum", true);
17+
let i = 0;
18+
for (let tests of testsToBeExecuted) {
19+
const GoTestPath = utils.separateGoPath(tests);
20+
const GoTestName = utils.separateGoTestName(tests);
21+
try {
22+
const argument = `--junitfile TEST-Go${i}-junit.xml -- ${GoTestPath} -v -run ^${GoTestName}$`;
23+
const status = await executeGoCommand(goPath, argument);
24+
if (status != 0) {
25+
finalStatus = 1;
26+
}
27+
tl.debug(`Test case ${GoTestName} executed successfully.`);
28+
} catch (error) {
29+
tl.debug(`Error executing ${GoTestName} test case: ${error}`);
30+
finalStatus = 1;
31+
}
32+
i++;
33+
}
34+
return finalStatus;
35+
}

Tasks/AzureTestPlanV0/constants.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ export const NOT_AUTOMATED = 'Not Automated'
1111
export const MERGE_THRESHOLD = 100;
1212
export const AUTOMATED_EXECUTION = "AutomatedExecutionPhase";
1313
export const AUTOMATED_PUBLISHING = "PublishingAutomatedResultsPhase";
14-
export const MANUALTESTS_PUBLISHING = "ManualTestResultsPublishingPhase";
14+
export const MANUALTESTS_PUBLISHING = "ManualTestResultsPublishingPhase";
15+
export const INSTALL_GOTESTSUM = "install gotest.tools/gotestsum@latest";

Tasks/AzureTestPlanV0/task.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 0,
1616
"Minor": 241,
17-
"Patch": 2
17+
"Patch": 4
1818
},
1919
"preview": true,
2020
"demands": [],

Tasks/AzureTestPlanV0/task.loc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 0,
1616
"Minor": 241,
17-
"Patch": 2
17+
"Patch": 4
1818
},
1919
"preview": true,
2020
"demands": [],

Tasks/AzureTestPlanV0/testLibExecutor.ts

+6
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,10 @@ export async function execGradleBuild(args: string[]): Promise<number> {
158158
tl.setResult(tl.TaskResult.Failed, "Build failed."); // Set the step result to Failed
159159
return 1; // Return 1 indicating failure
160160
}
161+
}
162+
163+
export async function executeGoCommand(goPath: string, argument: string): Promise<number> {
164+
let go: tr.ToolRunner = tl.tool(goPath);
165+
go.line(argument);
166+
return await go.exec(<tr.IExecOptions>{ cwd: "" });
161167
}

Tasks/AzureTestPlanV0/utils.ts

+22
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,25 @@ export function replaceLastDotWithHash(inputString) {
2121
}
2222
}
2323

24+
export function separateGoPath(inputString) {
25+
const lastDotIndex = inputString.lastIndexOf('.');
26+
27+
if (lastDotIndex !== -1) {
28+
const stringWith = inputString.slice(0, lastDotIndex);
29+
return stringWith;
30+
} else {
31+
// If there is no dot in the string, return the original string
32+
return inputString;
33+
}
34+
}
35+
export function separateGoTestName(inputString) {
36+
const lastDotIndex = inputString.lastIndexOf('.');
37+
38+
if (lastDotIndex !== -1) {
39+
const stringWith = inputString.slice(lastDotIndex + 1);
40+
return stringWith;
41+
} else {
42+
// If there is no dot in the string, return the original string
43+
return inputString;
44+
}
45+
}
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Default|0.241.2
2-
Node20-225|0.241.3
1+
Default|0.241.4
2+
Node20-225|0.241.5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
11
import tl = require('azure-pipelines-task-lib/task');
22
import utils = require('../utils');
33
import constants = require('../constants');
4+
import tr = require("azure-pipelines-task-lib/toolrunner");
5+
import { executeGoCommand } from '../testLibExecutor';
46

7+
//GO command like "gotestsum --junitfile TEST-Go<i>-junit.xml -- <filepath> -v -run ^<TestName>$"
58
export async function executeGoTests(testsToBeExecuted: string[]): Promise<number> {
69

7-
//Go execution will be added
8-
/*executable = go;
9-
args = test, ./...
10-
spawn*/
11-
12-
console.log("Go changes1");
13-
return 1;
14-
}
10+
let finalStatus = 0;
11+
let goPath = tl.which("go", true);
12+
await executeGoCommand(goPath, constants.INSTALL_GOTESTSUM);
13+
tl.debug("Installed Gotestsum");
1514

15+
//testsToBeExecuted: go.mod/01-normal/normal.Test1,go.mod/01-normal/normal.Test11,go.mod/04-testmain.Test1,go.mod/05-parallel.TestSumParalel
16+
goPath = tl.which("gotestsum", true);
17+
let i = 0;
18+
for (let tests of testsToBeExecuted) {
19+
const GoTestPath = utils.separateGoPath(tests);
20+
const GoTestName = utils.separateGoTestName(tests);
21+
try {
22+
const argument = `--junitfile TEST-Go${i}-junit.xml -- ${GoTestPath} -v -run ^${GoTestName}$`;
23+
const status = await executeGoCommand(goPath, argument);
24+
if (status != 0) {
25+
finalStatus = 1;
26+
}
27+
tl.debug(`Test case ${GoTestName} executed successfully.`);
28+
} catch (error) {
29+
tl.debug(`Error executing ${GoTestName} test case: ${error}`);
30+
finalStatus = 1;
31+
}
32+
i++;
33+
}
34+
return finalStatus;
35+
}

_generated/AzureTestPlanV0/constants.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ export const NOT_AUTOMATED = 'Not Automated'
1111
export const MERGE_THRESHOLD = 100;
1212
export const AUTOMATED_EXECUTION = "AutomatedExecutionPhase";
1313
export const AUTOMATED_PUBLISHING = "PublishingAutomatedResultsPhase";
14-
export const MANUALTESTS_PUBLISHING = "ManualTestResultsPublishingPhase";
14+
export const MANUALTESTS_PUBLISHING = "ManualTestResultsPublishingPhase";
15+
export const INSTALL_GOTESTSUM = "install gotest.tools/gotestsum@latest";

_generated/AzureTestPlanV0/task.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 0,
1616
"Minor": 241,
17-
"Patch": 2
17+
"Patch": 4
1818
},
1919
"preview": true,
2020
"demands": [],
@@ -177,7 +177,7 @@
177177
"MultipleMatchingGradlewFound": "Multiple gradlew files found. Selecting the first matched instance"
178178
},
179179
"_buildConfigMapping": {
180-
"Default": "0.241.2",
181-
"Node20-225": "0.241.3"
180+
"Default": "0.241.4",
181+
"Node20-225": "0.241.5"
182182
}
183183
}

_generated/AzureTestPlanV0/task.loc.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 0,
1616
"Minor": 241,
17-
"Patch": 2
17+
"Patch": 4
1818
},
1919
"preview": true,
2020
"demands": [],
@@ -177,7 +177,7 @@
177177
"MultipleMatchingGradlewFound": "ms-resource:loc.messages.MultipleMatchingGradlewFound"
178178
},
179179
"_buildConfigMapping": {
180-
"Default": "0.241.2",
181-
"Node20-225": "0.241.3"
180+
"Default": "0.241.4",
181+
"Node20-225": "0.241.5"
182182
}
183183
}

_generated/AzureTestPlanV0/testLibExecutor.ts

+6
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,10 @@ export async function execGradleBuild(args: string[]): Promise<number> {
158158
tl.setResult(tl.TaskResult.Failed, "Build failed."); // Set the step result to Failed
159159
return 1; // Return 1 indicating failure
160160
}
161+
}
162+
163+
export async function executeGoCommand(goPath: string, argument: string): Promise<number> {
164+
let go: tr.ToolRunner = tl.tool(goPath);
165+
go.line(argument);
166+
return await go.exec(<tr.IExecOptions>{ cwd: "" });
161167
}

_generated/AzureTestPlanV0/utils.ts

+22
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,25 @@ export function replaceLastDotWithHash(inputString) {
2121
}
2222
}
2323

24+
export function separateGoPath(inputString) {
25+
const lastDotIndex = inputString.lastIndexOf('.');
26+
27+
if (lastDotIndex !== -1) {
28+
const stringWith = inputString.slice(0, lastDotIndex);
29+
return stringWith;
30+
} else {
31+
// If there is no dot in the string, return the original string
32+
return inputString;
33+
}
34+
}
35+
export function separateGoTestName(inputString) {
36+
const lastDotIndex = inputString.lastIndexOf('.');
37+
38+
if (lastDotIndex !== -1) {
39+
const stringWith = inputString.slice(lastDotIndex + 1);
40+
return stringWith;
41+
} else {
42+
// If there is no dot in the string, return the original string
43+
return inputString;
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
11
import tl = require('azure-pipelines-task-lib/task');
22
import utils = require('../utils');
33
import constants = require('../constants');
4+
import tr = require("azure-pipelines-task-lib/toolrunner");
5+
import { executeGoCommand } from '../testLibExecutor';
46

7+
//GO command like "gotestsum --junitfile TEST-Go<i>-junit.xml -- <filepath> -v -run ^<TestName>$"
58
export async function executeGoTests(testsToBeExecuted: string[]): Promise<number> {
69

7-
//Go execution will be added
8-
/*executable = go;
9-
args = test, ./...
10-
spawn*/
11-
12-
console.log("Go changes1");
13-
return 1;
14-
}
10+
let finalStatus = 0;
11+
let goPath = tl.which("go", true);
12+
await executeGoCommand(goPath, constants.INSTALL_GOTESTSUM);
13+
tl.debug("Installed Gotestsum");
1514

15+
//testsToBeExecuted: go.mod/01-normal/normal.Test1,go.mod/01-normal/normal.Test11,go.mod/04-testmain.Test1,go.mod/05-parallel.TestSumParalel
16+
goPath = tl.which("gotestsum", true);
17+
let i = 0;
18+
for (let tests of testsToBeExecuted) {
19+
const GoTestPath = utils.separateGoPath(tests);
20+
const GoTestName = utils.separateGoTestName(tests);
21+
try {
22+
const argument = `--junitfile TEST-Go${i}-junit.xml -- ${GoTestPath} -v -run ^${GoTestName}$`;
23+
const status = await executeGoCommand(goPath, argument);
24+
if (status != 0) {
25+
finalStatus = 1;
26+
}
27+
tl.debug(`Test case ${GoTestName} executed successfully.`);
28+
} catch (error) {
29+
tl.debug(`Error executing ${GoTestName} test case: ${error}`);
30+
finalStatus = 1;
31+
}
32+
i++;
33+
}
34+
return finalStatus;
35+
}

_generated/AzureTestPlanV0_Node20/constants.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ export const NOT_AUTOMATED = 'Not Automated'
1111
export const MERGE_THRESHOLD = 100;
1212
export const AUTOMATED_EXECUTION = "AutomatedExecutionPhase";
1313
export const AUTOMATED_PUBLISHING = "PublishingAutomatedResultsPhase";
14-
export const MANUALTESTS_PUBLISHING = "ManualTestResultsPublishingPhase";
14+
export const MANUALTESTS_PUBLISHING = "ManualTestResultsPublishingPhase";
15+
export const INSTALL_GOTESTSUM = "install gotest.tools/gotestsum@latest";

_generated/AzureTestPlanV0_Node20/task.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 0,
1616
"Minor": 241,
17-
"Patch": 3
17+
"Patch": 5
1818
},
1919
"preview": true,
2020
"demands": [],
@@ -181,7 +181,7 @@
181181
"MultipleMatchingGradlewFound": "Multiple gradlew files found. Selecting the first matched instance"
182182
},
183183
"_buildConfigMapping": {
184-
"Default": "0.241.2",
185-
"Node20-225": "0.241.3"
184+
"Default": "0.241.4",
185+
"Node20-225": "0.241.5"
186186
}
187187
}

_generated/AzureTestPlanV0_Node20/task.loc.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 0,
1616
"Minor": 241,
17-
"Patch": 3
17+
"Patch": 5
1818
},
1919
"preview": true,
2020
"demands": [],
@@ -181,7 +181,7 @@
181181
"MultipleMatchingGradlewFound": "ms-resource:loc.messages.MultipleMatchingGradlewFound"
182182
},
183183
"_buildConfigMapping": {
184-
"Default": "0.241.2",
185-
"Node20-225": "0.241.3"
184+
"Default": "0.241.4",
185+
"Node20-225": "0.241.5"
186186
}
187187
}

_generated/AzureTestPlanV0_Node20/testLibExecutor.ts

+6
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,10 @@ export async function execGradleBuild(args: string[]): Promise<number> {
158158
tl.setResult(tl.TaskResult.Failed, "Build failed."); // Set the step result to Failed
159159
return 1; // Return 1 indicating failure
160160
}
161+
}
162+
163+
export async function executeGoCommand(goPath: string, argument: string): Promise<number> {
164+
let go: tr.ToolRunner = tl.tool(goPath);
165+
go.line(argument);
166+
return await go.exec(<tr.IExecOptions>{ cwd: "" });
161167
}

_generated/AzureTestPlanV0_Node20/utils.ts

+22
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,25 @@ export function replaceLastDotWithHash(inputString) {
2121
}
2222
}
2323

24+
export function separateGoPath(inputString) {
25+
const lastDotIndex = inputString.lastIndexOf('.');
26+
27+
if (lastDotIndex !== -1) {
28+
const stringWith = inputString.slice(0, lastDotIndex);
29+
return stringWith;
30+
} else {
31+
// If there is no dot in the string, return the original string
32+
return inputString;
33+
}
34+
}
35+
export function separateGoTestName(inputString) {
36+
const lastDotIndex = inputString.lastIndexOf('.');
37+
38+
if (lastDotIndex !== -1) {
39+
const stringWith = inputString.slice(lastDotIndex + 1);
40+
return stringWith;
41+
} else {
42+
// If there is no dot in the string, return the original string
43+
return inputString;
44+
}
45+
}

0 commit comments

Comments
 (0)