Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AzureTestPlanTask: Implemented support for Go Language #20006

Merged
merged 5 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions Tasks/AzureTestPlanV0/Invokers/goinvoker.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
import tl = require('azure-pipelines-task-lib/task');
import utils = require('../utils');
import constants = require('../constants');
import tr = require("azure-pipelines-task-lib/toolrunner");
import { executeGoCommand } from '../testLibExecutor';

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

//Go execution will be added
/*executable = go;
args = test, ./...
spawn*/

console.log("Go changes1");
return 1;
}
let finalStatus = 0;
let goPath = tl.which("go", true);
await executeGoCommand(goPath, constants.INSTALL_GOTESTSUM);
tl.debug("Installed Gotestsum");

//testsToBeExecuted: go.mod/01-normal/normal.Test1,go.mod/01-normal/normal.Test11,go.mod/04-testmain.Test1,go.mod/05-parallel.TestSumParalel
goPath = tl.which("gotestsum", true);
let i = 0;
for (let tests of testsToBeExecuted) {
const GoTestPath = utils.separateGoPath(tests);
const GoTestName = utils.separateGoTestName(tests);
try {
const argument = `--junitfile TEST-Go${i}-junit.xml -- ${GoTestPath} -v -run ^${GoTestName}$`;
const status = await executeGoCommand(goPath, argument);
if (status != 0) {
finalStatus = 1;
}
tl.debug(`Test case ${GoTestName} executed successfully.`);
} catch (error) {
tl.debug(`Error executing ${GoTestName} test case: ${error}`);
finalStatus = 1;
}
i++;
}
return finalStatus;
}
3 changes: 2 additions & 1 deletion Tasks/AzureTestPlanV0/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export const NOT_AUTOMATED = 'Not Automated'
export const MERGE_THRESHOLD = 100;
export const AUTOMATED_EXECUTION = "AutomatedExecutionPhase";
export const AUTOMATED_PUBLISHING = "PublishingAutomatedResultsPhase";
export const MANUALTESTS_PUBLISHING = "ManualTestResultsPublishingPhase";
export const MANUALTESTS_PUBLISHING = "ManualTestResultsPublishingPhase";
export const INSTALL_GOTESTSUM = "install gotest.tools/gotestsum@latest";
2 changes: 1 addition & 1 deletion Tasks/AzureTestPlanV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 0,
"Minor": 241,
"Patch": 2
"Patch": 4
},
"preview": true,
"demands": [],
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureTestPlanV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 0,
"Minor": 241,
"Patch": 2
"Patch": 4
},
"preview": true,
"demands": [],
Expand Down
6 changes: 6 additions & 0 deletions Tasks/AzureTestPlanV0/testLibExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,10 @@ export async function execGradleBuild(args: string[]): Promise<number> {
tl.setResult(tl.TaskResult.Failed, "Build failed."); // Set the step result to Failed
return 1; // Return 1 indicating failure
}
}

export async function executeGoCommand(goPath: string, argument: string): Promise<number> {
let go: tr.ToolRunner = tl.tool(goPath);
go.line(argument);
return await go.exec(<tr.IExecOptions>{ cwd: "" });
}
22 changes: 22 additions & 0 deletions Tasks/AzureTestPlanV0/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,25 @@ export function replaceLastDotWithHash(inputString) {
}
}

export function separateGoPath(inputString) {
const lastDotIndex = inputString.lastIndexOf('.');

if (lastDotIndex !== -1) {
const stringWith = inputString.slice(0, lastDotIndex);
return stringWith;
} else {
// If there is no dot in the string, return the original string
return inputString;
}
}
export function separateGoTestName(inputString) {
const lastDotIndex = inputString.lastIndexOf('.');

if (lastDotIndex !== -1) {
const stringWith = inputString.slice(lastDotIndex + 1);
return stringWith;
} else {
// If there is no dot in the string, return the original string
return inputString;
}
}
4 changes: 2 additions & 2 deletions _generated/AzureTestPlanV0.versionmap.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Default|0.241.2
Node20-225|0.241.3
Default|0.241.4
Node20-225|0.241.5
36 changes: 28 additions & 8 deletions _generated/AzureTestPlanV0/Invokers/goinvoker.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
import tl = require('azure-pipelines-task-lib/task');
import utils = require('../utils');
import constants = require('../constants');
import tr = require("azure-pipelines-task-lib/toolrunner");
import { executeGoCommand } from '../testLibExecutor';

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

