-
Notifications
You must be signed in to change notification settings - Fork 634
test(core): new integration tests #7229
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
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
141 changes: 141 additions & 0 deletions
141
packages/core/src/submodules/account-id-endpoint/account-id-endpoint.integ.spec.ts
This file contains hidden or 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,141 @@ | ||
import { requireRequestsFrom } from "@aws-sdk/aws-util-test/src"; | ||
import { DynamoDB } from "@aws-sdk/client-dynamodb"; | ||
import { AwsCredentialIdentity } from "@smithy/types"; | ||
import { afterEach, beforeEach, describe, expect, test as it } from "vitest"; | ||
|
||
describe("account id endpoint", () => { | ||
const credentialsWithAccountId: AwsCredentialIdentity = { | ||
accessKeyId: "INTEG_TEST", | ||
secretAccessKey: "INTEG_TEST", | ||
accountId: "123456789012", | ||
}; | ||
const credentials = { | ||
accessKeyId: "INTEG_TEST", | ||
secretAccessKey: "INTEG_TEST", | ||
}; | ||
|
||
beforeEach(async () => { | ||
delete process.env.AWS_ACCOUNT_ID_ENDPOINT_MODE; | ||
}); | ||
afterEach(async () => { | ||
kuhe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
delete process.env.AWS_ACCOUNT_ID_ENDPOINT_MODE; | ||
}); | ||
|
||
describe("when credentials have account id", () => { | ||
it("should default to resolving endpoint with account id when it is available in the client credentials", async () => { | ||
const ddb = new DynamoDB({ | ||
region: "us-west-2", | ||
credentials: credentialsWithAccountId, | ||
}); | ||
requireRequestsFrom(ddb).toMatch({ | ||
hostname: /123456789012.ddb.us-west-2.amazonaws.com/, | ||
}); | ||
await ddb.listTables(); | ||
}); | ||
|
||
describe("config values", () => { | ||
it("disabled", async () => { | ||
const ddb = new DynamoDB({ | ||
region: "us-west-2", | ||
credentials: credentialsWithAccountId, | ||
accountIdEndpointMode: "disabled", | ||
}); | ||
requireRequestsFrom(ddb).toMatch({ | ||
hostname: /dynamodb.us-west-2.amazonaws.com/, | ||
}); | ||
await ddb.listTables(); | ||
}); | ||
it("preferred", async () => { | ||
const ddb = new DynamoDB({ | ||
region: "us-west-2", | ||
credentials: credentialsWithAccountId, | ||
accountIdEndpointMode: "preferred", | ||
}); | ||
requireRequestsFrom(ddb).toMatch({ | ||
hostname: /123456789012.ddb.us-west-2.amazonaws.com/, | ||
}); | ||
await ddb.listTables(); | ||
}); | ||
it("required", async () => { | ||
const ddb = new DynamoDB({ | ||
region: "us-west-2", | ||
credentials: credentialsWithAccountId, | ||
accountIdEndpointMode: "required", | ||
}); | ||
requireRequestsFrom(ddb).toMatch({ | ||
hostname: /123456789012.ddb.us-west-2.amazonaws.com/, | ||
}); | ||
await ddb.listTables(); | ||
}); | ||
}); | ||
kuhe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
describe("ENV values", () => { | ||
it("disabled", async () => { | ||
process.env.AWS_ACCOUNT_ID_ENDPOINT_MODE = "disabled"; | ||
const ddb = new DynamoDB({ | ||
region: "us-west-2", | ||
credentials: credentialsWithAccountId, | ||
}); | ||
requireRequestsFrom(ddb).toMatch({ | ||
hostname: /dynamodb.us-west-2.amazonaws.com/, | ||
}); | ||
await ddb.listTables(); | ||
}); | ||
it("preferred", async () => { | ||
process.env.AWS_ACCOUNT_ID_ENDPOINT_MODE = "preferred"; | ||
const ddb = new DynamoDB({ | ||
region: "us-west-2", | ||
credentials: credentialsWithAccountId, | ||
}); | ||
requireRequestsFrom(ddb).toMatch({ | ||
hostname: /123456789012.ddb.us-west-2.amazonaws.com/, | ||
}); | ||
await ddb.listTables(); | ||
}); | ||
it("required", async () => { | ||
process.env.AWS_ACCOUNT_ID_ENDPOINT_MODE = "required"; | ||
const ddb = new DynamoDB({ | ||
region: "us-west-2", | ||
credentials: credentialsWithAccountId, | ||
}); | ||
requireRequestsFrom(ddb).toMatch({ | ||
hostname: /123456789012.ddb.us-west-2.amazonaws.com/, | ||
}); | ||
await ddb.listTables(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("when credentials do not have account id", () => { | ||
it("it follows that the hostname will not have it either", async () => { | ||
const ddb = new DynamoDB({ | ||
region: "us-west-2", | ||
credentials: credentials, | ||
}); | ||
requireRequestsFrom(ddb).toMatch({ | ||
hostname: /dynamodb.us-west-2.amazonaws.com/, | ||
}); | ||
await ddb.listTables(); | ||
}); | ||
|
||
it("will fail if required by ENV", async () => { | ||
process.env.AWS_ACCOUNT_ID_ENDPOINT_MODE = "required"; | ||
const ddb = new DynamoDB({ | ||
region: "us-west-2", | ||
credentials: credentials, | ||
}); | ||
const error = await ddb.listTables().catch((e) => e); | ||
expect(error.name).toEqual("EndpointError"); | ||
}); | ||
|
||
it("will fail if required by config", async () => { | ||
const ddb = new DynamoDB({ | ||
region: "us-west-2", | ||
credentials: credentials, | ||
accountIdEndpointMode: "required", | ||
}); | ||
const error = await ddb.listTables().catch((e) => e); | ||
expect(error.name).toEqual("EndpointError"); | ||
}); | ||
}); | ||
}); |
92 changes: 92 additions & 0 deletions
92
packages/core/src/submodules/client/pagination.integ.spec.ts
This file contains hidden or 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,92 @@ | ||
import { requireRequestsFrom } from "@aws-sdk/aws-util-test/src"; | ||
import { DynamoDB, paginateScan, ScanCommandInput } from "@aws-sdk/client-dynamodb"; | ||
import { HttpResponse } from "@smithy/protocol-http"; | ||
import { describe, expect, test as it } from "vitest"; | ||
|
||
describe("pagination", () => { | ||
it("makes sequential requests using a pagination token", async () => { | ||
const ddb = new DynamoDB({ | ||
credentials: { | ||
accessKeyId: "INTEG_TEST", | ||
secretAccessKey: "INTEG_TEST", | ||
}, | ||
region: "us-west-2", | ||
}); | ||
|
||
requireRequestsFrom(ddb) | ||
.toMatch( | ||
{ | ||
hostname: /dynamodb/, | ||
body(b) { | ||
expect(b).toContain("TableName"); | ||
expect(b).not.toContain("ExclusiveStartKey"); | ||
}, | ||
}, | ||
{ | ||
hostname: /dynamodb/, | ||
body: /ExclusiveStartKey/, | ||
} | ||
) | ||
.respondWith( | ||
new HttpResponse({ | ||
statusCode: 200, | ||
headers: {}, | ||
body: Buffer.from( | ||
JSON.stringify({ | ||
Items: [ | ||
{ | ||
id: { S: "1" }, | ||
name: { S: "Item 1" }, | ||
}, | ||
{ | ||
id: { S: "2" }, | ||
name: { S: "Item 2" }, | ||
}, | ||
], | ||
Count: 2, | ||
ScannedCount: 2, | ||
LastEvaluatedKey: { | ||
id: { S: "2" }, | ||
}, | ||
}) | ||
), | ||
}), | ||
new HttpResponse({ | ||
statusCode: 200, | ||
headers: {}, | ||
body: Buffer.from( | ||
JSON.stringify({ | ||
Items: [ | ||
{ | ||
id: { S: "3" }, | ||
name: { S: "Item 3" }, | ||
}, | ||
{ | ||
id: { S: "4" }, | ||
name: { S: "Item 4" }, | ||
}, | ||
], | ||
Count: 2, | ||
ScannedCount: 2, | ||
}) | ||
), | ||
}) | ||
); | ||
|
||
const requestParams: ScanCommandInput = { | ||
TableName: "test", | ||
}; | ||
|
||
let pages = 0; | ||
for await (const page of paginateScan({ client: ddb }, requestParams)) { | ||
void page; | ||
pages += 1; | ||
} | ||
|
||
expect(pages).toEqual(2); | ||
expect(requestParams.ExclusiveStartKey).toEqual({ | ||
id: { S: "2" }, | ||
}); | ||
expect.assertions(7); | ||
}); | ||
}); |
42 changes: 42 additions & 0 deletions
42
packages/core/src/submodules/protocols/lazy-json-string.integ.spec.ts
This file contains hidden or 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,42 @@ | ||
import { requireRequestsFrom } from "@aws-sdk/aws-util-test/src"; | ||
import { Schemas } from "@aws-sdk/client-schemas"; | ||
import { LazyJsonString } from "@smithy/core/serde"; | ||
import { describe, expect, test as it } from "vitest"; | ||
|
||
describe(LazyJsonString.name, () => { | ||
it("should auto-serialize fields to JSON", async () => { | ||
const client = new Schemas({ | ||
region: "us-west-2", | ||
}); | ||
|
||
let request = 0; | ||
|
||
requireRequestsFrom(client).toMatch({ | ||
body(b) { | ||
if (request === 0) { | ||
expect(b).toEqual(`{"Policy":"this is a plain string"}`); | ||
request += 1; | ||
} else if (request === 1) { | ||
expect(b).toEqual(`{"Policy":"{\\"this\\":\\"is a json string\\"}"}`); | ||
request += 1; | ||
} else if (request === 2) { | ||
expect(b).toEqual(`{"Policy":"{\\"message\\":\\"this is a js object\\"}"}`); | ||
request += 1; | ||
} | ||
}, | ||
}); | ||
|
||
await client.putResourcePolicy({ | ||
Policy: "this is a plain string", | ||
}); | ||
await client.putResourcePolicy({ | ||
Policy: `{"this":"is a json string"}`, | ||
}); | ||
await client.putResourcePolicy({ | ||
Policy: { | ||
message: "this is a js object", | ||
}, | ||
}); | ||
expect.assertions(3); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.