mirror of
https://github.com/ONLYOFFICE/server.git
synced 2026-02-10 18:05:07 +08:00
[test] Start mock server in storage.tests.js to run tests independently of live server
This commit is contained in:
40
.github/workflows/fsStorageTests.yml
vendored
40
.github/workflows/fsStorageTests.yml
vendored
@ -19,7 +19,7 @@ jobs:
|
||||
- name: Caching dependencies
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: '16'
|
||||
node-version: '20'
|
||||
cache: 'npm'
|
||||
cache-dependency-path: |
|
||||
./npm-shrinkwrap.json
|
||||
@ -32,25 +32,9 @@ jobs:
|
||||
npm --prefix Common ci
|
||||
npm --prefix DocService ci
|
||||
|
||||
- name: Install and start RabbitMQ
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y rabbitmq-server
|
||||
sudo systemctl start rabbitmq-server
|
||||
sudo rabbitmqctl status
|
||||
|
||||
- name: Install and configure PostgreSQL
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y postgresql postgresql-contrib
|
||||
sudo systemctl start postgresql
|
||||
sudo -u postgres psql -c "CREATE USER onlyoffice WITH PASSWORD 'onlyoffice';"
|
||||
sudo -u postgres psql -c "CREATE DATABASE onlyoffice OWNER onlyoffice;"
|
||||
sudo -u postgres psql -c "ALTER USER onlyoffice WITH SUPERUSER;"
|
||||
sudo -u postgres psql -d onlyoffice -f schema/postgresql/createdb.sql
|
||||
|
||||
- name: Creating service configuration
|
||||
run: |
|
||||
mkdir -p /tmp/storage
|
||||
mkdir -p Common/config
|
||||
echo '{
|
||||
"storage": {
|
||||
@ -75,23 +59,5 @@ jobs:
|
||||
},
|
||||
}' > Common/config/local.json
|
||||
|
||||
- name: Create storage directory
|
||||
run: mkdir -p /tmp/storage
|
||||
|
||||
- name: Start server instance
|
||||
run: |
|
||||
cd DocService && npx cross-env NODE_ENV=development-linux NODE_CONFIG_DIR=../Common/config node sources/server.js &
|
||||
sleep 10
|
||||
|
||||
- name: Run storage tests
|
||||
run: |
|
||||
cd ./DocService
|
||||
npx jest ../tests/integration/withServerInstance/storage.tests.js --inject-globals=false --config=../tests/jest.config.js
|
||||
|
||||
- name: Cleanup
|
||||
if: always()
|
||||
run: |
|
||||
pkill -f "node sources/server.js" || true
|
||||
rm -rf /tmp/storage
|
||||
sudo systemctl stop rabbitmq-server
|
||||
sudo systemctl stop postgresql
|
||||
run: npm run storage-tests
|
||||
@ -20,6 +20,7 @@
|
||||
"perf-png": "cd ./DocService&& cross-env NODE_ENV=development-windows NODE_CONFIG_DIR=../Common/config node ../tests/perf/convertImageToPng.js",
|
||||
"unit tests": "cd ./DocService && jest unit --inject-globals=false --config=../tests/jest.config.js",
|
||||
"integration tests with server instance": "cd ./DocService && jest integration/withServerInstance --inject-globals=false --config=../tests/jest.config.js",
|
||||
"storage-tests": "cd ./DocService && jest integration/withServerInstance/storage.tests.js --inject-globals=false --config=../tests/jest.config.js",
|
||||
"integration database tests": "cd ./DocService && jest integration/databaseTests --inject-globals=false --config=../tests/jest.config.js",
|
||||
"tests": "cd ./DocService && jest --inject-globals=false --config=../tests/jest.config.js",
|
||||
"tests:dev": "cd ./DocService && jest --inject-globals=false --config=../tests/jest.config.js --watch",
|
||||
|
||||
@ -30,7 +30,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
const {jest, describe, test, expect} = require('@jest/globals');
|
||||
const {jest, describe, test, expect, beforeAll, afterAll} = require('@jest/globals');
|
||||
jest.mock("fs/promises", () => ({
|
||||
...jest.requireActual('fs/promises'),
|
||||
cp: jest.fn().mockImplementation((from, to) => fs.writeFileSync(to, testFileData3))
|
||||
}));
|
||||
const { cp } = require('fs/promises');
|
||||
const http = require('http');
|
||||
const https = require('https');
|
||||
const fs = require('fs');
|
||||
@ -41,26 +46,23 @@ let testFileData2 = "test22";
|
||||
let testFileData3 = "test333";
|
||||
let testFileData4 = testFileData3;
|
||||
|
||||
jest.mock("fs/promises", () => ({
|
||||
...jest.requireActual('fs/promises'),
|
||||
cp: jest.fn().mockImplementation((from, to) => fs.writeFileSync(to, testFileData3))
|
||||
}));
|
||||
const { cp } = require('fs/promises');
|
||||
|
||||
const express = require('express');
|
||||
const operationContext = require('../../../Common/sources/operationContext');
|
||||
const tenantManager = require('../../../Common/sources/tenantManager');
|
||||
const storage = require('../../../Common/sources/storage/storage-base');
|
||||
const utils = require('../../../Common/sources/utils');
|
||||
const commonDefines = require("../../../Common/sources/commondefines");
|
||||
const config = require('../../../Common/node_modules/config');
|
||||
const staticRouter = require('../../../DocService/sources/routes/static');
|
||||
|
||||
const cfgCacheStorage = config.get('storage');
|
||||
const cfgPersistentStorage = utils.deepMergeObjects({}, cfgCacheStorage, config.get('persistentStorage'));
|
||||
|
||||
const ctx = operationContext.global;
|
||||
const PORT = 3456;
|
||||
const rand = Math.floor(Math.random() * 1000000);
|
||||
const testDir = "DocService-DocsCoServer-storage-" + rand;
|
||||
const baseUrl = "http://localhost:8000";
|
||||
const baseUrl = `http://localhost:${PORT}`;
|
||||
const urlType = commonDefines.c_oAscUrlTypes.Session;
|
||||
let testFile1 = testDir + "/test1.txt";
|
||||
let testFile2 = testDir + "/test2.txt";
|
||||
@ -71,6 +73,23 @@ let specialDirForgotten = "forgotten";
|
||||
|
||||
console.debug(`testDir: ${testDir}`)
|
||||
|
||||
let server;
|
||||
|
||||
beforeAll(async () => {
|
||||
//start server to server static files generated by getSignedUrl
|
||||
const app = express();
|
||||
app.use('/', staticRouter);
|
||||
server = app.listen(PORT, () => {
|
||||
console.debug('listening on ' + PORT);
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
if (server) {
|
||||
await new Promise((resolve) => server.close(resolve));
|
||||
}
|
||||
});
|
||||
|
||||
function getStorageCfg(specialDir) {
|
||||
return specialDir ? cfgPersistentStorage : cfgCacheStorage;
|
||||
}
|
||||
@ -354,38 +373,3 @@ describe('storage mix common and forgotten dir', function () {
|
||||
});
|
||||
});
|
||||
|
||||
// describe('storage direct URL testing', function () {
|
||||
// test("getSignedUrl with direct URLs enabled", async () => {
|
||||
// // we need to mock the getStorageCfg to return the config with direct URLs enabled
|
||||
|
||||
// let buffer = Buffer.from(testFileData1);
|
||||
// let res = await storage.putObject(ctx, testFile1, buffer, buffer.length, specialDirCache);
|
||||
// expect(res).toEqual(undefined);
|
||||
|
||||
// let url = await storage.getSignedUrl(ctx, baseUrl, testFile1, urlType, undefined, undefined, specialDirCache);
|
||||
// let data = await request(url);
|
||||
// expect(data).toEqual(testFileData1);
|
||||
|
||||
// if (cfgCacheStorage.name !== 'storage-fs') {
|
||||
// expect(url).toContain(cfgCacheStorage.endpoint);
|
||||
// expect(url).toContain(cfgCacheStorage.bucketName);
|
||||
// }
|
||||
// });
|
||||
|
||||
|
||||
// test("getSignedUrl with direct URLs disabled", async () => {
|
||||
// // we need to mock the getStorageCfg to return the config with direct URLs disabled
|
||||
|
||||
// let buffer = Buffer.from(testFileData1);
|
||||
// let res = await storage.putObject(ctx, testFile1, buffer, buffer.length, specialDirCache);
|
||||
// expect(res).toEqual(undefined);
|
||||
|
||||
// let url = await storage.getSignedUrl(ctx, baseUrl, testFile1, urlType, undefined, undefined, specialDirCache);
|
||||
// let data = await request(url);
|
||||
// expect(data).toEqual(testFileData1);
|
||||
|
||||
// expect(url).toContain(`md5`);
|
||||
// expect(url).toContain(`expires`);
|
||||
// expect(url).toContain(cfgCacheStorage.storageFolderName);
|
||||
// });
|
||||
// });
|
||||
Reference in New Issue
Block a user