Skip to content

feat(config-resolver): add isCustomEndpoint resolved config #1551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions packages/config-resolver/src/EndpointsConfig.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,28 @@ describe("EndpointsConfig", () => {
it("returns output of urlParser if endpoint is of type string", async () => {
const endpoint = "endpoint";
urlParser.mockReturnValueOnce(mockEndpoint);
const endpointOutput = await resolveEndpointsConfig({ ...input, endpoint }).endpoint();
const { endpoint: endpointProvider, isCustomEndpoint } = resolveEndpointsConfig({ ...input, endpoint });
expect(isCustomEndpoint).toBe(true);
const endpointOutput = await endpointProvider();
expect(endpointOutput).toStrictEqual(mockEndpoint);
expect(urlParser).toHaveBeenCalledTimes(1);
expect(urlParser).toHaveBeenCalledWith(endpoint);
});

it("returns promisified endpoint if it's of type object", async () => {
const endpoint = mockEndpoint;
const endpointOutput = await resolveEndpointsConfig({ ...input, endpoint }).endpoint();
const { endpoint: endpointProvider, isCustomEndpoint } = resolveEndpointsConfig({ ...input, endpoint });
expect(isCustomEndpoint).toBe(true);
const endpointOutput = await endpointProvider();
expect(endpointOutput).toStrictEqual(endpoint);
expect(urlParser).not.toHaveBeenCalled();
});

it("returns endpoint if it's already Provider<Endpoint>", async () => {
const endpoint = () => Promise.resolve(mockEndpoint);
const endpointOutput = await resolveEndpointsConfig({ ...input, endpoint }).endpoint();
const { endpoint: endpointProvider, isCustomEndpoint } = resolveEndpointsConfig({ ...input, endpoint });
expect(isCustomEndpoint).toBe(true);
const endpointOutput = await endpointProvider();
expect(endpointOutput).toStrictEqual(mockEndpoint);
expect(urlParser).not.toHaveBeenCalled();
});
Expand All @@ -58,6 +64,11 @@ describe("EndpointsConfig", () => {
const mockHostname = "mockHostname";
const mockEndpoint: Endpoint = { protocol: "protocol", hostname: "hostname", path: "path" };

it("isCustomEndpoint should be false", () => {
const { isCustomEndpoint } = resolveEndpointsConfig({ ...input });
expect(isCustomEndpoint).toBe(false);
});

describe("returns endpoint", () => {
beforeEach(() => {
region.mockResolvedValueOnce(mockRegion);
Expand Down
2 changes: 2 additions & 0 deletions packages/config-resolver/src/EndpointsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface PreviouslyResolved {

export interface EndpointsResolvedConfig extends Required<EndpointsInputConfig> {
endpoint: Provider<Endpoint>;
isCustomEndpoint: boolean;
}

export const resolveEndpointsConfig = <T>(
Expand All @@ -28,6 +29,7 @@ export const resolveEndpointsConfig = <T>(
...input,
tls: input.tls ?? true,
endpoint: input.endpoint ? normalizeEndpoint(input) : () => getEndPointFromRegion(input),
isCustomEndpoint: input.endpoint ? true : false,
});

const normalizeEndpoint = (input: EndpointsInputConfig & PreviouslyResolved): Provider<Endpoint> => {
Expand Down