Skip to content

Commit a37bd63

Browse files
authored
test(aws-client-api-test): add new endpoint variation tests (#7192)
1 parent d65a730 commit a37bd63

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import { EC2ProtocolClient } from "@aws-sdk/aws-protocoltests-ec2";
2+
import { S3Client } from "@aws-sdk/client-s3";
3+
import { WeatherClient } from "@aws-sdk/weather";
4+
import { describe, expect, test as it } from "vitest";
5+
6+
describe("variations in the config endpoint property", () => {
7+
describe("for an official AWS SDK client", () => {
8+
it("endpoint is not required", async () => {
9+
const client = new S3Client({});
10+
expect(client.config.endpoint).toBeUndefined();
11+
expect(await client.config.endpoint?.()).toBeUndefined();
12+
});
13+
14+
it("endpoint can be set, but must be queried with an undef-check", async () => {
15+
const client = new S3Client({
16+
endpoint: "https://localhost",
17+
forcePathStyle: true,
18+
});
19+
expect(await client.config.endpoint?.()).toEqual({
20+
hostname: "localhost",
21+
path: "/",
22+
port: undefined,
23+
protocol: "https:",
24+
query: undefined,
25+
});
26+
});
27+
});
28+
29+
describe("for a Smithy client SDK outside the context of AWS", () => {
30+
it("requires an endpoint if using the default endpointRuleSet", async () => {
31+
const client = new WeatherClient({
32+
endpoint: "https://localhost",
33+
});
34+
});
35+
36+
it("config.endpoint may be queried without undef-check since it was required on input", async () => {
37+
const client = new WeatherClient({
38+
endpoint: "https://localhost",
39+
});
40+
expect(await client.config.endpoint()).toEqual({
41+
hostname: "localhost",
42+
path: "/",
43+
port: undefined,
44+
protocol: "https:",
45+
query: undefined,
46+
});
47+
});
48+
});
49+
50+
describe("for an internal generated client that uses default AWS regional endpoints", () => {
51+
// EC2ProtocolClient is a protocol test client that has the aws.api#Service trait,
52+
// and here it represents generated clients outside the AWS SDK but still an "AWS Service" as far as the
53+
// code generator can tell.
54+
55+
it("endpoint is not required", async () => {
56+
const client = new EC2ProtocolClient({});
57+
expect(client.config.endpoint).toBeInstanceOf(Function);
58+
});
59+
60+
it("endpoint may be set", async () => {
61+
const client = new EC2ProtocolClient({
62+
endpoint: "https://localhost",
63+
});
64+
expect(await client.config.endpoint()).toEqual({
65+
hostname: "localhost",
66+
path: "/",
67+
port: undefined,
68+
protocol: "https:",
69+
query: undefined,
70+
});
71+
});
72+
73+
it("config.endpoint may be queried without undef-check", async () => {
74+
const client = new EC2ProtocolClient({});
75+
expect(await client.config.endpoint()).toEqual({
76+
hostname: "awsec2.us-west-2.amazonaws.com",
77+
path: "/",
78+
port: undefined,
79+
protocol: "https:",
80+
query: undefined,
81+
});
82+
});
83+
84+
it("fips", async () => {
85+
const client = new EC2ProtocolClient({
86+
useFipsEndpoint: true,
87+
});
88+
expect(await client.config.endpoint()).toEqual({
89+
hostname: "awsec2-fips.us-west-2.amazonaws.com",
90+
path: "/",
91+
port: undefined,
92+
protocol: "https:",
93+
query: undefined,
94+
});
95+
});
96+
97+
it("dualstack", async () => {
98+
const client = new EC2ProtocolClient({ useDualstackEndpoint: true });
99+
expect(await client.config.endpoint()).toEqual({
100+
hostname: "awsec2.us-west-2.api.aws",
101+
path: "/",
102+
port: undefined,
103+
protocol: "https:",
104+
query: undefined,
105+
});
106+
});
107+
});
108+
});

0 commit comments

Comments
 (0)