Skip to content

Commit dc9a8e9

Browse files
authored
chore: remove cdktf from tests (#277)
<!-- Unless this is a very simple 1-line-of-code change, please create a new issue describing the change you're proposing first, then link to it from this PR. Read more about our process in our contributing guide: https://github.com/open-constructs/cdk-terrain/blob/main/CONTRIBUTING.md --> ### Related issue Fixes #8 ### Description - Removes `cdktf` from the provider x command integration tests and instead tests using `cdktn`. - Exact versions used and sometimes providers used needed to be updated to match actual availability - Fixes an issue with C# package search. - Fixes two issues with Java installed package identifications - Hardcoded to cdktf group - Regex match incorrect in the case where one value is missing (only the version portion could be missing) ### Checklist - [ ] I have updated the PR title to match [CDKTN's style guide](https://github.com/open-constructs/cdk-terrain/blob/main/CONTRIBUTING.md#pull-requests-1) - [ ] I have run the linter on my code locally - [ ] I have performed a self-review of my code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the [documentation](https://github.com/open-constructs/cdk-terrain-docs/tree/main/content) if applicable - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works if applicable - [ ] New and existing unit tests pass locally with my changes <!-- If this is still a work in progress, feel free to open a draft PR until you're able to check off all the items on the list above -->
1 parent e1a69fc commit dc9a8e9

23 files changed

Lines changed: 149 additions & 197 deletions

File tree

packages/@cdktn/cli-core/src/lib/dependencies/dependency-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export class DependencyManager {
233233
provider: ${constraint.simplifiedName}
234234
version : ${constraint.version || "latest"}
235235
language: ${this.targetLanguage}
236-
cdktf : ${this.cdktfVersion}
236+
cdktn : ${this.cdktfVersion}
237237
`);
238238

239239
if (

packages/@cdktn/cli-core/src/lib/dependencies/package-manager.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,9 @@ class NugetPackageManager extends PackageManager {
561561
logger.debug(`Checking if ${packageName}@${packageVersion} is available`);
562562

563563
const [owner, ...rest] = packageName.split(".");
564+
const fixedOwner = packageName.startsWith("Io.Cdktn") ? "cdktn" : owner;
564565
const id = rest[rest.length - 1];
565-
const url = `https://azuresearch-usnc.nuget.org/query?q=owner:${owner}%20id:${id}&prerelease=false&semVerLevel=2.0.0`;
566+
const url = `https://azuresearch-usnc.nuget.org/query?q=owner:${fixedOwner}%20id:${id}&prerelease=false&semVerLevel=2.0.0`;
566567
logger.debug(`Fetching package metadata from Nuget: '${url}'`);
567568

568569
const response = await fetchWithRetry(url);
@@ -846,7 +847,7 @@ class GradlePackageManager extends JavaPackageManager {
846847
);
847848
})
848849
.map((dep) => ({
849-
name: `com.hashicorp.${dep!.name}`,
850+
name: `${dep!.group}.${dep!.name}`,
850851
version: dep!.version,
851852
}));
852853

