import registerStoragesTests from "@staticdeploy/storages-test-suite" ; import { S3 } from "aws-sdk" ; import { Knex } from "knex" ; import PgS3Storages from "../src" ; import tables from "../src/common/tables" ; execStorageTests ( false ) ; execStorageTests ( true ) ; function execStorageTests ( enableGCSCompatibility ) { const pgS3Storages = new PgS3Storages ( { postgresUrl : "postgres://postgres:password@localhost/postgres" , s3Config : { bucket : "test" , endpoint : "http://localhost:9000" , accessKeyId : "accessKeyId" , secretAccessKey : "secretAccessKey" , enableGCSCompatibility : enableGCSCompatibility , } , } ) ; registerStoragesTests ( { storagesName : "pg-s3-storages" , storages : pgS3Storages . getStorages ( ) , setupStorages : ( ) => pgS3Storages . setup ( ) , eraseStorages : async ( ) => { const knex = ( pgS3Storages as any ) . knex ; const s3Client = ( pgS3Storages as any ) . s3Client ; const s3Bucket = ( pgS3Storages as any ) . s3Bucket ; await knex ( tables . entrypoints ) . delete ( ) ; await knex ( tables . apps ) . delete ( ) ; await knex ( tables . bundles ) . delete ( ) ; await knex ( tables . operationLogs ) . delete ( ) ; await knex ( tables . usersAndGroups ) . delete ( ) ; await knex ( tables . groups ) . delete ( ) ; await knex ( tables . users ) . delete ( ) ; const objects = await s3Client . listObjects ( { Bucket : s3Bucket } ) . promise ( ) ; if ( objects . Contents && objects . Contents . length > 0 ) { await s3Client . deleteObjects ( { Bucket : s3Bucket , Delete : { Objects : objects . Contents . map ( ( obj ) => ( { Key : obj . Key ! , } ) ) , } , } ) . promise ( ) ; } } , } ) ; }