forked from Azure/oav
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support test scenario and test runner
- Loading branch information
Showing
65 changed files
with
6,612 additions
and
747 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
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
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
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
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
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
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
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 @@ | ||
require("reflect-metadata"); |
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,26 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
import * as yargs from "yargs"; | ||
|
||
import { ExampleQualityValidator } from "../exampleQualityValidator/exampleQualityValidator"; | ||
import { cliSuppressExceptions } from "../cliSuppressExceptions"; | ||
import { log } from "../util/logging"; | ||
|
||
export const command = "example-quality <spec-path>"; | ||
|
||
export const describe = | ||
"Performs example quality validation of x-ms-examples and examples present in the spec."; | ||
|
||
export async function handler(argv: yargs.Arguments): Promise<void> { | ||
await cliSuppressExceptions(async () => { | ||
log.debug(argv.toString()); | ||
const specPath = argv.specPath; | ||
const validator = ExampleQualityValidator.create({ | ||
swaggerFilePaths: [specPath], | ||
}); | ||
const res = await validator.validateSwaggerExamples(); | ||
console.log(JSON.stringify(res, null, 2)); | ||
return 0; | ||
}); | ||
} |
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,83 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
/* eslint-disable id-blacklist */ | ||
|
||
import * as fs from "fs"; | ||
import * as path from "path"; | ||
import * as yargs from "yargs"; | ||
import { | ||
PostmanCollectionGenerator, | ||
PostmanCollectionGeneratorOption, | ||
} from "../testScenario/postmanCollectionGenerator"; | ||
|
||
import { cliSuppressExceptions } from "../cliSuppressExceptions"; | ||
import { getAutorestConfig } from "../util/getAutorestConfig"; | ||
export const command = "generate-collection [testScenario-path]"; | ||
|
||
export const describe = "Generate postman collection file from test scenario."; | ||
|
||
export const builder: yargs.CommandBuilder = { | ||
tag: { | ||
describe: "the readme tag name.", | ||
string: true, | ||
}, | ||
output: { | ||
alias: "outputDir", | ||
describe: "the output folder.", | ||
string: true, | ||
default: "generated_collections", | ||
}, | ||
readme: { | ||
describe: "path to readme.md file", | ||
string: true, | ||
demandOption: true, | ||
}, | ||
e: { | ||
alias: "envFile", | ||
describe: "the env file path.", | ||
string: true, | ||
}, | ||
}; | ||
|
||
export async function handler(argv: yargs.Arguments): Promise<void> { | ||
await cliSuppressExceptions(async () => { | ||
const readmeMd: string = argv.readme; | ||
argv["try-require"] = "readme.test.md"; | ||
const autorestConfig = await getAutorestConfig(argv, readmeMd); | ||
console.log(autorestConfig["input-file"]); | ||
console.log(autorestConfig["test-resources"]); | ||
if (autorestConfig["test-resources"] === undefined) { | ||
throw new Error(`No test-scenario file found in '${argv.tag || "default"}'`); | ||
} | ||
const swaggerFilePaths: string[] = autorestConfig["input-file"]; | ||
for (const testResources of autorestConfig["test-resources"]) { | ||
const testScenarioFile = testResources.test; | ||
const fileRoot: string = path.dirname(readmeMd); | ||
let env = { | ||
subscriptionId: "<mySubcriptionId>", | ||
location: "westus", | ||
}; | ||
if (argv.e !== undefined) { | ||
env = JSON.parse(fs.readFileSync(argv.e).toString()); | ||
} | ||
console.log( | ||
`generating postman collection from ${testScenarioFile}. outputDir: ${argv.output}` | ||
); | ||
const opt: PostmanCollectionGeneratorOption = { | ||
name: testScenarioFile.replace(/^.*[\\\/]/, "").replace(".yaml", ""), | ||
testDef: testScenarioFile, | ||
swaggerFilePaths: swaggerFilePaths, | ||
fileRoot: fileRoot, | ||
env: env, | ||
outputFolder: argv.output, | ||
}; | ||
if (!fs.existsSync(argv.output)) { | ||
fs.mkdirSync(argv.output); | ||
} | ||
const generator = new PostmanCollectionGenerator(opt); | ||
await generator.GenerateCollection(); | ||
} | ||
return 0; | ||
}); | ||
} |
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,67 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
/* eslint-disable id-blacklist */ | ||
|
||
import * as fs from "fs"; | ||
import * as path from "path"; | ||
import * as yargs from "yargs"; | ||
|
||
import { cliSuppressExceptions } from "../cliSuppressExceptions"; | ||
import { getAutorestConfig } from "../util/getAutorestConfig"; | ||
import { ReportGenerator } from "../testScenario/reportGenerator"; | ||
export const command = "generate-report [raw-report-path]"; | ||
|
||
export const describe = "Generate report from postman report."; | ||
|
||
export const builder: yargs.CommandBuilder = { | ||
newmanReport: { | ||
describe: "The newman report", | ||
string: true, | ||
}, | ||
tag: { | ||
describe: "the readme tag name.", | ||
string: true, | ||
}, | ||
output: { | ||
alias: "outputDir", | ||
describe: "the output folder.", | ||
string: true, | ||
default: "generated", | ||
}, | ||
readme: { | ||
describe: "path to readme.md file", | ||
string: true, | ||
demandOption: true, | ||
}, | ||
}; | ||
|
||
export async function handler(argv: yargs.Arguments): Promise<void> { | ||
await cliSuppressExceptions(async () => { | ||
const readmeMd: string = argv.readme; | ||
const newmanReport: string = argv.newmanReport; | ||
argv["try-require"] = "readme.test.md"; | ||
const autorestConfig = await getAutorestConfig(argv, readmeMd); | ||
const fileRoot: string = path.dirname(readmeMd); | ||
const swaggerFilePaths: string[] = autorestConfig["input-file"]; | ||
const testScenarioFile = autorestConfig["test-resources"][0].test; | ||
console.log( | ||
`generating report from ${newmanReport}. test-scenario: ${testScenarioFile} outputDir: ${argv.output}` | ||
); | ||
if (!fs.existsSync(argv.output)) { | ||
fs.mkdirSync(argv.output); | ||
} | ||
const generator = new ReportGenerator( | ||
newmanReport, | ||
argv.output, | ||
fileRoot, | ||
swaggerFilePaths, | ||
testScenarioFile, | ||
readmeMd, | ||
argv.tag || "default" | ||
); | ||
await generator.generateReport(); | ||
console.log(`generate report successfully!`); | ||
return 0; | ||
}); | ||
} |
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,81 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
/* eslint-disable id-blacklist */ | ||
|
||
import { dirname, relative as pathRelative, resolve as pathResolve } from "path"; | ||
import globby from "globby"; | ||
import * as yargs from "yargs"; | ||
import { inversifyGetInstance } from "../inversifyUtils"; | ||
import { TestRecordingLoader } from "../testScenario/gen/testRecordingLoader"; | ||
import { RequestTracking, TestScenarioGenerator } from "../testScenario/gen/testScenarioGenerator"; | ||
import { getAutorestConfig } from "../util/getAutorestConfig"; | ||
|
||
export const command = "generate-test-scenario"; | ||
export const describe = "Generate swagger examples from real payload records."; | ||
|
||
export const builder: yargs.CommandBuilder = { | ||
tag: { | ||
describe: "the readme tag name.", | ||
string: true, | ||
}, | ||
recording: { | ||
describe: | ||
"path glob pattern for recording files. Supported format: DotNet recording, Azure Powershell recording, Azure Cli recording", | ||
string: true, | ||
demandOption: true, | ||
}, | ||
readme: { | ||
describe: "path to readme.md file", | ||
string: true, | ||
demandOption: true, | ||
}, | ||
output: { | ||
describe: "path to output test scenario", | ||
string: true, | ||
demandOption: true, | ||
}, | ||
}; | ||
|
||
export async function handler(argv: yargs.Arguments): Promise<void> { | ||
const readmeMd: string = argv.readme; | ||
let output: string = argv.output; | ||
const recording: string = argv.recording; | ||
argv["try-require"] = "readme.test.md"; | ||
|
||
const recordingFilePaths = await globby(recording); | ||
recordingFilePaths.sort(); | ||
const autorestConfig = await getAutorestConfig(argv, readmeMd); | ||
const swaggerFilePaths: string[] = autorestConfig["input-file"]; | ||
const fileRoot = dirname(readmeMd); | ||
output = pathResolve(fileRoot, output); | ||
output = pathRelative(fileRoot, output); | ||
|
||
console.log("input-file:"); | ||
console.log(swaggerFilePaths); | ||
console.log("recording-file:"); | ||
console.log(recordingFilePaths); | ||
console.log("output-file:"); | ||
console.log(`\t${output}\n`); | ||
|
||
const generator = TestScenarioGenerator.create({ | ||
useJsonParser: false, | ||
checkUnderFileRoot: false, | ||
fileRoot, | ||
swaggerFilePaths, | ||
}); | ||
|
||
await generator.initialize(); | ||
|
||
const recordingLoader = inversifyGetInstance(TestRecordingLoader, {}); | ||
const trackingList: RequestTracking[] = []; | ||
for (const filePath of recordingFilePaths) { | ||
console.log(`Transforming:\t${filePath}`); | ||
const tracking = await recordingLoader.load(filePath); | ||
trackingList.push(tracking); | ||
} | ||
await generator.generateTestDefinition(trackingList, output); | ||
|
||
await generator.writeGeneratedFiles(); | ||
process.exit(0); | ||
} |
Oops, something went wrong.