Skip to content

Commit

Permalink
test(endpoints): skip reading defaultEndpointResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Aug 9, 2024
1 parent a50628b commit 6e5b22d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
25 changes: 11 additions & 14 deletions tests/endpoints-2.0/endpoints-integration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { resolveParams } from "@smithy/middleware-endpoint";
import { EndpointParameters, EndpointV2 } from "@smithy/types";
import { EndpointV2 } from "@smithy/types";
import { resolveEndpoint, EndpointParams } from "@smithy/util-endpoints";
import * as fs from "fs";
import * as path from "path";

Expand All @@ -16,31 +17,27 @@ describe("client list", () => {
describe.each(clientList)(`%s endpoint test cases`, (client) => {
const serviceName = client.slice(7);

let defaultEndpointResolver: any;
let namespace: any;
let model: any;

// 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);
}
}

if (defaultEndpointResolver && namespace && model) {
if (namespace && model) {
for (const value of Object.values(model.shapes)) {
if (typeof value === "object" && value !== null && "type" in value && value.type === "service") {
const service = value as ServiceModel;
runTestCases(service, namespace, defaultEndpointResolver);
runTestCases(service, namespace);
break;
}
}
Expand All @@ -50,13 +47,13 @@ describe("client list", () => {
});
});

function runTestCases(
service: ServiceModel,
namespace: ServiceNamespace,
defaultEndpointResolver: (endpointParams: EndpointParameters) => EndpointV2
) {
function runTestCases(service: ServiceModel, namespace: ServiceNamespace) {
const serviceId = service.traits["aws.api#service"].serviceId;
const testCases = service.traits["smithy.rules#endpointTests"]?.testCases;

const ruleSet = service.traits["smithy.rules#endpointRuleSet"];
const defaultEndpointResolver = (endpointParams: EndpointParams) => resolveEndpoint(ruleSet, { endpointParams });

if (testCases) {
for (const testCase of testCases) {
const { documentation, params = {}, expect: expectation, operationInputs } = testCase;
Expand All @@ -83,12 +80,12 @@ function runTestCases(
for (const operationInput of operationInputs) {
const { operationName, operationParams = {} } = operationInput;
const endpointParams = await resolveParams(operationParams, namespace[`${operationName}Command`], params);
const observed = defaultEndpointResolver(endpointParams as any);
const observed = defaultEndpointResolver(endpointParams as EndpointParams);
assertEndpointResolvedCorrectly(endpoint, observed);
}
} else {
const endpointParams = await resolveParams({}, {}, params);
const observed = defaultEndpointResolver(endpointParams as any);
const observed = defaultEndpointResolver(endpointParams as EndpointParams);
assertEndpointResolvedCorrectly(endpoint, observed);
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/endpoints-2.0/integration-test-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EndpointParameterInstructionsSupplier } from "@smithy/middleware-endpoint";
import { RuleSetObject } from "@smithy/types";

export interface EndpointTestCase {
documentation?: string;
Expand Down Expand Up @@ -38,6 +39,7 @@ export interface ServiceModel {
"aws.api#service": {
serviceId: string;
};
"smithy.rules#endpointRuleSet": RuleSetObject;
"smithy.rules#endpointTests"?: {
testCases: EndpointTestCase[];
};
Expand Down

0 comments on commit 6e5b22d

Please sign in to comment.