Skip to content
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

Unable to mock a file stream in S3 Client Mock #247

Open
1 task done
dreessan opened this issue Dec 3, 2024 · 0 comments
Open
1 task done

Unable to mock a file stream in S3 Client Mock #247

dreessan opened this issue Dec 3, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@dreessan
Copy link

dreessan commented Dec 3, 2024

Checklist

  • I have read Caveats documentation and didn't find a solution for this problem there.

Bug description

Attached sample does not work

  1. I have also tried several permutations on Readable and fs.ReadStream
  2. Q is unable to help. Q seems to think that my code ought to work.

Here is the error it produces:

Type 'SdkStream<ReadableStream | Blob> | SdkStream<Readable>' is not assignable to type 'StreamingBlobPayloadOutputTypes | undefined'.
  Type 'ReadableStream & SdkStreamMixin' is not assignable to type 'StreamingBlobPayloadOutputTypes | undefined'.
    Type 'ReadableStream & SdkStreamMixin' is not assignable to type 'Readable & SdkStreamMixin'.
      Type 'ReadableStream & SdkStreamMixin' is missing the following properties from type 'Readable': readable, readableEncoding, readableEnded, readableFlowing, and 33 more.ts(2322)
(property) Body?: StreamingBlobPayloadOutputTypes | undefined

Reproduction

import { mockClient } from "aws-sdk-client-mock";
import { GetObjectCommand, S3Client } from "@aws-sdk/client-s3";
import { sdkStreamMixin } from "@smithy/util-stream";
import fs from "node:fs";
import { Readable } from "node:stream";

const s3ClientMock = mockClient(S3Client);

const trainingData = fs.createReadStream(
  __dirname + "path/to/file.csv",
  "utf8"
);
describe("oversampleTraining", () => {
  beforeEach(() => {
    s3ClientMock.reset();
  });

  it("oversamples the training data", () => {
    s3ClientMock.on(GetObjectCommand).resolves({
      Body: sdkStreamMixin(Readable.from(trainingData)),
    });
  });
});

Environment

  • Node version: using bb app -v :: 8.19.4
  • Testing lib and version: "jest": "^29.4.3",
  • Typescript version: "~4.7.4"
  • AWS SDK v3 Client mock version: "^3.1.0"
  • AWS JS SDK libs and versions:
    • "@aws-sdk/client-s3": "^3.515.0",
@dreessan dreessan added the bug Something isn't working label Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant