-
Notifications
You must be signed in to change notification settings - Fork 5.6k
[openapi-diff-runner] Add e2e tests for oad calls from git diff #40218
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
56a6b28
Initial plan
Copilot 789e6ad
Add test infrastructure and e2e tests from PR #40121
Copilot 5bbe3cc
get test to load
mikeharder e43456e
WIP: Improve test
mikeharder 73d48de
add fixtures
mikeharder 63bf378
cleanup
mikeharder 34d1992
relative path
mikeharder 53626bf
log to null
mikeharder 6621103
minimal valid JSON
mikeharder 22e1aad
multi-version test
mikeharder 8b5a915
improve test for adding new stable
mikeharder d7d35a3
comment
mikeharder c4cfa49
test names
mikeharder 32b115b
add fixture with multiple swaggers per api version
mikeharder 4ba0c97
add test multi-file, multi-version
mikeharder eff0bb8
new stable, multi files
mikeharder ffa6ddb
mock createDummySwagger, add rename tests
mikeharder d12afc3
Merge branch 'main' into copilot/add-tests-to-commands
mikeharder 4f1f80a
rename
mikeharder fb83148
Merge branch 'copilot/add-tests-to-commands' of https://github.com/Az…
mikeharder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,384 @@ | ||
| import { BREAKING_CHANGES_CHECK_TYPES } from "@azure-tools/specs-shared/breaking-change"; | ||
| import { getChangedFilesStatuses } from "@azure-tools/specs-shared/changed-files"; | ||
| import { devNull } from "node:os"; | ||
| import path, { resolve } from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import { createDummySwagger } from "../src/command-helpers.js"; | ||
| import { validateBreakingChange } from "../src/commands.js"; | ||
| import { runOad } from "../src/run-oad.js"; | ||
|
|
||
| vi.mock("@azure-tools/specs-shared/changed-files", async () => { | ||
| const actual = await vi.importActual("@azure-tools/specs-shared/changed-files"); | ||
| return { | ||
| ...actual, | ||
| getChangedFilesStatuses: vi.fn(), | ||
| }; | ||
| }); | ||
|
|
||
| vi.mock("../src/run-oad.js", () => ({ | ||
| runOad: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("../src/command-helpers.js", async () => { | ||
| const actual = await vi.importActual("../src/command-helpers.js"); | ||
| return { | ||
| ...actual, | ||
| createDummySwagger: vi.fn(), | ||
| }; | ||
| }); | ||
|
|
||
| function mockChangedFilesStatuses( | ||
| partial: Partial<{ | ||
| additions: string[]; | ||
| modifications: string[]; | ||
| deletions: string[]; | ||
| renames: { from: string; to: string }[]; | ||
| }> = {}, | ||
| ) { | ||
| const defaultResult = { | ||
| additions: [], | ||
| modifications: [], | ||
| deletions: [], | ||
| renames: [], | ||
| total: 0, | ||
| }; | ||
|
|
||
| const result = { ...defaultResult, ...partial }; | ||
|
|
||
| result.total = | ||
| result.additions.length + | ||
| result.modifications.length + | ||
| result.deletions.length + | ||
| result.renames.length; | ||
|
|
||
| return vi.mocked(getChangedFilesStatuses).mockResolvedValue(result); | ||
| } | ||
|
|
||
| const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
|
|
||
| const context = { | ||
| localSpecRepoPath: "", | ||
| workingFolder: "", | ||
| logFileFolder: "", | ||
| swaggerDirs: [], | ||
| baseBranch: "", | ||
| headCommit: "", | ||
| runType: "", | ||
| checkName: "", | ||
| targetRepo: "", | ||
| sourceRepo: "", | ||
| prInfo: { | ||
| targetBranch: "", | ||
| sourceBranch: "", | ||
| baseBranch: "", | ||
| currentBranch: "", | ||
| tempRepoFolder: path.resolve(__dirname, "fixtures"), | ||
| checkout: function (branch: string): Promise<void> { | ||
| console.log("checkout " + branch); | ||
| return Promise.resolve(); | ||
| }, | ||
| }, | ||
| prNumber: "", | ||
| prSourceBranch: "", | ||
| prTargetBranch: "", | ||
| oadMessageProcessorContext: { | ||
| logFilePath: devNull, | ||
| prUrl: "", | ||
| messageCache: [], | ||
| }, | ||
| prUrl: "", | ||
| }; | ||
|
|
||
| const cases = [ | ||
| { | ||
| name: "modify one file, one version", | ||
| changedFiles: { | ||
| modifications: ["specification/foo/data-plane/Foo/stable/2025-03-01/foo.json"], | ||
| }, | ||
| expectedCreateDummySwaggers: { | ||
| old: [], | ||
| new: [], | ||
| }, | ||
| expectedOadCalls: { | ||
| sameVersion: [ | ||
| { | ||
| old: "specification/foo/data-plane/Foo/stable/2025-03-01/foo.json", | ||
| new: "specification/foo/data-plane/Foo/stable/2025-03-01/foo.json", | ||
| }, | ||
| ], | ||
| crossVersion: [], | ||
| }, | ||
| }, | ||
| { | ||
| name: "modify one file, multiple versions", | ||
| changedFiles: { | ||
| modifications: [ | ||
| "specification/foo/data-plane/Foo/preview/2025-04-01-preview/foo.json", | ||
| "specification/foo/data-plane/Foo/stable/2025-01-01/foo.json", | ||
| "specification/foo/data-plane/Foo/stable/2025-03-01/foo.json", | ||
| ], | ||
| }, | ||
| expectedCreateDummySwaggers: { | ||
| old: [], | ||
| new: [], | ||
| }, | ||
| expectedOadCalls: { | ||
| sameVersion: [ | ||
| { | ||
| old: "specification/foo/data-plane/Foo/preview/2025-04-01-preview/foo.json", | ||
| new: "specification/foo/data-plane/Foo/preview/2025-04-01-preview/foo.json", | ||
| }, | ||
| { | ||
| old: "specification/foo/data-plane/Foo/stable/2025-01-01/foo.json", | ||
| new: "specification/foo/data-plane/Foo/stable/2025-01-01/foo.json", | ||
| }, | ||
| { | ||
| old: "specification/foo/data-plane/Foo/stable/2025-03-01/foo.json", | ||
| new: "specification/foo/data-plane/Foo/stable/2025-03-01/foo.json", | ||
| }, | ||
| ], | ||
| crossVersion: [], | ||
| }, | ||
| }, | ||
| { | ||
| name: "modify multiple files, multiple versions", | ||
| changedFiles: { | ||
| modifications: [ | ||
| "specification/bar/data-plane/Bar/preview/2025-04-01-preview/bar.json", | ||
| "specification/bar/data-plane/Bar/preview/2025-04-01-preview/baz.json", | ||
| "specification/bar/data-plane/Bar/stable/2025-03-01/bar.json", | ||
| "specification/bar/data-plane/Bar/stable/2025-03-01/baz.json", | ||
| ], | ||
| }, | ||
| expectedCreateDummySwaggers: { | ||
| old: [], | ||
| new: [], | ||
| }, | ||
| expectedOadCalls: { | ||
| sameVersion: [ | ||
| { | ||
| old: "specification/bar/data-plane/Bar/preview/2025-04-01-preview/bar.json", | ||
| new: "specification/bar/data-plane/Bar/preview/2025-04-01-preview/bar.json", | ||
| }, | ||
| { | ||
| old: "specification/bar/data-plane/Bar/preview/2025-04-01-preview/baz.json", | ||
| new: "specification/bar/data-plane/Bar/preview/2025-04-01-preview/baz.json", | ||
| }, | ||
| { | ||
| old: "specification/bar/data-plane/Bar/stable/2025-03-01/bar.json", | ||
| new: "specification/bar/data-plane/Bar/stable/2025-03-01/bar.json", | ||
| }, | ||
| { | ||
| old: "specification/bar/data-plane/Bar/stable/2025-03-01/baz.json", | ||
| new: "specification/bar/data-plane/Bar/stable/2025-03-01/baz.json", | ||
| }, | ||
| ], | ||
| crossVersion: [], | ||
| }, | ||
| }, | ||
| { | ||
| name: "add new stable, one file", | ||
| changedFiles: { | ||
| additions: ["specification/foo/data-plane/Foo/stable/2026-01-01/foo.json"], | ||
| }, | ||
| expectedCreateDummySwaggers: { | ||
| old: [], | ||
| new: [], | ||
| }, | ||
| expectedOadCalls: { | ||
| sameVersion: [], | ||
| crossVersion: [ | ||
| { | ||
| old: "specification/foo/data-plane/Foo/preview/2025-04-01-preview/foo.json", | ||
| new: "specification/foo/data-plane/Foo/stable/2026-01-01/foo.json", | ||
| }, | ||
| { | ||
| old: "specification/foo/data-plane/Foo/stable/2025-03-01/foo.json", | ||
| new: "specification/foo/data-plane/Foo/stable/2026-01-01/foo.json", | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| { | ||
| name: "add new stable, multiple files", | ||
| changedFiles: { | ||
| additions: [ | ||
| "specification/bar/data-plane/Bar/stable/2026-01-01/bar.json", | ||
| "specification/bar/data-plane/Bar/stable/2026-01-01/baz.json", | ||
| ], | ||
| }, | ||
| expectedCreateDummySwaggers: { | ||
| old: [], | ||
| new: [], | ||
| }, | ||
| expectedOadCalls: { | ||
| sameVersion: [], | ||
| crossVersion: [ | ||
| { | ||
| old: "specification/bar/data-plane/Bar/preview/2025-04-01-preview/bar.json", | ||
| new: "specification/bar/data-plane/Bar/stable/2026-01-01/bar.json", | ||
| }, | ||
| { | ||
| old: "specification/bar/data-plane/Bar/preview/2025-04-01-preview/baz.json", | ||
| new: "specification/bar/data-plane/Bar/stable/2026-01-01/baz.json", | ||
| }, | ||
| { | ||
| old: "specification/bar/data-plane/Bar/stable/2025-03-01/bar.json", | ||
| new: "specification/bar/data-plane/Bar/stable/2026-01-01/bar.json", | ||
| }, | ||
| { | ||
| old: "specification/bar/data-plane/Bar/stable/2025-03-01/baz.json", | ||
| new: "specification/bar/data-plane/Bar/stable/2026-01-01/baz.json", | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| { | ||
| name: "rename one file, one version", | ||
| changedFiles: { | ||
| renames: [ | ||
| { | ||
| from: "specification/foo/data-plane/Foo/stable/2025-01-01/foo.json", | ||
| to: "specification/foo/data-plane/Foo/stable/2025-01-01/openapi.json", | ||
| }, | ||
| ], | ||
| }, | ||
| // TODO: After code is fixed, should not create *any* dummy swaggers | ||
| expectedCreateDummySwaggers: { | ||
| old: ["specification/foo/data-plane/Foo/stable/2025-01-01/openapi.json"], | ||
| new: ["specification/foo/data-plane/Foo/stable/2025-01-01/foo.json"], | ||
| }, | ||
| // TODO: After code is fixed, should only compare before and after renamed file | ||
| expectedOadCalls: { | ||
| sameVersion: [ | ||
| { | ||
| old: "specification/foo/data-plane/Foo/stable/2025-01-01/foo.json", | ||
| new: "specification/foo/data-plane/Foo/stable/2025-01-01/foo.json", | ||
| }, | ||
| { | ||
| old: "specification/foo/data-plane/Foo/stable/2025-01-01/openapi.json", | ||
| new: "specification/foo/data-plane/Foo/stable/2025-01-01/openapi.json", | ||
| }, | ||
| ], | ||
| crossVersion: [], | ||
| }, | ||
| }, | ||
| { | ||
| name: "rename one file, change case of service", | ||
| changedFiles: { | ||
| addtions: ["specification/foo/data-plane/foo/stable/2025-01-01/openapi.json"], | ||
| deletions: ["specification/foo/data-plane/Foo/stable/2025-01-01/foo.json"], | ||
| }, | ||
| // TODO: After code is fixed, should not create *any* dummy swaggers | ||
| expectedCreateDummySwaggers: { | ||
| old: [], | ||
| new: ["specification/foo/data-plane/Foo/stable/2025-01-01/foo.json"], | ||
| }, | ||
| // TODO: After code is fixed, should only compare before and after renamed file | ||
| expectedOadCalls: { | ||
| sameVersion: [ | ||
| { | ||
| old: "specification/foo/data-plane/Foo/stable/2025-01-01/foo.json", | ||
| new: "specification/foo/data-plane/Foo/stable/2025-01-01/foo.json", | ||
| }, | ||
| ], | ||
| crossVersion: [], | ||
| }, | ||
| }, | ||
|
|
||
| // Currently failing, code needs better support for renames | ||
| // | ||
| // { | ||
| // name: "change case folder, rename file", | ||
| // changedFiles: { | ||
| // additions: [ | ||
| // "specification/nginx/resource-manager/Nginx.NginxPlus/preview/2025-03-01-preview/openapi.json", | ||
| // ], | ||
| // deletions: [ | ||
| // "specification/nginx/resource-manager/NGINX.NGINXPLUS/preview/2025-03-01-preview/swagger.json", | ||
| // ], | ||
| // renames: [ | ||
| // { | ||
| // from: "specification/nginx/resource-manager/NGINX.NGINXPLUS/stable/2023-09-01/swagger.json", | ||
| // to: "specification/nginx/resource-manager/Nginx.NginxPlus/stable/2023-09-01/swagger.json", | ||
| // }, | ||
| // ], | ||
| // }, | ||
| // existingFiles: [ | ||
| // "specification/nginx/resource-manager/NGINX.NGINXPLUS/stable/2023-09-01/swagger.json", | ||
| // "specification/nginx/resource-manager/NGINX.NGINXPLUS/preview/2025-03-01-preview/swagger.json", | ||
| // ], | ||
| // expectedOadCalls: [ | ||
| // { | ||
| // old: "specification/nginx/resource-manager/NGINX.NGINXPLUS/preview/2025-03-01-preview/swagger.json", | ||
| // new: "specification/nginx/resource-manager/Nginx.NginxPlus/preview/2025-03-01-preview/openapi.json", | ||
| // }, | ||
| // { | ||
| // old: "specification/nginx/resource-manager/NGINX.NGINXPLUS/stable/2023-09-01/swagger.json", | ||
| // new: "specification/nginx/resource-manager/Nginx.NginxPlus/stable/2023-09-01/swagger.json", | ||
| // }, | ||
| // ], | ||
| // }, | ||
| ]; | ||
|
|
||
| describe("validateBreakingChange", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| it.each(cases)( | ||
| "$name", | ||
| async ({ changedFiles, expectedCreateDummySwaggers, expectedOadCalls }) => { | ||
| mockChangedFilesStatuses(changedFiles); | ||
|
|
||
| const mockCreateDummySwagger = vi.mocked(createDummySwagger); | ||
|
|
||
| const mockRunOad = vi.mocked(runOad).mockResolvedValue([]); | ||
|
|
||
| for (const data of [ | ||
| { | ||
| runType: BREAKING_CHANGES_CHECK_TYPES.SAME_VERSION, | ||
| expectedOadCalls: expectedOadCalls.sameVersion, | ||
| }, | ||
| { | ||
| runType: BREAKING_CHANGES_CHECK_TYPES.CROSS_VERSION, | ||
| expectedOadCalls: expectedOadCalls.crossVersion, | ||
| }, | ||
| ]) { | ||
| mockRunOad.mockClear(); | ||
|
|
||
| const statusCode = await validateBreakingChange({ | ||
| ...context, | ||
| runType: data.runType, | ||
| }); | ||
|
|
||
| expect(statusCode).toEqual(0); | ||
|
|
||
| for (const expected of expectedCreateDummySwaggers.old) { | ||
| expect(mockCreateDummySwagger).toBeCalledWith( | ||
| expect.anything(), | ||
| resolve(context.prInfo.tempRepoFolder, expected), | ||
| ); | ||
| } | ||
|
|
||
| for (const expected of expectedCreateDummySwaggers.new) { | ||
| expect(mockCreateDummySwagger).toBeCalledWith(expect.anything(), resolve(expected)); | ||
| } | ||
|
|
||
| expect(mockCreateDummySwagger).toBeCalledTimes( | ||
| expectedCreateDummySwaggers.old.length + expectedCreateDummySwaggers.new.length, | ||
| ); | ||
|
|
||
| for (const expected of data.expectedOadCalls) { | ||
| expect(mockRunOad).toBeCalledWith( | ||
| path.join(context.prInfo.tempRepoFolder, expected.old), | ||
| expected.new, | ||
| ); | ||
| } | ||
|
|
||
| expect(mockRunOad).toBeCalledTimes(data.expectedOadCalls.length); | ||
| } | ||
| }, | ||
| ); | ||
| }); |
1 change: 1 addition & 0 deletions
1
...runner/test/fixtures/specification/bar/data-plane/Bar/preview/2025-02-01-preview/bar.json
This file contains hidden or 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 @@ | ||
| {} |
1 change: 1 addition & 0 deletions
1
...runner/test/fixtures/specification/bar/data-plane/Bar/preview/2025-02-01-preview/baz.json
This file contains hidden or 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 @@ | ||
| {} |
1 change: 1 addition & 0 deletions
1
...runner/test/fixtures/specification/bar/data-plane/Bar/preview/2025-04-01-preview/bar.json
This file contains hidden or 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 @@ | ||
| {} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated bug fix