Skip to content

Commit

Permalink
test(endpoints): re-introduce namespace
Browse files Browse the repository at this point in the history
Test Suites: 1 failed, 1 total
Tests:       22 failed, 124 skipped, 14526 passed, 14672 total
Snapshots:   0 total
Time:        61.488 s
  • Loading branch information
trivikr committed Aug 9, 2024
1 parent 4767f6c commit a360f3e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
27 changes: 17 additions & 10 deletions tests/endpoints-2.0/endpoints-integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EndpointParameters, EndpointV2 } from "@smithy/types";
import * as fs from "fs";
import * as path from "path";

import { EndpointExpectation, EndpointTestCase, ServiceNamespace } from "./integration-test-types";
import { EndpointExpectation, EndpointTestCase, ServiceModel, ServiceNamespace } from "./integration-test-types";

describe("client list", () => {
const root = path.join(__dirname, "..", "..");
Expand All @@ -17,35 +17,42 @@ describe("client list", () => {
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 && model) {
const [, service] = Object.entries(model.shapes).find(
([k, v]) => typeof v === "object" && v !== null && "type" in v && v.type === "service"
) as any;
runTestCases(service, defaultEndpointResolver, "");
if (defaultEndpointResolver && 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, "");
break;
}
}
} else {
it.skip("unable to load endpoint resolver, or test cases", () => {});
it.skip("unable to load endpoint resolver, namespace, or test cases", () => {});
}
});
});

function runTestCases(
service: ServiceNamespace,
service: ServiceModel,
namespace: ServiceNamespace,
defaultEndpointResolver: (endpointParams: EndpointParameters) => EndpointV2,
serviceId: string
) {
Expand Down Expand Up @@ -76,7 +83,7 @@ function runTestCases(
if (operationInputs) {
for (const operationInput of operationInputs) {
const { operationName, operationParams = {} } = operationInput;
const endpointParams = await resolveParams(operationParams, service[`${operationName}Command`], params);
const endpointParams = await resolveParams(operationParams, namespace[`${operationName}Command`], params);
const observed = defaultEndpointResolver(endpointParams as any);
assertEndpointResolvedCorrectly(endpoint, observed);
}
Expand All @@ -93,7 +100,7 @@ function runTestCases(
if (operationInputs) {
for (const operationInput of operationInputs) {
const { operationName, operationParams = {} } = operationInput;
const endpointParams = await resolveParams(operationParams, service[`${operationName}Command`], {
const endpointParams = await resolveParams(operationParams, namespace[`${operationName}Command`], {
...params,
endpointProvider: defaultEndpointResolver,
}).catch(pass);
Expand Down
13 changes: 13 additions & 0 deletions tests/endpoints-2.0/integration-test-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,16 @@ export type ErrorExpectation = {
export interface ServiceNamespace {
[Command: string]: EndpointParameterInstructionsSupplier;
}

export interface ServiceModel {
type: "service";
version: string;
traits: {
"aws.api#service": {
serviceId: string;
};
"smithy.rules#endpointTests": {
testCases: EndpointTestCase[];
};
};
}

0 comments on commit a360f3e

Please sign in to comment.