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

🪵 Logging file path and verify s3 test #461

Merged
merged 5 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default class S3ConnectorService implements StorageConnectorAPI {
let err = null;
for (let i = 0; i <= tries; i++) {
try {
console.log("🚀🚀 reading s3 object: ", path);
const stat = await this.client.statObject(this.minioConfiguration.bucket, path);
if (stat?.size > 0) {
break;
Expand Down
29 changes: 12 additions & 17 deletions tdrive/backend/node/test/e2e/files/files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import { afterAll, beforeAll, describe, expect, it } from "@jest/globals";
import { init, TestPlatform } from "../setup";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import fs from "fs";
import LocalConnectorService from "../../../src/core/platform/services/storage/connectors/local/service";
import S3ConnectorService from "../../../src/core/platform/services/storage/connectors/S3/s3-service";
import UserApi from "../common/user-api";


describe("The Files feature", () => {
const url = "/internal/services/files/v1";
let platform: TestPlatform;
Expand All @@ -17,14 +15,17 @@ describe("The Files feature", () => {
platform = await init({
services: ["webserver", "database", "storage", "files", "previews"],
});
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await platform.database.getConnector().init();
helpers = await UserApi.getInstance(platform)
helpers = await UserApi.getInstance(platform);
});

afterAll(async () => {
await platform?.tearDown();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
platform = null;

});

describe("On user send files", () => {
Expand All @@ -34,10 +35,9 @@ describe("The Files feature", () => {
//given file
const filesUpload = await helpers.uploadRandomFile();
expect(filesUpload.id).toBeTruthy();
//clean files directory
expect(platform.storage.getConnector()).toBeInstanceOf(LocalConnectorService)
const path = (<LocalConnectorService>platform.storage.getConnector()).configuration.path;
fs.readdirSync(path).forEach(f => fs.rmSync(`${path}/${f}`, {recursive: true, force: true}));
expect(platform.storage.getConnector()).toBeInstanceOf(S3ConnectorService);
const path = `tdrive/files/${platform.workspace.company_id}/${platform.currentUser.id}/${filesUpload.id}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this "tdrive" should be a part of the configuration, or maybe even make function getPath from files service public

await platform.storage.getConnector().remove(path);
//when try to download the file
const fileDownloadResponse = await platform.app.inject({
method: "GET",
Expand All @@ -46,15 +46,14 @@ describe("The Files feature", () => {
//then file should be not found with 404 error and "File not found message"
expect(fileDownloadResponse).toBeTruthy();
expect(fileDownloadResponse.statusCode).toBe(500);

}, 120000);

it("Download file should return 200 if file exists", async () => {
//given file
const filesUpload = await helpers.uploadRandomFile()
const filesUpload = await helpers.uploadRandomFile();
expect(filesUpload.id).toBeTruthy();
//clean files directory
expect(platform.storage.getConnector()).toBeInstanceOf(LocalConnectorService)
expect(platform.storage.getConnector()).toBeInstanceOf(S3ConnectorService);

//when try to download the file
const fileDownloadResponse = await platform.app.inject({
Expand All @@ -64,7 +63,6 @@ describe("The Files feature", () => {
//then file should be not found with 404 error and "File not found message"
expect(fileDownloadResponse).toBeTruthy();
expect(fileDownloadResponse.statusCode).toBe(200);

}, 120000);

it.skip("should save file and generate previews", async () => {
Expand All @@ -79,16 +77,13 @@ describe("The Files feature", () => {

for (const thumb of filesUpload.thumbnails) {
const thumbnails = await platform.app.inject({
headers: {"authorization": `Bearer ${await platform.auth.getJWTToken()}`},
headers: { authorization: `Bearer ${await platform.auth.getJWTToken()}` },
method: "GET",
url: `${url}/companies/${platform.workspace.company_id}/files/${filesUpload.id}/thumbnails/${thumb.index}`,
});
expect(thumbnails.statusCode).toBe(200);
}
}


}, 1200000);
});
});

Loading