//Go execution will be added
/*executable = go;
args = test, ./...
spawn*/

console.log("Go changes1");
return 1;
}
let finalStatus = 0;
let goPath = tl.which("go", true);
await executeGoCommand(goPath, constants.INSTALL_GOTESTSUM);
tl.debug("Installed Gotestsum");

//testsToBeExecuted: go.mod/01-normal/normal.Test1,go.mod/01-normal/normal.Test11,go.mod/04-testmain.Test1,go.mod/05-parallel.TestSumParalel
goPath = tl.which("gotestsum", true);
let i = 0;
for (let tests of testsToBeExecuted) {
const GoTestPath = utils.separateGoPath(tests);
const GoTestName = utils.separateGoTestName(tests);
try {
const argument = `--junitfile TEST-Go${i}-junit.xml -- ${GoTestPath} -v -run ^${GoTestName}$`;
const status = await executeGoCommand(goPath, argument);
if (status != 0) {
finalStatus = 1;
}
tl.debug(`Test case ${GoTestName} executed successfully.`);
} catch (error) {
tl.debug(`Error executing ${GoTestName} test case: ${error}`);
finalStatus = 1;
}
i++;
}
return finalStatus;
}
3 changes: 2 additions & 1 deletion _generated/AzureTestPlanV0/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export const NOT_AUTOMATED = 'Not Automated'
export const MERGE_THRESHOLD = 100;
export const AUTOMATED_EXECUTION = "AutomatedExecutionPhase";
export const AUTOMATED_PUBLISHING = "PublishingAutomatedResultsPhase";
export const MANUALTESTS_PUBLISHING = "ManualTestResultsPublishingPhase";
export const MANUALTESTS_PUBLISHING = "ManualTestResultsPublishingPhase";
export const INSTALL_GOTESTSUM = "install gotest.tools/gotestsum@latest";
6 changes: 3 additions & 3 deletions _generated/AzureTestPlanV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 0,
"Minor": 241,
"Patch": 2
"Patch": 4
},
"preview": true,
"demands": [],
Expand Down Expand Up @@ -177,7 +177,7 @@
"MultipleMatchingGradlewFound": "Multiple gradlew files found. Selecting the first matched instance"
},
"_buildConfigMapping": {
"Default": "0.241.2",
"Node20-225": "0.241.3"
"Default": "0.241.4",
"Node20-225": "0.241.5"
}
}
6 changes: 3 additions & 3 deletions _generated/AzureTestPlanV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 0,
"Minor": 241,
"Patch": 2
"Patch": 4
},
"preview": true,
"demands": [],
Expand Down Expand Up @@ -177,7 +177,7 @@
"MultipleMatchingGradlewFound": "ms-resource:loc.messages.MultipleMatchingGradlewFound"
},
"_buildConfigMapping": {
"Default": "0.241.2",
"Node20-225": "0.241.3"
"Default": "0.241.4",
"Node20-225": "0.241.5"
}
}
6 changes: 6 additions & 0 deletions _generated/AzureTestPlanV0/testLibExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,10 @@ export async function execGradleBuild(args: string[]): Promise<number> {
tl.setResult(tl.TaskResult.Failed, "Build failed."); // Set the step result to Failed
return 1; // Return 1 indicating failure
}
}

export async function executeGoCommand(goPath: string, argument: string): Promise<number> {
let go: tr.ToolRunner = tl.tool(goPath);
go.line(argument);
return await go.exec(<tr.IExecOptions>{ cwd: "" });
}
22 changes: 22 additions & 0 deletions _generated/AzureTestPlanV0/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,25 @@ export function replaceLastDotWithHash(inputString) {
}
}

export function separateGoPath(inputString) {
const lastDotIndex = inputString.lastIndexOf('.');

if (lastDotIndex !== -1) {
const stringWith = inputString.slice(0, lastDotIndex);
return stringWith;
} else {
// If there is no dot in the string, return the original string
return inputString;
}
}
export function separateGoTestName(inputString) {
const lastDotIndex = inputString.lastIndexOf('.');

if (lastDotIndex !== -1) {
const stringWith = inputString.slice(lastDotIndex + 1);
return stringWith;
} else {
// If there is no dot in the string, return the original string
return inputString;
}
}
36 changes: 28 additions & 8 deletions _generated/AzureTestPlanV0_Node20/Invokers/goinvoker.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
import tl = require('azure-pipelines-task-lib/task');
import utils = require('../utils');
import constants = require('../constants');
import tr = require("azure-pipelines-task-lib/toolrunner");
import { executeGoCommand } from '../testLibExecutor';

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