packages/@cdktn/commons/src/gradle.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ export function getDependencyInformationFromLine(
9494

9595
if (matches[3] === undefined) {
9696
return {
97-
group: "",
98-
name: matches[1],
99-
version: matches[2],
97+
group: matches[1],
98+
name: matches[2],
99+
version: "",
100100
};
101101
}
102102

packages/@cdktn/hcl2cdk/test/helpers/convert.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,6 @@ const preSynth: Record<
247247
<TargetFramework>net6.0</TargetFramework>
248248
</PropertyGroup>
249249
250-
<ItemGroup>
251-
<PackageReference Include="HashiCorp.Cdktf" Version="0.21.0" />
252-
</ItemGroup>
253-
254250
<ItemGroup>
255251
<PackageReference Include="Io.Cdktn" Version="0.0.0" />
256252
</ItemGroup>

test/csharp/provider-add-command/test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ describe("provider add command", () => {
1919
await driver.exec("dotnet", [
2020
"add",
2121
"package",
22-
"HashiCorp.Cdktf",
22+
"Io.Cdktn",
2323
"--version",
24-
"0.12.2",
24+
"0.23.1",
2525
]);
2626
}, 500_000);
2727

2828
it("detects correct cdktn version", async () => {
2929
const res = await driver.exec("cdktn", ["debug"]);
30-
expect(res.stdout).toContain("cdktf: 0.12.2");
30+
expect(res.stdout).toContain("cdktn: 0.23.1");
3131
});
3232

3333
onPosix(
@@ -36,19 +36,19 @@ describe("provider add command", () => {
3636
const res = await driver.exec("cdktn", [
3737
"provider",
3838
"add",
39-
"random@=3.4.2", // this is not the latest version, but theres v3.0.52 of the pre-built provider resulting in exactly this package
39+
"random@=3.9.0",
4040
]);
4141
expect(sanitizeTimestamps(res.stdout)).toMatchInlineSnapshot(`
4242
"[<TIMESTAMP>] [INFO] default - Checking whether pre-built provider exists for the following constraints:
4343
provider: random
44-
version : =3.4.2
44+
version : =3.9.0
4545
language: csharp
46-
cdktf : 0.12.2
46+
cdktn : 0.23.1
4747
4848
4949
[<TIMESTAMP>] [INFO] default - Found pre-built provider.
5050
51-
Installing package HashiCorp.Cdktf.Providers.Random @ 2.0.52 using "dotnet add package HashiCorp.Cdktf.Providers.Random --version 2.0.52".
51+
Installing package Io.Cdktn.Providers.Random @ 14.1.0 using "dotnet add package Io.Cdktn.Providers.Random --version 14.1.0".
5252
5353
Package installed.
5454
"
@@ -58,7 +58,7 @@ describe("provider add command", () => {
5858
const proj = driver.readLocalFile("MyTerraformStack.csproj");
5959

6060
expect(proj).toContain(
61-
'<PackageReference Include="HashiCorp.Cdktf.Providers.Random" Version="2.0.52" />',
61+
'<PackageReference Include="Io.Cdktn.Providers.Random" Version="14.1.0" />',
6262
);
6363
},
6464
500_000,
@@ -70,19 +70,19 @@ describe("provider add command", () => {
7070
const res = await driver.exec("cdktn", [
7171
"provider",
7272
"add",
73-
"random@=3.4.2", // this is not the latest version, but theres v2.0.52 of the pre-built provider resulting in exactly this package
73+
"random@=3.9.0",
7474
]);
7575
expect(sanitizeTimestamps(res.stdout)).toMatchInlineSnapshot(`
7676
"[<TIMESTAMP>] [INFO] default - Checking whether pre-built provider exists for the following constraints:
7777
provider: random
78-
version : =3.4.2
78+
version : =3.9.0
7979
language: csharp
80-
cdktf : 0.12.2
80+
cdktn : 0.23.1
8181
8282
8383
[<TIMESTAMP>] [INFO] default - Found pre-built provider.
8484
85-
Installing package HashiCorp.Cdktf.Providers.Random @ 2.0.52 using "dotnet add package HashiCorp.Cdktf.Providers.Random --version 2.0.52".
85+
Installing package Io.Cdktn.Providers.Random @ 14.1.0 using "dotnet add package Io.Cdktn.Providers.Random --version 14.1.0".
8686
8787
Package installed.
8888
"
@@ -92,7 +92,7 @@ describe("provider add command", () => {
9292
const proj = driver.readLocalFile("MyTerraformStack.csproj");
9393

9494
expect(proj).toContain(
95-
'<PackageReference Include="HashiCorp.Cdktf.Providers.Random" Version="2.0.52" />',
95+
'<PackageReference Include="Io.Cdktn.Providers.Random" Version="14.1.0" />',
9696
);
9797
},
9898
500_000,
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`provider list command lists both local and prebuilt providers with tabular output 1`] = `
4-
"┌───────────────┬──────────────────┬─────────┬───────┬────────────┬──────────────────────────────────┬─────────────────┐
5-
│ Provider Name │ Provider Version │ CDKTF │ CDKTN │ Constraint │ Package Name │ Package Version │
6-
├───────────────┼──────────────────┼─────────┼───────┼────────────┼──────────────────────────────────┼─────────────────┤
7-
│ null │ 3.2.4 │ │ ~> 3.2.0 │ │ │
8-
├───────────────┼──────────────────┼─────────┼───────┼────────────┼──────────────────────────────────┼─────────────────┤
9-
│ local │ 2.2.3 │ │ =2.2.3 │ │ │
10-
├───────────────┼──────────────────┼─────────┼───────┼────────────┼──────────────────────────────────┼─────────────────┤
11-
│ random │ 3.4.3^0.13.0 │ │ │ HashiCorp.Cdktf.Providers.Random │ 3.0.11
12-
└───────────────┴──────────────────┴─────────┴───────┴────────────┴──────────────────────────────────┴─────────────────┘
4+
"┌───────────────┬──────────────────┬───────┬─────────┬────────────┬───────────────────────────┬─────────────────┐
5+
│ Provider Name │ Provider Version │ CDKTF │ CDKTN │ Constraint │ Package Name │ Package Version │
6+
├───────────────┼──────────────────┼───────┼─────────┼────────────┼───────────────────────────┼─────────────────┤
7+
│ null │ 3.2.4 │ │ ~> 3.2.0 │ │ │
8+
├───────────────┼──────────────────┼───────┼─────────┼────────────┼───────────────────────────┼─────────────────┤
9+
│ local │ 2.2.3 │ │ =2.2.3 │ │ │
10+
├───────────────┼──────────────────┼───────┼─────────┼────────────┼───────────────────────────┼─────────────────┤
11+
│ random │ 3.8.1 │ ^0.23.0 │ │ Io.Cdktn.Providers.Random │ 14.0.0
12+
└───────────────┴──────────────────┴───────┴─────────┴────────────┴───────────────────────────┴─────────────────┘
1313
"
1414
`;

test/csharp/provider-list-command/test.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,21 @@ describe("provider list command", () => {
88
driver = new TestDriver(__dirname, {
99
DISABLE_VERSION_CHECK: "true",
1010
CI: "1",
11-
}); // reset CDKTF_DIST set by run-against-dist script & disable version check as we have to use an older version of cdktf-cli
11+
}); // reset CDKTF_DIST set by run-against-dist script & disable version check as we have to use an older version of cdktn-cli
1212
await driver.setupCsharpProject();
1313

1414
await driver.exec("dotnet", [
1515
"add",
1616
"package",
17-
"HashiCorp.Cdktf",
17+
"Io.Cdktn",
1818
"--version",
19-
"0.13.0",
19+
"0.23.1",
2020
]);
2121
}, 500_000);
2222

2323
describe("lists both local and prebuilt providers", () => {
2424
beforeEach(async () => {
25-
await driver.exec("cdktn", [
26-
"provider",
27-
"add",
28-
"random@=3.4.3", // this is not the latest version, but theres v0.2.55 of the pre-built provider resulting in exactly this package
29-
]);
25+
await driver.exec("cdktn", ["provider", "add", "random@=3.8.1"]);
3026

3127
await driver.exec("cdktn", [
3228
"provider",
@@ -58,11 +54,11 @@ describe("provider list command", () => {
5854

5955
expect(output.prebuilt[0]).toEqual(
6056
expect.objectContaining({
61-
packageName: "HashiCorp.Cdktf.Providers.Random",
62-
packageVersion: "3.0.11",
57+
packageName: "Io.Cdktn.Providers.Random",
58+
packageVersion: "14.0.0",
6359
providerName: "random",
64-
providerVersion: "3.4.3",
65-
cdktfVersion: "^0.13.0",
60+
providerVersion: "3.8.1",
61+
cdktnVersion: "^0.23.0",
6662
}),
6763
);
6864
}, 120_000);

test/csharp/provider-upgrade-command/test.ts

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,34 @@ describe("provider upgrade command", () => {
88
beforeEach(async () => {
99
driver = new TestDriver(__dirname, {
1010
DISABLE_VERSION_CHECK: "true",
11-
}); // reset CDKTF_DIST set by run-against-dist script & disable version check as we have to use an older version of cdktf-cli
11+
}); // reset CDKTF_DIST set by run-against-dist script & disable version check as we have to use an older version of cdktn-cli
1212
await driver.setupCsharpProject();
1313

1414
await driver.exec("dotnet", [
1515
"add",
1616
"package",
17-
"HashiCorp.Cdktf",
17+
"Io.Cdktn",
1818
"--version",
19-
"0.12.2",
19+
"0.23.1",
2020
]);
2121
}, 500_000);
2222

2323
onPosix(
2424
"installs pre-built provider using nuget",
2525
async () => {
26-
await driver.exec("cdktn", [
27-
"provider",
28-
"add",
29-
"random@=3.4.2", // this is not the latest version, but theres v2.0.52 of the pre-built provider resulting in exactly this package
30-
]);
26+
await driver.exec("cdktn", ["provider", "add", "random@=3.8.1"]);
3127

3228
expect(driver.readLocalFile("MyTerraformStack.csproj")).toContain(
33-
'<PackageReference Include="HashiCorp.Cdktf.Providers.Random" Version="2.0.52" />',
29+
'<PackageReference Include="Io.Cdktn.Providers.Random" Version="14.0.0" />',
3430
);
3531

36-
await driver.exec("cdktn", ["provider", "upgrade", "random@=3.4.3"]);
32+
await driver.exec("cdktn", ["provider", "upgrade", "random@=3.9.0"]);
3733

3834
expect(driver.readLocalFile("MyTerraformStack.csproj")).not.toContain(
39-
'<PackageReference Include="HashiCorp.Cdktf.Providers.Random" Version="2.0.52" />',
35+
'<PackageReference Include="Io.Cdktn.Providers.Random" Version="14.0.0" />',
4036
);
4137
expect(driver.readLocalFile("MyTerraformStack.csproj")).toContain(
42-
'<PackageReference Include="HashiCorp.Cdktf.Providers.Random" Version="2.0.79" />',
38+
'<PackageReference Include="Io.Cdktn.Providers.Random" Version="14.1.0" />',
4339
);
4440
},
4541
500_000,
@@ -48,23 +44,19 @@ describe("provider upgrade command", () => {
4844
onWindows(
4945
"installs pre-built provider using nuget",
5046
async () => {
51-
await driver.exec("cdktn", [
52-
"provider",
53-
"add",
54-
"random@=3.4.2", // this is not the latest version, but theres v2.0.52 of the pre-built provider resulting in exactly this package
55-
]);
47+
await driver.exec("cdktn", ["provider", "add", "random@=3.8.1"]);
5648

5749
expect(driver.readLocalFile("MyTerraformStack.csproj")).toContain(
58-
'<PackageReference Include="HashiCorp.Cdktf.Providers.Random" Version="2.0.52" />',
50+
'<PackageReference Include="Io.Cdktn.Providers.Random" Version="14.0.0" />',
5951
);
6052

61-
await driver.exec("cdktn", ["provider", "upgrade", "random@=3.4.3"]);
53+
await driver.exec("cdktn", ["provider", "upgrade", "random@=3.9.0"]);
6254

6355
expect(driver.readLocalFile("MyTerraformStack.csproj")).not.toContain(
64-
'<PackageReference Include="HashiCorp.Cdktf.Providers.Random" Version="2.0.52" />',
56+
'<PackageReference Include="Io.Cdktn.Providers.Random" Version="14.0.0" />',
6557
);
6658
expect(driver.readLocalFile("MyTerraformStack.csproj")).toContain(
67-
'<PackageReference Include="HashiCorp.Cdktf.Providers.Random" Version="2.0.79" />',
59+
'<PackageReference Include="Io.Cdktn.Providers.Random" Version="14.1.0" />',
6860
);
6961
},
7062
500_000,

test/go/provider-add-command/test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,25 @@ describe("provider add command", () => {
8787
beforeEach(async () => {
8888
driver = new TestDriver(__dirname, {
8989
DISABLE_VERSION_CHECK: "true",
90-
}); // reset CDKTF_DIST set by run-against-dist script & disable version check as we have to use an older version of cdktf-cli
90+
}); // reset CDKTF_DIST set by run-against-dist script & disable version check as we have to use an older version of cdktn-cli
9191
await driver.setupGoProject();
9292

9393
await driver.exec("go", [
9494
"get",
95-
"github.com/hashicorp/terraform-cdk-go/cdktf@v0.13.0",
95+
"github.com/open-constructs/cdk-terrain-go/cdktn@v0.23.1",
9696
]);
9797
});
9898

9999
it("detects correct cdktn version", async () => {
100100
const res = await driver.exec("cdktn", ["debug"]);
101-
expect(res.stdout).toContain("cdktf: 0.13.0");
101+
expect(res.stdout).toContain("cdktn: 0.23.1");
102102
});
103103

104104
test("installs pre-built provider using go get", async () => {
105105
const res = await driver.exec("cdktn", [
106106
"provider",
107107
"add",
108-
"random@=3.4.3", // this won't always be the latest version, but theres v3.0.11 of the pre-built provider resulting in exactly this package
108+
"random@=3.9.0",
109109
]);
110110

111111
// no snapshot, as the output also contains logs from Go upgrading JSII dependencies which might
@@ -115,32 +115,32 @@ describe("provider add command", () => {
115115
);
116116

117117
expect(sanitizeTimestamps(res.stdout)).toContain(`provider: random
118-
version : =3.4.3
118+
version : =3.9.0
119119
language: go
120-
cdktf : 0.13.0`);
120+
cdktn : 0.23.1`);
121121

122122
expect(sanitizeTimestamps(res.stdout)).toContain(
123123
`[<TIMESTAMP>] [INFO] default - Found pre-built provider.`,
124124
);
125125

126126
expect(sanitizeTimestamps(res.stdout)).toContain(
127-
`Adding package github.com/cdktf/cdktf-provider-random-go/random @ 3.0.11`,
127+
`Adding package github.com/cdktn-io/cdktn-provider-random-go/random @ 14.1.0`,
128128
);
129129

130130
expect(sanitizeTimestamps(res.stdout)).toContain(
131-
"added github.com/cdktf/cdktf-provider-random-go/random/v3 v3.0.11",
131+
"added github.com/cdktn-io/cdktn-provider-random-go/random/v14 v14.1.0",
132132
);
133133
expect(sanitizeTimestamps(res.stdout)).toContain("Package installed.");
134134

135135
// go also prints to stderr, weird but 🤷
136136
expect(res.stderr).toContain(
137-
"added github.com/cdktf/cdktf-provider-random-go/random/v3 v3.0.11",
137+
"added github.com/cdktn-io/cdktn-provider-random-go/random/v14 v14.1.0",
138138
);
139139

140140
const goMod = driver.readLocalFile("go.mod");
141141

142142
expect(goMod).toContain(
143-
"github.com/cdktf/cdktf-provider-random-go/random/v3 v3.0.11",
143+
"github.com/cdktn-io/cdktn-provider-random-go/random/v14 v14.1.0",
144144
);
145145
}, 180_000);
146146
});

0 commit comments

Comments
 (0)