-
Notifications
You must be signed in to change notification settings - Fork 584
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(types): add client config interface test with s3 example (#4156)
* fix(types): add client config interface test with s3 example * fix(types): decouple V1orV2Endpoint type from EndpointBearer type * fix(lib-storage): type fix, allow undefined endpoint * fix(types): code reorganization in client-api-test
- Loading branch information
Showing
19 changed files
with
384 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const base = require("../../jest.config.base.js"); | ||
|
||
module.exports = { | ||
...base, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{ | ||
"name": "@aws-sdk/client-api-test", | ||
"description": "Test suite for client interface stability", | ||
"version": "3.0.0", | ||
"scripts": { | ||
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'", | ||
"build:cjs": "tsc -p tsconfig.cjs.json", | ||
"build:docs": "typedoc", | ||
"build:es": "tsc -p tsconfig.es.json", | ||
"build:include:deps": "lerna run --scope $npm_package_name --include-dependencies build", | ||
"build:types": "tsc -p tsconfig.types.json", | ||
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4", | ||
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo", | ||
"test": "jest --coverage --passWithNoTests" | ||
}, | ||
"main": "./dist-cjs/index.js", | ||
"types": "./dist-types/index.d.ts", | ||
"module": "./dist-es/index.js", | ||
"sideEffects": false, | ||
"dependencies": { | ||
"@aws-sdk/client-s3": "*", | ||
"tslib": "^2.3.1" | ||
}, | ||
"devDependencies": { | ||
"@tsconfig/node14": "1.0.3", | ||
"@types/node": "^12.7.5", | ||
"concurrently": "7.0.0", | ||
"downlevel-dts": "0.10.1", | ||
"typedoc": "0.19.2", | ||
"typescript": "~4.6.2" | ||
}, | ||
"overrides": { | ||
"typedoc": { | ||
"typescript": "~4.6.2" | ||
} | ||
}, | ||
"engines": { | ||
"node": ">=14.0.0" | ||
}, | ||
"typesVersions": { | ||
"<4.0": { | ||
"dist-types/*": [ | ||
"dist-types/ts3.4/*" | ||
] | ||
} | ||
}, | ||
"files": [ | ||
"dist-*" | ||
], | ||
"author": { | ||
"name": "AWS SDK for JavaScript Team", | ||
"url": "https://aws.amazon.com/javascript/" | ||
}, | ||
"license": "Apache-2.0", | ||
"private": true, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/aws/aws-sdk-js-v3.git", | ||
"directory": "private/client-api-test" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# @aws-sdk/client-api-test | ||
|
||
This is not a runtime or published package. | ||
|
||
This is a test spec. | ||
|
||
The purpose of this package is to stabilize the `@aws-sdk/client-*` interface against changes. | ||
|
||
If tests in this package fail, the author should either fix their changes such that the API contract | ||
is maintained, or appropriately announce and safely deprecate the interfaces affected by incoming changes. |
24 changes: 24 additions & 0 deletions
24
private/client-api-test/src/client-interface-tests/ClientInterfaceTest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Pattern for testing the stability of a Client interface. | ||
*/ | ||
export interface ClientInterfaceTest<Client> { | ||
/** | ||
* Assert that some resolved config fields can be set to undefined. | ||
*/ | ||
optionalConfigFieldsCanBeVoided(): void; | ||
/** | ||
* Create a test that initializes a client | ||
* with the minimal number of user-supplied values. This is | ||
* usually 0. | ||
* | ||
* This method is also a compilation test. | ||
*/ | ||
initializeWithMinimalConfiguration(): Client; | ||
/** | ||
* Create a test that initializes a client with all config fields supplied | ||
* by the user. | ||
* | ||
* This method is also a compilation test. | ||
*/ | ||
initializeWithMaximalConfiguration(): Client; | ||
} |
5 changes: 5 additions & 0 deletions
5
private/client-api-test/src/client-interface-tests/FIELD_INIT_TYPE.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** | ||
* The status of a config field after passing through constructor | ||
* resolvers. | ||
*/ | ||
export type FIELD_INIT_TYPE = "resolvedByConfigResolver" | "resolvedOnlyIfProvided" | "neverResolved"; |
41 changes: 41 additions & 0 deletions
41
private/client-api-test/src/client-interface-tests/client-s3/ClientS3InterfaceTest.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { ClientS3InterfaceTest } from "./ClientS3InterfaceTest"; | ||
import { RESOLVED_FIELDS } from "./RESOLVED_FIELDS"; | ||
|
||
const Subject = ClientS3InterfaceTest; | ||
|
||
describe("Client config interface should be stable", () => { | ||
describe(ClientS3InterfaceTest.name, () => { | ||
describe("initialization with minimal configuration", () => { | ||
const client = new Subject().initializeWithMinimalConfiguration(); | ||
for (const [configType, fields] of Object.entries(RESOLVED_FIELDS)) { | ||
for (const field of fields) { | ||
if (configType === "resolvedByConfigResolver") { | ||
it(`should resolve the field [${field}] after minimal client init`, () => { | ||
expect(client.config[field as keyof typeof client.config]).toBeDefined(); | ||
}); | ||
} else { | ||
it(`should not resolve the field [${field}] after minimal client init`, () => { | ||
expect(client.config[field as keyof typeof client.config]).not.toBeDefined(); | ||
}); | ||
} | ||
} | ||
} | ||
}); | ||
describe("initialization with maximal configuration", () => { | ||
const client = new Subject().initializeWithMaximalConfiguration(); | ||
for (const [configType, fields] of Object.entries(RESOLVED_FIELDS)) { | ||
for (const field of fields) { | ||
if (configType === "resolvedByConfigResolver" || configType === "resolvedOnlyIfProvided") { | ||
it(`should resolve the field [${field}] after maximally configured client init`, () => { | ||
expect(client.config[field as keyof typeof client.config]).toBeDefined(); | ||
}); | ||
} else { | ||
it(`should not resolve the field [${field}] after maximally configured client init`, () => { | ||
expect(client.config[field as keyof typeof client.config]).not.toBeDefined(); | ||
}); | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
private/client-api-test/src/client-interface-tests/client-s3/ClientS3InterfaceTest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { S3Client, S3ClientResolvedConfig } from "@aws-sdk/client-s3"; | ||
|
||
import { ClientInterfaceTest } from "../ClientInterfaceTest"; | ||
import { initializeWithMaximalConfiguration } from "./impl/initializeWithMaximalConfiguration"; | ||
import { initializeWithMinimalConfiguration } from "./impl/initializeWithMinimalConfiguration"; | ||
|
||
export class ClientS3InterfaceTest implements ClientInterfaceTest<S3Client> { | ||
optionalConfigFieldsCanBeVoided(): void { | ||
const s3 = new S3Client({}); | ||
const resolvedConfig: S3ClientResolvedConfig = s3.config; | ||
/** | ||
* Endpoint is no longer guaranteed as of endpoints 2.0 (rulesets). | ||
* @see https://github.com/aws/aws-sdk-js-v3/issues/4122 | ||
*/ | ||
resolvedConfig.endpoint = void 0; | ||
resolvedConfig.isCustomEndpoint = void 0; | ||
resolvedConfig.customUserAgent = void 0; | ||
} | ||
initializeWithMinimalConfiguration(): S3Client { | ||
return initializeWithMinimalConfiguration(); | ||
} | ||
initializeWithMaximalConfiguration(): S3Client { | ||
return initializeWithMaximalConfiguration(); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
private/client-api-test/src/client-interface-tests/client-s3/RESOLVED_FIELDS.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { S3ClientResolvedConfig } from "@aws-sdk/client-s3"; | ||
|
||
import { FIELD_INIT_TYPE } from "../FIELD_INIT_TYPE"; | ||
|
||
export const RESOLVED_FIELDS: Record<FIELD_INIT_TYPE, (keyof S3ClientResolvedConfig)[]> = { | ||
resolvedByConfigResolver: [ | ||
"requestHandler", | ||
"apiVersion", | ||
"sha256", | ||
"urlParser", | ||
"bodyLengthChecker", | ||
"streamCollector", | ||
"base64Decoder", | ||
"base64Encoder", | ||
"utf8Decoder", | ||
"utf8Encoder", | ||
"runtime", | ||
"disableHostPrefix", | ||
"maxAttempts", | ||
"retryMode", | ||
"logger", | ||
"useDualstackEndpoint", | ||
"useFipsEndpoint", | ||
"serviceId", | ||
"region", | ||
"credentialDefaultProvider", | ||
"signingEscapePath", | ||
"useArnRegion", | ||
"defaultUserAgentProvider", | ||
"streamHasher", | ||
"md5", | ||
"sha1", | ||
"getAwsChunkedEncodingStream", | ||
"eventStreamSerdeProvider", | ||
"defaultsMode", | ||
"sdkStreamMixin", | ||
"endpointProvider", | ||
"tls", | ||
"isCustomEndpoint", | ||
"retryStrategy", | ||
"credentials", | ||
"signer", | ||
"systemClockOffset", | ||
"forcePathStyle", | ||
"useAccelerateEndpoint", | ||
"disableMultiregionAccessPoints", | ||
"eventStreamMarshaller", | ||
"defaultSigningName", | ||
"useGlobalEndpoint", | ||
], | ||
resolvedOnlyIfProvided: ["customUserAgent", "endpoint"], | ||
neverResolved: [], | ||
}; |
Oops, something went wrong.