Skip to content

Commit 3daceed

Browse files
gosarJordonPhillips
authored andcommitted
test(config-resolver): add test for CustomEndpointsConfig (#2305)
1 parent 422db80 commit 3daceed

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { Endpoint } from "@aws-sdk/types";
2+
3+
import { resolveCustomEndpointsConfig } from "./CustomEndpointsConfig";
4+
5+
describe("CustomEndpointsConfig", () => {
6+
const urlParser = jest.fn();
7+
8+
const input = { urlParser };
9+
10+
afterEach(() => {
11+
jest.clearAllMocks();
12+
});
13+
14+
describe("endpoint", () => {
15+
const mockEndpoint: Endpoint = { protocol: "protocol", hostname: "hostname", path: "path" };
16+
17+
it("returns output of urlParser if endpoint is of type string", async () => {
18+
const endpoint = "endpoint";
19+
urlParser.mockReturnValueOnce(mockEndpoint);
20+
const { endpoint: endpointProvider, isCustomEndpoint } = resolveCustomEndpointsConfig({ ...input, endpoint });
21+
expect(isCustomEndpoint).toBe(true);
22+
const endpointOutput = await endpointProvider();
23+
expect(endpointOutput).toStrictEqual(mockEndpoint);
24+
expect(urlParser).toHaveBeenCalledTimes(1);
25+
expect(urlParser).toHaveBeenCalledWith(endpoint);
26+
});
27+
28+
it("returns promisified endpoint if it's of type object", async () => {
29+
const endpoint = mockEndpoint;
30+
const { endpoint: endpointProvider, isCustomEndpoint } = resolveCustomEndpointsConfig({ ...input, endpoint });
31+
expect(isCustomEndpoint).toBe(true);
32+
const endpointOutput = await endpointProvider();
33+
expect(endpointOutput).toStrictEqual(endpoint);
34+
expect(urlParser).not.toHaveBeenCalled();
35+
});
36+
37+
it("returns endpoint if it's already Provider<Endpoint>", async () => {
38+
const endpoint = () => Promise.resolve(mockEndpoint);
39+
const { endpoint: endpointProvider, isCustomEndpoint } = resolveCustomEndpointsConfig({ ...input, endpoint });
40+
expect(isCustomEndpoint).toBe(true);
41+
const endpointOutput = await endpointProvider();
42+
expect(endpointOutput).toStrictEqual(mockEndpoint);
43+
expect(urlParser).not.toHaveBeenCalled();
44+
});
45+
});
46+
47+
describe("tls", () => {
48+
const endpoint = "endpoint";
49+
50+
beforeEach(() => {
51+
urlParser.mockReturnValueOnce({ protocol: "protocol", hostname: "hostname", path: "path" });
52+
});
53+
54+
[true, false].forEach((tls) => {
55+
it(`returns input.tls when it's ${tls}`, () => {
56+
expect(resolveCustomEndpointsConfig({ ...input, endpoint, tls }).tls).toStrictEqual(tls);
57+
});
58+
});
59+
60+
it("returns true is input.tls is undefined", () => {
61+
expect(resolveCustomEndpointsConfig({ ...input, endpoint }).tls).toStrictEqual(true);
62+
});
63+
});
64+
});

packages/config-resolver/src/CustomEndpointsConfig.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// TODO: Create a .spec.ts for this
21
import { Endpoint, Provider, UrlParser } from "@aws-sdk/types";
32

43
export interface CustomEndpointsInputConfig {
@@ -19,7 +18,7 @@ interface PreviouslyResolved {
1918

2019
export interface CustomEndpointsResolvedConfig extends Required<CustomEndpointsInputConfig> {
2120
endpoint: Provider<Endpoint>;
22-
isCustomEndpoint: true; // TODO: Can this be removed or some other logic depends on this?
21+
isCustomEndpoint: true;
2322
}
2423

2524
export const resolveCustomEndpointsConfig = <T>(
@@ -31,7 +30,6 @@ export const resolveCustomEndpointsConfig = <T>(
3130
isCustomEndpoint: true,
3231
});
3332

34-
// TODO: can this be shared with EndpointsConfig.ts
3533
const normalizeEndpoint = (input: CustomEndpointsInputConfig & PreviouslyResolved): Provider<Endpoint> => {
3634
const { endpoint, urlParser } = input;
3735
if (typeof endpoint === "string") {

0 commit comments

Comments
 (0)