From a360f3e15e483afec906da74e89db0a8a24535de Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 9 Aug 2024 20:46:59 +0000 Subject: [PATCH] test(endpoints): re-introduce namespace Test Suites: 1 failed, 1 total Tests: 22 failed, 124 skipped, 14526 passed, 14672 total Snapshots: 0 total Time: 61.488 s --- .../endpoints-integration.spec.ts | 27 ++++++++++++------- tests/endpoints-2.0/integration-test-types.ts | 13 +++++++++ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/tests/endpoints-2.0/endpoints-integration.spec.ts b/tests/endpoints-2.0/endpoints-integration.spec.ts index c711624fafaf..86c672e8dfda 100644 --- a/tests/endpoints-2.0/endpoints-integration.spec.ts +++ b/tests/endpoints-2.0/endpoints-integration.spec.ts @@ -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, "..", ".."); @@ -17,6 +17,7 @@ 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, @@ -24,28 +25,34 @@ describe("client list", () => { 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 ) { @@ -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); } @@ -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); diff --git a/tests/endpoints-2.0/integration-test-types.ts b/tests/endpoints-2.0/integration-test-types.ts index 9c9d33b75e29..de9b29d6b06e 100644 --- a/tests/endpoints-2.0/integration-test-types.ts +++ b/tests/endpoints-2.0/integration-test-types.ts @@ -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[]; + }; + }; +}