Skip to content

Commit fe61d27

Browse files
authored
temp: disable build association using Feature Flag (#139)
* Add temporary feature flag to disable build association * Test featureflag in regression test --------- Co-authored-by: bryan cook <3217452+bryancook@users.noreply.github.com>
1 parent bcf2dce commit fe61d27

4 files changed

Lines changed: 57 additions & 3 deletions

File tree

PublishTestPlanResultsV1/services/AdoWrapper.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ITestApi } from "azure-devops-node-api/TestApi";
77
import * as fs from "fs";
88
import path from "path";
99
import { ILogger, getLogger } from "./Logger";
10+
import FeatureFlags, { FeatureFlag } from "./FeatureFlags";
1011

1112
interface AdoResponseHeaders {
1213
"x-ms-continuationtoken"? : string;
@@ -151,6 +152,11 @@ export class AdoWrapper {
151152
configurationIds: []
152153
};
153154

155+
// temp: disable build id association when test plan is different project than pipeline
156+
if (FeatureFlags.isFeatureEnabled(FeatureFlag.DisableBuildAssociation)) {
157+
testRun.build = undefined;
158+
}
159+
154160
return await this.testApi.createTestRun(testRun, projectId);
155161
}
156162

PublishTestPlanResultsV1/services/FeatureFlags.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { getLogger, ILogger } from "./Logger";
33
export class FeatureFlag {
44
static DisplayTelemetry : string = "displaytelemetry";
55
static DisplayTelemetryErrors : string = "displaytelemetryerrors";
6+
static DisableBuildAssociation : string = "disablebuildassociation";
67
}
78

89
export class FeatureFlags {

PublishTestPlanResultsV1/test/AdoWrapper.specs.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import path from "path";
44
import * as Contracts from 'azure-devops-node-api/interfaces/TestInterfaces'
55
import * as testUtil from './testUtil';
66
import { AdoWrapper } from "../services/AdoWrapper";
7+
import { FeatureFlag } from "../services/FeatureFlags";
78

89
describe("AdoWrapper", () => {
910

@@ -43,6 +44,7 @@ describe("AdoWrapper", () => {
4344

4445
afterEach(() => {
4546
sinon.restore();
47+
testUtil.clearData();
4648
})
4749

4850
context('Integration Tests', () => {
@@ -158,6 +160,37 @@ describe("AdoWrapper", () => {
158160
expect(result.length).eq(20);
159161
})
160162

163+
context("Create Test Run", () => {
164+
165+
it(`Should disable build association when ${FeatureFlag.DisableBuildAssociation} feature flag is enabled`, async () => {
166+
// arrange
167+
const createTestRunStub = stubCreateTestRun(<Contracts.TestRun>{ id: 123 });
168+
testUtil.setFeatureFlag(FeatureFlag.DisableBuildAssociation, "true");
169+
testUtil.loadData();
170+
171+
// act
172+
await subject.createTestRun(projectId, parseInt(planId), [1,2,3], "buildId");
173+
174+
// assert
175+
let testRun = createTestRunStub.getCall(0).args[1] as Contracts.TestRun;
176+
expect(testRun.build).to.be.undefined;
177+
});
178+
179+
it(`Should include build association when ${FeatureFlag.DisableBuildAssociation} feature flag is not provided`, async () => {
180+
// arrange
181+
const createTestRunStub = stubCreateTestRun(<Contracts.TestRun>{ id: 123 });
182+
testUtil.loadData();
183+
184+
// act
185+
await subject.createTestRun(projectId, parseInt(planId), [1,2,3], "buildId");
186+
187+
// assert
188+
let testRun = createTestRunStub.getCall(0).args[1] as Contracts.TestRun;
189+
expect(testRun.build).not.to.be.undefined;
190+
expect(testRun.build?.id).to.be.eq("buildId");
191+
});
192+
});
193+
161194
// it("Should create a testrun", async function () {
162195
// // arrange
163196
// // this.timeout(10000);
@@ -321,4 +354,18 @@ describe("AdoWrapper", () => {
321354
});
322355
}
323356

357+
function stubCreateTestRun(testRun : Contracts.TestRun) : sinon.SinonStub {
358+
const createTestRunStub = sinon.stub(subject.testApi.rest, "create");
359+
createTestRunStub.callsFake( (url, testRun, options?) => {
360+
361+
let response : any = {
362+
result : testRun,
363+
headers : {}
364+
}
365+
366+
return Promise.resolve(response);
367+
});
368+
return createTestRunStub;
369+
}
370+
324371
})

devops/pipelines/marketplace-extension/regression-test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ parameters:
4040
testResultsFile: '$(Build.SourcesDirectory)/examples/dotnet/xUnitResults/TestResults-adotestplan-prj.xml'
4141
projectName: 'ADO Test Automation'
4242
testplan: 'Plan w Duplicates'
43-
buildId: 2436
4443
expectedResults:
4544
- outcome: Passed
4645
count: 1
46+
featureFlags: 'DisableBuildAssociation'
4747
- name: TestDuplicates_wTestOutcomeSettingEnabled
4848
format: xunit
4949
testResultsFile: '$(Build.SourcesDirectory)/examples/dotnet/xUnitResults/TestResults-adotestplan-prj.xml'
5050
projectName: 'ADO Test Automation'
5151
testplan: 'Plan w Duplicates and TestOutcome Setting Enabled'
52-
buildId: 2436
52+
buildId: 2436 # TODO: remove when 137 is fixed
5353
expectedResults:
5454
- outcome: Passed
5555
count: 2
@@ -110,7 +110,7 @@ steps:
110110
-failTaskOnMissingResultsFile ''
111111
-failTaskOnMissingTests ''
112112
-failTaskOnUnmatchedTestCases ''
113-
-featureFlags 'DisplayTelemetry,DisplayTelemetryErrors'
113+
-featureFlags '${{ iif(ne(test.featureFlags,''), test.featureFlags, 'DisplayTelemetry,DisplayTelemetryErrors') }}'
114114
-DryRun ''
115115
116116
- ${{ if ne(test.expectedResults, '') }}:

0 commit comments

Comments
 (0)