Skip to content

Commit

Permalink
test(endpoints): make namespace and model variables const
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Aug 12, 2024
1 parent 5d16bbe commit d24bff5
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions tests/endpoints-2.0/endpoints-integration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,35 @@
import { resolveParams } from "@smithy/middleware-endpoint";
import { EndpointV2 } from "@smithy/types";
import { resolveEndpoint, EndpointParams } from "@smithy/util-endpoints";
import { readdirSync } from "fs";
import { existsSync, readdirSync } from "fs";
import { join } from "path";

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

describe("client list", () => {
const root = join(__dirname, "..", "..");
const clientList = readdirSync(join(root, "clients"));
const clientPackageNameList = readdirSync(join(root, "clients"));

it("should be at least 300 clients", () => {
expect(clientList.length).toBeGreaterThan(300);
expect(clientPackageNameList.length).toBeGreaterThan(300);
});

describe.each(clientList)(`%s endpoint test cases`, (client) => {
const serviceName = client.slice(7);
describe.each(clientPackageNameList)(`%s endpoint test cases`, (clientPackageName) => {
const serviceName = clientPackageName.slice(7);

let namespace: any;
let model: any;
// since client package name list is populated from clients folder, we know it exists.
const namespace = require(`@aws-sdk/${clientPackageName}`);
const modelPath = join(root, "codegen", "sdk-codegen", "aws-models", serviceName + ".json");

// this may also work with dynamic async import() in a beforeAll() block,
// but needs more effort than using synchronous require().
try {
namespace = require(`@aws-sdk/client-${serviceName}`);
model = require(join(root, "codegen", "sdk-codegen", "aws-models", serviceName + ".json"));
} catch (e) {
namespace = null;
model = null;
if (e.code !== "MODULE_NOT_FOUND") {
console.error(e);
}
}

if (namespace && model) {
if (existsSync(modelPath)) {
const model = require(modelPath);
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);
break;
}
}
} else {
it.skip("unable to load endpoint resolver, namespace, or test cases", () => {});
}
});
});
Expand Down

0 comments on commit d24bff5

Please sign in to comment.