Skip to content

Commit 983b512

Browse files
committed
chore: add functional test for hostname generator
1 parent b9b7301 commit 983b512

File tree

8 files changed

+461
-4
lines changed

8 files changed

+461
-4
lines changed

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/EndpointGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private void writeEndpointProviderFunction() {
133133
writer.openBlock("export const defaultRegionInfoProvider: RegionInfoProvider = (\n"
134134
+ " region: string,\n"
135135
+ " options?: any\n"
136-
+ ") {", "};", () -> {
136+
+ ") => {", "};", () -> {
137137
writer.openBlock("switch (region) {", "}", () -> {
138138
writer.write("// First, try to match exact region names.");
139139
for (Map.Entry<String, ObjectNode> entry : endpoints.entrySet()) {
@@ -144,7 +144,7 @@ private void writeEndpointProviderFunction() {
144144
writer.write("// Next, try to match partition endpoints.");
145145
writer.write("default:").indent();
146146
partitions.values().forEach(partition -> {
147-
writer.openBlock("if (region in $L) {", "}", partition.regionVariableName, () -> {
147+
writer.openBlock("if ($L.has(region)) {", "}", partition.regionVariableName, () -> {
148148
writePartitionEndpointResolver(partition);
149149
});
150150
});

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
"build:smithy-client": "lerna run --scope '@aws-sdk/client-rds-data' --include-dependencies pretest",
1515
"pretest": "yarn build:crypto-dependencies && yarn build:smithy-client",
1616
"test": "jest --coverage --passWithNoTests",
17-
"pretest-all": "lerna run pretest",
18-
"test-all": "jest --coverage",
17+
"test:functional": "jest --config tests/functional/jest.config.js --passWithNoTests",
1918
"integ-test": "cucumber.js"
2019
},
2120
"repository": {

tests/functional/endpoints/fixtures.js

Lines changed: 402 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const { KNOWN_REGIONS } = require("./fixtures");
2+
const { getRegionInfoProvider } = require("../util/regioninfo-provider");
3+
4+
describe("hostname for know regions", () => {
5+
for (const region of Object.keys(KNOWN_REGIONS)) {
6+
describe(region, () => {
7+
for (const [service, hostname] of Object.entries(KNOWN_REGIONS[region])) {
8+
it(`${service} should resolve to hostname ${hostname}`, () => {
9+
const regionInfoProvider = getRegionInfoProvider(service);
10+
expect(regionInfoProvider(region).hostname).toBe(hostname);
11+
});
12+
}
13+
});
14+
}
15+
});

tests/functional/jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const base = require("../../jest.config.base");
2+
module.exports = {
3+
...base,
4+
testMatch: ["./**/?(*.)+(spec|test).js?(x)"]
5+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports.SIGNING_NAMES = {
2+
"us-west-2": {
3+
"rds-data": undefined
4+
}
5+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const { SIGNING_NAMES } = require("./fixtures");
2+
const { getRegionInfoProvider } = require("../util/regioninfo-provider");
3+
4+
describe("signing names for know regions", () => {
5+
for (const region of Object.keys(SIGNING_NAMES)) {
6+
describe(region, () => {
7+
for (const [service, signingName] of Object.entries(
8+
SIGNING_NAMES[region]
9+
)) {
10+
it(`${service} should infer signing name ${signingName}`, () => {
11+
const regionInfoProvider = getRegionInfoProvider(service);
12+
expect(regionInfoProvider(region).signingService).toBe(signingName);
13+
});
14+
}
15+
});
16+
}
17+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const { join } = require("path");
2+
module.exports.getRegionInfoProvider = fromService => {
3+
const path = join(
4+
"..",
5+
"..",
6+
"..",
7+
"clients",
8+
`client-${fromService}`,
9+
"dist",
10+
"cjs",
11+
"endpoints"
12+
);
13+
return require(path).defaultRegionInfoProvider;
14+
};

0 commit comments

Comments
 (0)