Skip to content

Commit 1e94526

Browse files
committed
fix(types): code reorganization in client-api-test
1 parent 95484b3 commit 1e94526

File tree

9 files changed

+159
-112
lines changed

9 files changed

+159
-112
lines changed

private/client-api-test/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aws-sdk/client-api-test",
3-
"description": "",
3+
"description": "Test suite for client interface stability",
44
"version": "3.0.0",
55
"scripts": {
66
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Pattern for testing the stability of a Client interface.
3+
*/
4+
export interface ClientInterfaceTest<Client> {
5+
/**
6+
* Assert that some resolved config fields can be set to undefined.
7+
*/
8+
optionalConfigFieldsCanBeVoided(): void;
9+
/**
10+
* Create a test that initializes a client
11+
* with the minimal number of user-supplied values. This is
12+
* usually 0.
13+
*
14+
* This method is also a compilation test.
15+
*/
16+
initializeWithMinimalConfiguration(): Client;
17+
/**
18+
* Create a test that initializes a client with all config fields supplied
19+
* by the user.
20+
*
21+
* This method is also a compilation test.
22+
*/
23+
initializeWithMaximalConfiguration(): Client;
24+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* The status of a config field after passing through constructor
3+
* resolvers.
4+
*/
5+
export type FIELD_INIT_TYPE = "resolvedByConfigResolver" | "resolvedOnlyIfProvided" | "neverResolved";
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { ClientS3InterfaceTest } from "./ClientS3InterfaceTest";
2+
import { RESOLVED_FIELDS } from "./RESOLVED_FIELDS";
3+
4+
const Subject = ClientS3InterfaceTest;
5+
6+
describe("Client config interface should be stable", () => {
7+
describe(ClientS3InterfaceTest.name, () => {
8+
describe("initialization with minimal configuration", () => {
9+
const client = new Subject().initializeWithMinimalConfiguration();
10+
for (const [configType, fields] of Object.entries(RESOLVED_FIELDS)) {
11+
for (const field of fields) {
12+
if (configType === "resolvedByConfigResolver") {
13+
it(`should resolve the field [${field}] after minimal client init`, () => {
14+
expect(client.config[field as keyof typeof client.config]).toBeDefined();
15+
});
16+
} else {
17+
it(`should not resolve the field [${field}] after minimal client init`, () => {
18+
expect(client.config[field as keyof typeof client.config]).not.toBeDefined();
19+
});
20+
}
21+
}
22+
}
23+
});
24+
describe("initialization with maximal configuration", () => {
25+
const client = new Subject().initializeWithMaximalConfiguration();
26+
for (const [configType, fields] of Object.entries(RESOLVED_FIELDS)) {
27+
for (const field of fields) {
28+
if (configType === "resolvedByConfigResolver" || configType === "resolvedOnlyIfProvided") {
29+
it(`should resolve the field [${field}] after maximally configured client init`, () => {
30+
expect(client.config[field as keyof typeof client.config]).toBeDefined();
31+
});
32+
} else {
33+
it(`should not resolve the field [${field}] after maximally configured client init`, () => {
34+
expect(client.config[field as keyof typeof client.config]).not.toBeDefined();
35+
});
36+
}
37+
}
38+
}
39+
});
40+
});
41+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { S3Client, S3ClientResolvedConfig } from "@aws-sdk/client-s3";
2+
3+
import { ClientInterfaceTest } from "../ClientInterfaceTest";
4+
import { initializeWithMaximalConfiguration } from "./impl/initializeWithMaximalConfiguration";
5+
import { initializeWithMinimalConfiguration } from "./impl/initializeWithMinimalConfiguration";
6+
7+
export class ClientS3InterfaceTest implements ClientInterfaceTest<S3Client> {
8+
optionalConfigFieldsCanBeVoided(): void {
9+
const s3 = new S3Client({});
10+
const resolvedConfig: S3ClientResolvedConfig = s3.config;
11+
/**
12+
* Endpoint is no longer guaranteed as of endpoints 2.0 (rulesets).
13+
* @see https://github.com/aws/aws-sdk-js-v3/issues/4122
14+
*/
15+
resolvedConfig.endpoint = void 0;
16+
resolvedConfig.isCustomEndpoint = void 0;
17+
resolvedConfig.customUserAgent = void 0;
18+
}
19+
initializeWithMinimalConfiguration(): S3Client {
20+
return initializeWithMinimalConfiguration();
21+
}
22+
initializeWithMaximalConfiguration(): S3Client {
23+
return initializeWithMaximalConfiguration();
24+
}
25+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { S3ClientResolvedConfig } from "@aws-sdk/client-s3";
2+
3+
import { FIELD_INIT_TYPE } from "../FIELD_INIT_TYPE";
4+
5+
export const RESOLVED_FIELDS: Record<FIELD_INIT_TYPE, (keyof S3ClientResolvedConfig)[]> = {
6+
resolvedByConfigResolver: [
7+
"requestHandler",
8+
"apiVersion",
9+
"sha256",
10+
"urlParser",
11+
"bodyLengthChecker",
12+
"streamCollector",
13+
"base64Decoder",
14+
"base64Encoder",
15+
"utf8Decoder",
16+
"utf8Encoder",
17+
"runtime",
18+
"disableHostPrefix",
19+
"maxAttempts",
20+
"retryMode",
21+
"logger",
22+
"useDualstackEndpoint",
23+
"useFipsEndpoint",
24+
"serviceId",
25+
"region",
26+
"credentialDefaultProvider",
27+
"signingEscapePath",
28+
"useArnRegion",
29+
"defaultUserAgentProvider",
30+
"streamHasher",
31+
"md5",
32+
"sha1",
33+
"getAwsChunkedEncodingStream",
34+
"eventStreamSerdeProvider",
35+
"defaultsMode",
36+
"sdkStreamMixin",
37+
"endpointProvider",
38+
"tls",
39+
"isCustomEndpoint",
40+
"retryStrategy",
41+
"credentials",
42+
"signer",
43+
"systemClockOffset",
44+
"forcePathStyle",
45+
"useAccelerateEndpoint",
46+
"disableMultiregionAccessPoints",
47+
"eventStreamMarshaller",
48+
"defaultSigningName",
49+
"useGlobalEndpoint",
50+
],
51+
resolvedOnlyIfProvided: ["customUserAgent", "endpoint"],
52+
neverResolved: [],
53+
};

private/client-api-test/src/client-s3-interface.ts renamed to private/client-api-test/src/client-interface-tests/client-s3/impl/initializeWithMaximalConfiguration.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { S3Client, S3ClientResolvedConfig } from "@aws-sdk/client-s3";
1+
import { S3Client } from "@aws-sdk/client-s3";
22
import { decorateDefaultCredentialProvider } from "@aws-sdk/client-sts";
33
import {
44
NODE_REGION_CONFIG_FILE_OPTIONS,
@@ -29,30 +29,6 @@ import { getAwsChunkedEncodingStream, sdkStreamMixin } from "@aws-sdk/util-strea
2929
import { defaultUserAgent } from "@aws-sdk/util-user-agent-node";
3030
import { fromUtf8, toUtf8 } from "@aws-sdk/util-utf8-node";
3131

32-
/**
33-
* This function compiling indicates the expected
34-
* optional fields can be reassigned to void.
35-
*/
36-
export const optionalConfigFieldsCanBeVoided = () => {
37-
const s3 = new S3Client({});
38-
const resolvedConfig: S3ClientResolvedConfig = s3.config;
39-
/**
40-
* Endpoint is no longer guaranteed as of endpoints 2.0 (rulesets).
41-
* @see https://github.com/aws/aws-sdk-js-v3/issues/4122
42-
*/
43-
resolvedConfig.endpoint = void 0;
44-
resolvedConfig.isCustomEndpoint = void 0;
45-
resolvedConfig.customUserAgent = void 0;
46-
};
47-
48-
/**
49-
* Successful compilation indicates the client can be initialized
50-
* with minimal configuration.
51-
*/
52-
export const initializeWithMinimalConfiguration = () => {
53-
return new S3Client({});
54-
};
55-
5632
/**
5733
* Successful compilation indicates the client can be initialized
5834
* with maximal configuration.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { S3Client } from "@aws-sdk/client-s3";
2+
3+
/**
4+
* Successful compilation indicates the client can be initialized
5+
* with minimal configuration.
6+
*/
7+
export const initializeWithMinimalConfiguration = () => {
8+
return new S3Client({});
9+
};

private/client-api-test/src/client-s3-interface.spec.ts

Lines changed: 0 additions & 86 deletions
This file was deleted.

0 commit comments

Comments
 (0)