Skip to content

Commit

Permalink
chore(endpoint): update partitions.json (#4046)
Browse files Browse the repository at this point in the history
* chore(endpoint): update partitions.json

* chore(endpoint): add endpoints integration test runner connected to model json test cases

* fix(endpoint): fix partition test

* fix(endpoint): fix partition test

* fix(endpoint): endpoints integration test runner fixes
  • Loading branch information
kuhe authored Oct 17, 2022
1 parent b53f5bd commit e37a76d
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ export const resolveParams = async <
clientConfig: Partial<EndpointResolvedConfig<T>> & Config
) => {
const endpointParams: EndpointParameters = {};
const instructions: EndpointParameterInstructions =
(instructionsSupplier.getEndpointParameterInstructions || (() => null))() || {};
const instructions: EndpointParameterInstructions = instructionsSupplier?.getEndpointParameterInstructions?.() || {};

for (const [name, instruction] of Object.entries(instructions)) {
switch (instruction.type) {
Expand Down

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions packages/middleware-endpoint/src/integration-tests/s3/o.json

This file was deleted.

4 changes: 0 additions & 4 deletions packages/middleware-endpoint/src/integration-tests/s3/oa.json

This file was deleted.

4 changes: 0 additions & 4 deletions packages/middleware-endpoint/src/integration-tests/s3/ol.json

This file was deleted.

4 changes: 0 additions & 4 deletions packages/middleware-endpoint/src/integration-tests/s3/s.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/middleware-signing/src/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export const resolveAwsAuthConfig = <T>(
authScheme = Object.assign(
{},
{
name: "v4",
name: "sigv4",
signingName: input.signingName || input.defaultSigningName!,
signingRegion: await normalizeProvider(input.region)(),
properties: {},
Expand Down
7 changes: 2 additions & 5 deletions packages/util-endpoints/src/lib/aws/partition.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const MOCK_DEFAULT_PARTITION = {
"mock-region-2": {},
},
outputs: {
name: "aws",
dnsSuffix: "mockDefaultDnsSuffix",
dualStackDnsSuffix: "mockDefaultDualStackDnsSuffix",
supportsFIPS: false,
Expand All @@ -23,6 +24,7 @@ const MOCK_PARTITION = {
regionRegex: "mockRegionRegex",
regions: {},
outputs: {
name: "partitionId",
dnsSuffix: "mockPartitionDnsSuffix",
dualStackDnsSuffix: "mockPartitionDualStackDnsSuffix",
supportsFIPS: true,
Expand All @@ -42,7 +44,6 @@ describe("partition", () => {
it("returns region data if it exists", () => {
const regionWithRegionData = "mock-region-1";
expect(partition(regionWithRegionData)).toEqual({
name: MOCK_DEFAULT_PARTITION.id,
...MOCK_DEFAULT_PARTITION.outputs,
...MOCK_DEFAULT_PARTITION.regions[regionWithRegionData],
});
Expand All @@ -51,26 +52,22 @@ describe("partition", () => {
it("returns partition data if region data does not exist", () => {
const regionWithoutRegionData = "mock-region-2";
expect(partition(regionWithoutRegionData)).toEqual({
name: MOCK_DEFAULT_PARTITION.id,
...MOCK_DEFAULT_PARTITION.outputs,
});
});
});

it("should return the partition data when region is matched with regionRegex", () => {
expect(partition(MOCK_DEFAULT_PARTITION.regionRegex)).toEqual({
name: MOCK_DEFAULT_PARTITION.id,
...MOCK_DEFAULT_PARTITION.outputs,
});
expect(partition(MOCK_PARTITION.regionRegex)).toEqual({
name: MOCK_PARTITION.id,
...MOCK_PARTITION.outputs,
});
});

it("should return the default partition when the region is not found", () => {
expect(partition("non-existant-region")).toEqual({
name: MOCK_DEFAULT_PARTITION.id,
...MOCK_DEFAULT_PARTITION.outputs,
});
});
Expand Down
7 changes: 2 additions & 5 deletions packages/util-endpoints/src/lib/aws/partition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ const DEFAULT_PARTITION = partitions.find((partition) => partition.id === "aws")
export const partition = (value: string): EndpointPartition => {
// Check for explicit region listed in the regions array.
for (const partition of partitions) {
const { id, regions, outputs } = partition;
const { regions, outputs } = partition;
for (const [region, regionData] of Object.entries(regions)) {
if (region === value) {
return {
name: id,
...outputs,
...regionData,
};
Expand All @@ -27,10 +26,9 @@ export const partition = (value: string): EndpointPartition => {

// Check for region that matches a regionRegex pattern.
for (const partition of partitions) {
const { id, regionRegex, outputs } = partition;
const { regionRegex, outputs } = partition;
if (new RegExp(regionRegex).test(value)) {
return {
name: id,
...outputs,
};
}
Expand All @@ -45,7 +43,6 @@ export const partition = (value: string): EndpointPartition => {

// Return the default partition.
return {
name: DEFAULT_PARTITION.id,
...DEFAULT_PARTITION.outputs,
};
};
13 changes: 11 additions & 2 deletions packages/util-endpoints/src/lib/aws/partitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"aws-global": {}
},
"outputs": {
"name": "aws",
"dnsSuffix": "amazonaws.com",
"dualStackDnsSuffix": "api.aws",
"supportsFIPS": true,
Expand All @@ -45,6 +46,7 @@
"aws-us-gov-global": {}
},
"outputs": {
"name": "aws-us-gov",
"dnsSuffix": "amazonaws.com",
"dualStackDnsSuffix": "api.aws",
"supportsFIPS": true,
Expand All @@ -60,6 +62,7 @@
"aws-cn-global": {}
},
"outputs": {
"name": "aws-cn",
"dnsSuffix": "amazonaws.com.cn",
"dualStackDnsSuffix": "api.amazonwebservices.com.cn",
"supportsFIPS": true,
Expand All @@ -70,23 +73,29 @@
"id": "aws-iso",
"regionRegex": "^us\\-iso\\-\\w+\\-\\d+$",
"outputs": {
"name": "aws-iso",
"dnsSuffix": "c2s.ic.gov",
"supportsFIPS": true,
"supportsDualStack": false,
"dualStackDnsSuffix": "c2s.ic.gov"
},
"regions": {}
"regions": {
"aws-iso-global": {}
}
},
{
"id": "aws-iso-b",
"regionRegex": "^us\\-isob\\-\\w+\\-\\d+$",
"outputs": {
"name": "aws-iso-b",
"dnsSuffix": "sc2s.sgov.gov",
"supportsFIPS": true,
"supportsDualStack": false,
"dualStackDnsSuffix": "sc2s.sgov.gov"
},
"regions": {}
"regions": {
"aws-iso-b-global": {}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -1,64 +1,84 @@
import * as S3Namespace from "@aws-sdk/client-s3";
import { EndpointV2 } from "@aws-sdk/types";
import { resolveParams } from "@aws-sdk/middleware-endpoint";
import { EndpointParameters, EndpointV2 } from "@aws-sdk/types";
import * as fs from "fs";
import * as path from "path";

// import { defaultEndpointResolver } from "../../../../clients/client-s3/src/endpoint/endpointResolver";
const defaultEndpointResolver = (...args: any): any => {};
import { resolveParams } from "../adaptors";
import { EndpointExpectation, EndpointTestCase, ErrorExpectation, ServiceNamespace } from "./integration-test-types";
import customTests from "./s3/custom-tests.json";
import generatedTests from "./s3/generated-tests.json";
import o from "./s3/o.json";
import oa from "./s3/oa.json";
import ol from "./s3/ol.json";
import s from "./s3/s.json";

describe("endpoints 2.0 service integration", () => {
describe("s3", () => {
it("placeholder", () => {});
const clientList: string[] = [];
const root = path.join(__dirname, "..", "..");
const clients = fs.readdirSync(path.join(root, "clients"));
clientList.push(...clients);

if (customTests.testCases?.length) {
describe("custom", () => {
runTestCases(customTests, S3Namespace as ServiceNamespace);
});
}
describe("client list", () => {
it("should be at least 300 clients", () => {
expect(clientList.length).toBeGreaterThan(300);
});
});

if (generatedTests.testCases?.length) {
describe("generated", () => {
runTestCases(generatedTests, S3Namespace as ServiceNamespace);
});
}
for (const client of clientList) {
const serviceName = client.slice(7);

return; // skipping additional tests for now.
let defaultEndpointResolver;
let namespace;
let model;

for (const group of [o, oa, ol, s]) {
if (group.testCases?.length) {
describe("additional test group", () => {
runTestCases(group, S3Namespace as ServiceNamespace);
});
// this may also work with dynamic async import() in a beforeAll() block,
// but needs more effort than using synchronous require().
try {
defaultEndpointResolver =
require(`@aws-sdk/client-${serviceName}/src/endpoint/endpointResolver`).defaultEndpointResolver;
namespace = require(`@aws-sdk/client-${serviceName}`);
model = require(path.join(root, "codegen", "sdk-codegen", "aws-models", serviceName + ".json"));
} catch (e) {
defaultEndpointResolver = null;
namespace = null;
model = null;
if (e.code !== "MODULE_NOT_FOUND") {
console.error(e);
}
}

describe(`client-${serviceName} endpoint test cases`, () => {
if (defaultEndpointResolver && namespace && model) {
const [, service] = Object.entries(model.shapes).find(([k, v]) => v?.["type"] === "service") as any;
const [, tests] = Object.entries(service.traits).find(([k, v]) => k === "smithy.rules#endpointTests") as any;
if (tests?.testCases) {
runTestCases(tests, service, defaultEndpointResolver, "");
} else {
it.skip("has no test cases", () => {});
}
} else {
it.skip("unable to load endpoint resolver, namespace, or test cases", () => {});
}
});
});
}

function runTestCases({ testCases }: { testCases: EndpointTestCase[] }, service: ServiceNamespace) {
const start = 0; //67;
const end = 100; //68;
for (const testCase of testCases.slice(start, end)) {
runTestCase(testCase, service);
function runTestCases(
{ testCases }: { testCases: EndpointTestCase[] },
service: ServiceNamespace,
defaultEndpointResolver: (endpointParams: EndpointParameters) => EndpointV2,
serviceId: string
) {
for (const testCase of testCases) {
runTestCase(testCase, service, defaultEndpointResolver, serviceId);
}
}

async function runTestCase(testCase: EndpointTestCase, service: ServiceNamespace) {
async function runTestCase(
testCase: EndpointTestCase,
service: ServiceNamespace,
defaultEndpointResolver: (endpointParams: EndpointParameters) => EndpointV2,
serviceId: string
) {
const { documentation, params = {}, expect: expectation, operationInputs } = testCase;

if (params.UseGlobalEndpoint || params.Region === "aws-global") {
it.skip(documentation || "undocumented testcase", () => {});
return;
}

if (service === S3Namespace) {
params.serviceId = "s3";
}
params.serviceId = serviceId;

it(documentation || "undocumented testcase", async () => {
if (isEndpointExpectation(expectation)) {
Expand All @@ -68,13 +88,11 @@ async function runTestCase(testCase: EndpointTestCase, service: ServiceNamespace
const { operationName, operationParams = {} } = operationInput;
const endpointParams = await resolveParams(operationParams, service[`${operationName}Command`], params);
const observed = defaultEndpointResolver(endpointParams as any);
console.log("params were", endpointParams);
assertEndpointResolvedCorrectly(endpoint, observed);
}
} else {
const endpointParams = await resolveParams({}, {}, params);
const observed = defaultEndpointResolver(endpointParams as any);
console.log("params were", endpointParams);
assertEndpointResolvedCorrectly(endpoint, observed);
}
}
Expand All @@ -97,7 +115,6 @@ async function runTestCase(testCase: EndpointTestCase, service: ServiceNamespace
} else {
const endpointParams = await resolveParams({}, {}, params).catch(pass);
const observedError = await (async () => defaultEndpointResolver(endpointParams as any))().catch(pass);
console.error(observedError);
expect(observedError).not.toBeUndefined();
expect(observedError?.url).toBeUndefined();
// expect(normalizeQuotes(String(observedError))).toContain(normalizeQuotes(error));
Expand All @@ -117,7 +134,7 @@ function assertEndpointResolvedCorrectly(expected: EndpointExpectation["endpoint
expect(observed.headers).toEqual(headers);
}
if (authSchemes) {
// expect(observed.properties?.authSchemes).toEqual(authSchemes);
expect(observed.properties?.authSchemes).toEqual(authSchemes);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EndpointParameterInstructionsSupplier } from "../adaptors";
import { EndpointParameterInstructionsSupplier } from "@aws-sdk/middleware-endpoint";

export interface EndpointTestCase {
documentation?: string;
Expand Down Expand Up @@ -29,4 +29,4 @@ export type ErrorExpectation = {

export interface ServiceNamespace {
[Command: string]: EndpointParameterInstructionsSupplier;
}
}
4 changes: 4 additions & 0 deletions tests/endpoints-2.0/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: "ts-jest",
testMatch: ["**/*.spec.ts"],
};

0 comments on commit e37a76d

Please sign in to comment.