//Go execution will be added
/*executable = go;
args = test, ./...
spawn*/

console.log("Go changes1");
return 1;
}
let finalStatus = 0;
let goPath = tl.which("go", true);
await executeGoCommand(goPath, constants.INSTALL_GOTESTSUM);
tl.debug("Installed Gotestsum");

//testsToBeExecuted: go.mod/01-normal/normal.Test1,go.mod/01-normal/normal.Test11,go.mod/04-testmain.Test1,go.mod/05-parallel.TestSumParalel
goPath = tl.which("gotestsum", true);
let i = 0;
for (let tests of testsToBeExecuted) {
const GoTestPath = utils.separateGoPath(tests);
const GoTestName = utils.separateGoTestName(tests);
try {
const argument = `--junitfile TEST-Go${i}-junit.xml -- ${GoTestPath} -v -run ^${GoTestName}$`;
const status = await executeGoCommand(goPath, argument);
if (status != 0) {
finalStatus = 1;
}
tl.debug(`Test case ${GoTestName} executed successfully.`);
} catch (error) {
tl.debug(`Error executing ${GoTestName} test case: ${error}`);
finalStatus = 1;
}
i++;
}
return finalStatus;
}
3 changes: 2 additions & 1 deletion _generated/AzureTestPlanV0_Node20/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export const NOT_AUTOMATED = 'Not Automated'
export const MERGE_THRESHOLD = 100;
export const AUTOMATED_EXECUTION = "AutomatedExecutionPhase";
export const AUTOMATED_PUBLISHING = "PublishingAutomatedResultsPhase";
export const MANUALTESTS_PUBLISHING = "ManualTestResultsPublishingPhase";
export const MANUALTESTS_PUBLISHING = "ManualTestResultsPublishingPhase";
export const INSTALL_GOTESTSUM = "install gotest.tools/gotestsum@latest";
6 changes: 3 additions & 3 deletions _generated/AzureTestPlanV0_Node20/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 0,
"Minor": 241,
"Patch": 3
"Patch": 5
},
"preview": true,
"demands": [],
Expand Down Expand Up @@ -181,7 +181,7 @@
"MultipleMatchingGradlewFound": "Multiple gradlew files found. Selecting the first matched instance"
},
"_buildConfigMapping": {
"Default": "0.241.2",
"Node20-225": "0.241.3"
"Default": "0.241.4",
"Node20-225": "0.241.5"
}
}
6 changes: 3 additions & 3 deletions _generated/AzureTestPlanV0_Node20/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 0,
"Minor": 241,
"Patch": 3
"Patch": 5
},
"preview": true,
"demands": [],
Expand Down Expand Up @@ -181,7 +181,7 @@
"MultipleMatchingGradlewFound": "ms-resource:loc.messages.MultipleMatchingGradlewFound"
},
"_buildConfigMapping": {
"Default": "0.241.2",
"Node20-225": "0.241.3"
"Default": "0.241.4",
"Node20-225": "0.241.5"
}
}
6 changes: 6 additions & 0 deletions _generated/AzureTestPlanV0_Node20/testLibExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,10 @@ export async function execGradleBuild(args: string[]): Promise<number> {
tl.setResult(tl.TaskResult.Failed, "Build failed."); // Set the step result to Failed
return 1; // Return 1 indicating failure
}
}

export async function executeGoCommand(goPath: string, argument: string): Promise<number> {
let go: tr.ToolRunner = tl.tool(goPath);
go.line(argument);
return await go.exec(<tr.IExecOptions>{ cwd: "" });
}
22 changes: 22 additions & 0 deletions _generated/AzureTestPlanV0_Node20/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,25 @@ export function replaceLastDotWithHash(inputString) {
}
}

export function separateGoPath(inputString) {
const lastDotIndex = inputString.lastIndexOf('.');

if (lastDotIndex !== -1) {
const stringWith = inputString.slice(0, lastDotIndex);
return stringWith;
} else {
// If there is no dot in the string, return the original string
return inputString;
}
}
export function separateGoTestName(inputString) {
const lastDotIndex = inputString.lastIndexOf('.');

if (lastDotIndex !== -1) {
const stringWith = inputString.slice(lastDotIndex + 1);
return stringWith;
} else {
// If there is no dot in the string, return the original string
return inputString;
}
}