Skip to content

Commit 727a541

Browse files
author
William Faithfull
committed
954: Adds a sanity check test that the import command can actually import an openAPI spec, and fix a race condition bug arising from it.
1 parent fc03134 commit 727a541

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/breadboard-cli/src/commands/import.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export const importGraph = async (url: string, options: ImportOptions) => {
8282

8383
const board = apiRef;
8484
if (outputPath != undefined) {
85-
outputBoard(board.board.board, api, outputPath);
85+
await outputBoard(board.board.board, api, outputPath);
8686
} else {
8787
console.log(JSON.stringify(board.board.board, null, 2));
8888
}

packages/breadboard-cli/tests/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import test from "ava";
99
import { ExecException, exec } from "child_process";
1010
import * as fs from "fs";
1111
import path from "path";
12+
import { importGraph } from "../src/commands/import.js";
1213

1314
const packageDir = getPackageDir("@google-labs/breadboard-cli");
1415
console.debug("packageDir", packageDir);
@@ -203,6 +204,25 @@ test.after.always(() => {
203204
fs.rmSync(testDataDir, { recursive: true });
204205
});
205206

207+
test("import can import an openapi spec", async (t) => {
208+
await importGraph("https://raw.githubusercontent.com/OAI/OpenAPI-Specification/3.1.0/examples/v3.0/petstore.yaml", {
209+
api: undefined,
210+
output: testDataDir,
211+
root: "",
212+
save: false,
213+
watch: false
214+
})
215+
216+
const routes: string[] = ["createPets.json", "listPets.json", "showPetById.json"]
217+
.map(f =>
218+
path.resolve(testDataDir, f)
219+
)
220+
221+
routes.forEach(f => {
222+
t.true(fs.existsSync(f))
223+
})
224+
})
225+
206226
//////////////////////////////////////////////////
207227
test("all test files exist", (t) => {
208228
testFiles.forEach((p) => {

0 commit comments

Comments
 (0)