Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Thels committed Dec 20, 2024
1 parent 02a733d commit 1ab6833
Show file tree
Hide file tree
Showing 9 changed files with 313 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"clearOnRun": "none"
},
"java.compile.nullAnalysis.mode": "automatic",
"java.configuration.updateBuildConfiguration": "automatic"
"java.configuration.updateBuildConfiguration": "automatic",
"testing.automaticallyOpenTestResults": "neverOpen"
}
6 changes: 5 additions & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
"author": "",
"license": "ISC",
"dependencies": {
"@types/supertest": "^6.0.2",
"axios": "^1.7.9",
"canvas": "^2.11.2",
"commander": "^12.0.0",
"copyfiles": "^2.4.1",
"jest-environment-node": "^29.7.0",
"mkdirp": "^3.0.1"
},
"devDependencies": {
Expand All @@ -47,10 +50,11 @@
"eslint": "^9.13.0",
"globals": "^15.12.0",
"jest": "^29.7.0",
"supertest": "^7.0.0",
"ts-jest": "^29.2.5",
"ts-node": "10.9.2",
"tsup": "^8.0.0",
"typescript": "^5.4.3",
"xml2js": "^0.6.2"
}
}
}
38 changes: 37 additions & 1 deletion cli/src/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import * as fs from 'fs';
import * as os from 'os';
import { parseStringPromise } from 'xml2js';
import util from 'util';
import axios from 'axios';


const execPromise = util.promisify(exec);

Expand All @@ -13,7 +15,7 @@ describe('CLI Integration Tests', () => {
const millisPerSecond = 1000;
const integrationTestPrefix = 'calm-test';
const projectRoot = __dirname;
jest.setTimeout(30 * millisPerSecond);
jest.setTimeout(30 * millisPerSecond); // Uncomment this line to set the timeout for Jest tests

beforeAll(async () => {
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), integrationTestPrefix));
Expand Down Expand Up @@ -161,6 +163,40 @@ describe('CLI Integration Tests', () => {
done();
});
});


test('example server command - health check', (done) => {
const serverCommand = 'calm server';

const serverProcess = exec(serverCommand, async (_error, _stdout, _stderr) => {
const response = await axios.get('http://localhost:3000/api/validate/health');
expect(response.status).toBe(200);
done();
});

serverProcess.kill();


}, millisPerSecond * 30);


test('example server command - basic validation - temp', async () => {
const serverCommand = 'calm server --verbose';

const serverProcess = exec(serverCommand, async (_error, _stdout, _stderr) => {
});

const response = await axios.get('http://localhost:3000/api/validate/health');
expect(response.status).toBe(200);

serverProcess.kill();


}, millisPerSecond * 5);




});


Expand Down
25 changes: 25 additions & 0 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { Option, program } from 'commander';
import path from 'path';
import { mkdirp } from 'mkdirp';
import { writeFileSync } from 'fs';
import express from 'express';
import { allRoutes } from './routes/routes';
import { Application } from 'express';

const FORMAT_OPTION = '-f, --format <format>';
const INSTANTIATION_OPTION = '-i, --instantiation <file>';
Expand All @@ -15,6 +18,8 @@ const SCHEMAS_OPTION = '-s, --schemaDirectory <path>';
const STRICT_OPTION = '--strict';
const VERBOSE_OPTION = '-v, --verbose';



program
.name('calm')
.version('0.2.5')
Expand Down Expand Up @@ -70,6 +75,26 @@ program
exitBasedOffOfValidationOutcome(outcome, options.strict);
});

program
.command('server')
.description('Start a HTTP server to proxy CLI commands.')
.option('-p, --port <port>', 'Port to run the server on', '3000')
.option(VERBOSE_OPTION, 'Enable verbose logging.', false)
.action((options) => {

const app: Application = express();
app.use(express.json());
app.use('/', allRoutes);

const port = options.port;

app.listen(port, () => {
if (options.verbose) {
console.log(`CALM Server is running on http://localhost:${port}`);
}
});
});

function writeOutputFile(output: string, validationsOutput: string) {
if (output) {
const dirname = path.dirname(output);
Expand Down
9 changes: 9 additions & 0 deletions cli/src/routes/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import express from 'express';

import { validationRouter } from './validation-route';

import { Router } from 'express';

export const allRoutes: Router = express.Router();

allRoutes.use('/api/validate', validationRouter);
19 changes: 19 additions & 0 deletions cli/src/routes/validation-route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// import { CALM_META_SCHEMA_DIRECTORY, getFormattedOutput, validate } from '@finos/calm-shared';
import { Router } from 'express';

export const validationRouter: Router = Router();


validationRouter.get('/example', (req, res) => {
// const { patternFile, instantiationFile, verbose } = req.body;
// console.error('req.body', req.body);
// const outcome = await validate(patternFile, instantiationFile, CALM_META_SCHEMA_DIRECTORY, verbose);
// const content = getFormattedOutput(outcome, 'json');
// res.status(200).json({requestBody: req.body}});
console.log(req.body);
res.status(200).json({ requestBody: req.body });
});

validationRouter.get('/health', (_req, res) => {
res.status(200).json({ status: 'OK' });
});
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

https://calm.finos.org/

I
Loading

0 comments on commit 1ab6833

Please sign in to comment.