-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): fix bug that required cdktf.json in parent directory when r…
…unning convert `path.resolve(rootPath, ..)` will return rootPath if there's no more parent directory. This caused an infinite loop ending in `RangeError: Maximum call stack size exceeded`. Resolves #1247
- Loading branch information
Showing
2 changed files
with
71 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import execa from "execa"; | ||
import path from "path"; | ||
import { promises as fs } from "fs"; | ||
import { mkdtemp } from "../../lib/util"; | ||
|
||
const cdktfBin = path.resolve(__dirname, "../../bin/cdktf"); | ||
const input = ` | ||
resource "null_resource" "dummy" {} | ||
`; | ||
|
||
describe("convert command", () => { | ||
it("proposes specifying a provider version", async () => { | ||
await mkdtemp(async (cwd) => { | ||
await fs.writeFile( | ||
path.resolve(cwd, "cdktf.json"), | ||
JSON.stringify({ terraformProviders: [] }) | ||
); | ||
const child = execa(cdktfBin, ["convert"], { stdio: "pipe", cwd, input }); | ||
const result = await child; | ||
expect(result.stderr).toEqual(""); | ||
expect(result.stdout).toContain( | ||
`The following providers are missing schema information and might need manual adjustments to synthesize correctly: null.` | ||
); | ||
expect(result.stdout).toContain( | ||
`import * as NullProvider from "./.gen/providers/null";` | ||
); | ||
expect(result.stdout).toContain( | ||
`new NullProvider.Resource(this, "dummy", {});` | ||
); | ||
}); | ||
}); | ||
it("reads provider version from existing cdktf.json", async () => { | ||
await mkdtemp(async (cwd) => { | ||
await fs.writeFile( | ||
path.resolve(cwd, "cdktf.json"), | ||
JSON.stringify({ terraformProviders: ["hashicorp/null@~> 2.0"] }) | ||
); | ||
const child = execa(cdktfBin, ["convert"], { stdio: "pipe", cwd, input }); | ||
const result = await child; | ||
expect(result.stderr).toEqual(""); | ||
expect(result.stdout).not.toContain( | ||
`The following providers are missing schema information and might need manual adjustments to synthesize correctly: null.` | ||
); | ||
expect(result.stdout).toContain( | ||
`import * as NullProvider from "./.gen/providers/null";` | ||
); | ||
expect(result.stdout).toContain( | ||
`new NullProvider.Resource(this, "dummy", {});` | ||
); | ||
}); | ||
}); | ||
it("works if no cdktf.json could be found", async () => { | ||
await mkdtemp(async (cwd) => { | ||
const child = execa(cdktfBin, ["convert"], { stdio: "pipe", cwd, input }); | ||
const result = await child; | ||
expect(result.stderr).toEqual(""); | ||
expect(result.stdout).toContain( | ||
`The following providers are missing schema information and might need manual adjustments to synthesize correctly: null.` | ||
); | ||
expect(result.stdout).toContain( | ||
`import * as NullProvider from "./.gen/providers/null";` | ||
); | ||
expect(result.stdout).toContain( | ||
`new NullProvider.Resource(this, "dummy", {});` | ||
); | ||
}); | ||
}); | ||
}); |