🌟Add an option to not delete files from S3 storage (#321)

This commit is contained in:
Anton Shepilov
2024-01-14 02:40:02 +03:00
committed by GitHub
parent 70c033aabe
commit 873ef8c08c
5 changed files with 65 additions and 5 deletions
@@ -0,0 +1,51 @@
import S3ConnectorService, {
S3Configuration
} from "../../../../../../../src/core/platform/services/storage/connectors/S3/s3-service";
import { jest } from "@jest/globals";
describe("The S3ConnectorService", () => {
beforeEach(async () => {
});
afterEach(() => {
jest.clearAllMocks();
});
test("remove shouldnt remove file if the option is disabled", async () => {
//given
const subj: S3ConnectorService = new S3ConnectorService({
disableRemove: true,
endPoint: "play.min.io",
port: 9000
} as S3Configuration);
const removeSpy = jest.spyOn(subj.client, "removeObject");
//when
const result = await subj.remove("path");
//then
expect(result).toBeTruthy();
expect(removeSpy).not.toHaveBeenCalled();
});
test("remove should call remove if the option is not disabled", async () => {
//given
const subj: S3ConnectorService = new S3ConnectorService({
disableRemove: false,
endPoint: "play.min.io",
port: 9000,
bucket: "testbucket"
} as S3Configuration);
const removeSpy = jest.spyOn(subj.client, "removeObject");
removeSpy.mockReturnThis();
//when
const result = await subj.remove("path");
//then
expect(removeSpy).toHaveBeenCalled();
expect(removeSpy).toBeCalledWith("testbucket", "path");
});
});