forked from Azure/azure-sdk-for-js
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(playwrighttesting): SDK Default Job Config as Empty Strings (Azur…
…e#31178) ### Packages impacted by this PR ` @azure/microsoft-playwright-testing` ### Issues associated with this PR SDK was passing Default Job Config as Empty Strings instead of null Added test for clInfoProvider. ### Describe the problem that is addressed by this PR ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? ### Are there test cases added in this PR? _(If not, why?)_ ### Provide a list of related PRs _(if any)_ ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ ### Checklists - [ ] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [ ] Added a changelog (if necessary)
- Loading branch information
1 parent
32617b4
commit b7b20ed
Showing
2 changed files
with
152 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
sdk/playwrighttesting/microsoft-playwright-testing/test/utils/clInfoProvider.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import { expect } from "@azure-tools/test-utils"; | ||
import { CIInfoProvider, CI_PROVIDERS } from "../../src/utils/cIInfoProvider"; | ||
import sinon from "sinon"; | ||
|
||
describe("CIInfoProvider", () => { | ||
let sandbox: sinon.SinonSandbox; | ||
let environmentVariables: NodeJS.ProcessEnv; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.createSandbox(); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
process.env = { ...environmentVariables }; | ||
}); | ||
|
||
it("should return GitHub CIInfo when GitHub environment variables are set", () => { | ||
process.env["GITHUB_ACTIONS"] = "true"; | ||
process.env["GITHUB_REPOSITORY_ID"] = "repoID"; | ||
process.env["GITHUB_REPOSITORY"] = "repo"; | ||
process.env["GITHUB_ACTOR"] = "testAuthor"; | ||
process.env["GITHUB_SHA"] = "sampleSha"; | ||
process.env["GITHUB_SERVER_URL"] = "https://github.com"; | ||
process.env["GITHUB_RUN_ID"] = "runId123"; | ||
process.env["GITHUB_RUN_ATTEMPT"] = "1"; | ||
process.env["GITHUB_JOB"] = "testJob"; | ||
process.env["GITHUB_REF_NAME"] = "main"; | ||
|
||
const ciInfo = CIInfoProvider.getCIInfo(); | ||
|
||
expect(ciInfo.provider).to.equal(CI_PROVIDERS.GITHUB); | ||
expect(ciInfo.repo).to.equal("repoID"); | ||
expect(ciInfo.branch).to.equal("main"); | ||
expect(ciInfo.author).to.equal("testAuthor"); | ||
expect(ciInfo.commitId).to.equal("sampleSha"); | ||
expect(ciInfo.revisionUrl).to.equal("https://github.com/repo/commit/sampleSha"); | ||
expect(ciInfo.runId).to.equal("runId123"); | ||
expect(ciInfo.runAttempt).to.equal(1); | ||
expect(ciInfo.jobId).to.equal("testJob"); | ||
}); | ||
|
||
it("should return GitHub CIInfo with null fields when Github environment variables are not set", () => { | ||
process.env["GITHUB_ACTIONS"] = "true"; | ||
|
||
const ciInfo = CIInfoProvider.getCIInfo(); | ||
|
||
expect(ciInfo.provider).to.equal(CI_PROVIDERS.GITHUB); | ||
expect(ciInfo.repo).to.be.null; | ||
expect(ciInfo.branch).to.be.null; | ||
expect(ciInfo.author).to.be.null; | ||
expect(ciInfo.commitId).to.be.null; | ||
expect(ciInfo.revisionUrl).to.be.null; | ||
expect(ciInfo.runId).to.be.null; | ||
expect(ciInfo.runAttempt).to.be.null; | ||
expect(ciInfo.jobId).to.be.null; | ||
}); | ||
|
||
it("should return Azure DevOps CIInfo when Azure DevOps environment variables are set", () => { | ||
process.env["AZURE_HTTP_USER_AGENT"] = "someAgent"; | ||
process.env["TF_BUILD"] = "true"; | ||
process.env["BUILD_REPOSITORY_ID"] = "repo123"; | ||
process.env["BUILD_SOURCEBRANCH"] = "main"; | ||
process.env["BUILD_REQUESTEDFOR"] = "testAuthor"; | ||
process.env["BUILD_SOURCEVERSION"] = "commitSha123"; | ||
process.env["SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"] = "https://dev.azure.com/"; | ||
process.env["SYSTEM_TEAMPROJECT"] = "project123"; | ||
process.env["BUILD_REPOSITORY_NAME"] = "repo123"; | ||
process.env["SYSTEM_JOBID"] = "job123"; | ||
process.env["SYSTEM_DEFINITIONID"] = "def123"; | ||
process.env["SYSTEM_JOBATTEMPT"] = "1"; | ||
process.env["RELEASE_DEFINITIONID"] = "Rdef123"; | ||
process.env["RELEASE_DEPLOYMENTID"] = "Rdep123"; | ||
|
||
const ciInfo = CIInfoProvider.getCIInfo(); | ||
|
||
expect(ciInfo.provider).to.equal(CI_PROVIDERS.ADO); | ||
expect(ciInfo.repo).to.equal("repo123"); | ||
expect(ciInfo.branch).to.equal("main"); | ||
expect(ciInfo.author).to.equal("testAuthor"); | ||
expect(ciInfo.commitId).to.equal("commitSha123"); | ||
expect(ciInfo.revisionUrl).to.equal( | ||
"https://dev.azure.com/project123/_git/repo123/commit/commitSha123", | ||
); | ||
expect(ciInfo.runId).to.equal("Rdef123-Rdep123"); | ||
expect(ciInfo.jobId).to.equal("Rdep123"); | ||
}); | ||
|
||
it("should return Azure DevOps CIInfo with null fields when Azure DevOps environment variables are not set", () => { | ||
process.env["AZURE_HTTP_USER_AGENT"] = "someAgent"; | ||
process.env["TF_BUILD"] = "true"; | ||
|
||
const ciInfo = CIInfoProvider.getCIInfo(); | ||
|
||
expect(ciInfo.provider).to.equal(CI_PROVIDERS.ADO); | ||
expect(ciInfo.repo).to.be.null; | ||
expect(ciInfo.branch).to.be.null; | ||
expect(ciInfo.author).to.be.null; | ||
expect(ciInfo.commitId).to.be.null; | ||
expect(ciInfo.revisionUrl).to.be.null; | ||
expect(ciInfo.runId).to.be.null; | ||
expect(ciInfo.jobId).to.be.null; | ||
}); | ||
|
||
it("should return default CIInfo when no supported CI environment is detected", () => { | ||
process.env["REPO"] = "defaultRepo"; | ||
process.env["BRANCH"] = "defaultBranch"; | ||
process.env["AUTHOR"] = "defaultAuthor"; | ||
process.env["COMMIT_ID"] = "defaultCommit"; | ||
process.env["REVISION_URL"] = "https://default.com/repo/commit/defaultCommit"; | ||
process.env["RUN_ID"] = "defaultRunId"; | ||
process.env["RUN_ATTEMPT"] = "2"; | ||
process.env["JOB_ID"] = "defaultJobId"; | ||
|
||
const ciInfo = CIInfoProvider.getCIInfo(); | ||
|
||
expect(ciInfo.provider).to.equal(CI_PROVIDERS.DEFAULT); | ||
expect(ciInfo.repo).to.equal("defaultRepo"); | ||
expect(ciInfo.branch).to.equal("defaultBranch"); | ||
expect(ciInfo.author).to.equal("defaultAuthor"); | ||
expect(ciInfo.commitId).to.equal("defaultCommit"); | ||
expect(ciInfo.revisionUrl).to.equal("https://default.com/repo/commit/defaultCommit"); | ||
expect(ciInfo.runId).to.equal("defaultRunId"); | ||
expect(ciInfo.runAttempt).to.equal(2); | ||
expect(ciInfo.jobId).to.equal("defaultJobId"); | ||
}); | ||
|
||
it("should return default CIInfo with null fields when no supported CI environment is detected", () => { | ||
const ciInfo = CIInfoProvider.getCIInfo(); | ||
|
||
expect(ciInfo.provider).to.equal(CI_PROVIDERS.DEFAULT); | ||
expect(ciInfo.repo).to.be.null; | ||
expect(ciInfo.branch).to.be.null; | ||
expect(ciInfo.author).to.be.null; | ||
expect(ciInfo.commitId).to.be.null; | ||
expect(ciInfo.revisionUrl).to.be.null; | ||
expect(ciInfo.runId).to.be.null; | ||
expect(ciInfo.runAttempt).to.be.null; | ||
expect(ciInfo.jobId).to.be.null; | ||
}); | ||
}); |