-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Completes integration tests for the codebase - Makes the execaCMDRunner catch the invalid commands - Removes get-stream dependency from execaCMDRunner - Uploads codecoverage to codecov - Adds new yarn command to watch the tests - Adds emojis to README
- Loading branch information
1 parent
f28f400
commit d31da4a
Showing
12 changed files
with
192 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,31 @@ | ||
# Overview | ||
# :runner: Digital Twin Runner | ||
|
||
A commandline utility to run a digital twin. It will provide REST interface to execute lifecycle scripts of a digital twin. It is possible to run multiple instances of this utility within one computer. | ||
A commandline utility to run a digital twin. It will provide REST interface | ||
to execute lifecycle scripts of a digital twin. It is possible to run | ||
multiple instances of this utility within one computer. | ||
|
||
## Developer Commands | ||
## :hammer_and_wrench: Developer Commands | ||
|
||
```bash | ||
yarn install # Install dependencies for the microservice | ||
yarn syntax # analyzes source code for potential errors, style violations, and other issues, | ||
yarn build # compile ES6 files into ES5 javascript files and copy all JS files into build/ directory | ||
yarn test # run tests | ||
yarn test:watchAll #Watch changes in test/ and run the tests | ||
yarn start # start the application | ||
yarn clean # deletes directories "build", "coverage", and "dist" | ||
``` | ||
|
||
## Publish Package | ||
## :package: :ship: Publish Package | ||
|
||
### Setup private npm registry | ||
|
||
This package need to be published to an npm registry. There after, the package can be installed as a system command. Since publishing to npmjs.org is irrevocable and public, developers are encouraged to setup their own private npm registry for local development. We recommend using [verdaccio](https://verdaccio.org) for this task. The following commands help you create a working private npm registry for development. | ||
This package need to be published to an npm registry. There after, the package | ||
can be installed as a system command. Since publishing to npmjs.org is | ||
irrevocable and public, developers are encouraged to setup their own private | ||
npm registry for local development. We recommend using | ||
[verdaccio](https://verdaccio.org) for this task. The following commands | ||
help you create a working private npm registry for development. | ||
|
||
```bash | ||
docker run -d --name verdaccio -p 4873:4873 verdaccio/verdaccio | ||
|
@@ -26,7 +34,8 @@ npm set registry http://localhost:4873/ | |
yarn config set registry "http://localhost:4873" | ||
``` | ||
|
||
You can open `http://localhost:4873` in your browser, login with the user credentials to see the packages published. | ||
You can open `http://localhost:4873` in your browser, login with | ||
the user credentials to see the packages published. | ||
|
||
### Publish to private registry | ||
|
||
|
@@ -39,7 +48,11 @@ yarn publish --no-git-tag-version #increments version in package.json, publishes | |
yarn publish #increments version in package.json, publishes to registry and adds a git tag | ||
``` | ||
|
||
The package version in package.json gets updated as well. You can open `http://localhost:4873` in your browser, login with the user credentials to see the packages published. Please see [verdaccio docs](https://verdaccio.org/docs/installation/#basic-usage) for more information. | ||
The package version in package.json gets updated as well. You can | ||
open `http://localhost:4873` in your browser, login with the user credentials | ||
to see the packages published. Please see | ||
[verdaccio docs](https://verdaccio.org/docs/installation/#basic-usage) | ||
for more information. | ||
|
||
If there is a need to unpublish a package, ex: `@dtaas/[email protected]`, do: | ||
|
||
|
@@ -54,3 +67,9 @@ sudo npm install --registry http://localhost:4873 -g @dtaas/runner | |
sudo npm list -g # should list @dtaas/runner in the packages | ||
sudo npm remove --global @dtaas/runner | ||
``` | ||
|
||
## :balance_scale: License | ||
|
||
This software is owned by | ||
[The INTO-CPS Association](https://into-cps.org/) | ||
and is available under [the INTO-CPS License](./LICENSE.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
import { Module } from '@nestjs/common'; | ||
import AppController from './app.controller'; | ||
import AppService from './app.service'; | ||
import LifeCycleManager from './lifecycleManager.service'; | ||
import Queue from './queue.service'; | ||
|
||
@Module({ | ||
imports: [], | ||
controllers: [AppController], | ||
providers: [AppService, LifeCycleManager, Queue], | ||
providers: [LifeCycleManager, Queue], | ||
}) | ||
export default class AppModule {} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
servers/execution/runner/test/integration/lifecycleManager.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { describe, expect, it } from '@jest/globals'; | ||
import LifeCycleManager from 'src/lifecycleManager.service'; | ||
import { DTLifeCycle, Phase } from 'src/interfaces/lifecycle.interface'; | ||
import ExecaCMDRunner from 'src/execaCMDRunner'; | ||
|
||
describe('Check LifecycleManager', () => { | ||
it('Should create object', async () => { | ||
try { | ||
const dt: DTLifeCycle = new LifeCycleManager(); | ||
expect(dt).toBeInstanceOf(LifeCycleManager); | ||
} catch (error) { | ||
expect(fail); | ||
} | ||
}); | ||
|
||
it('Should change to valid phase', async () => { | ||
const dt: DTLifeCycle = new LifeCycleManager(); | ||
let status: boolean = false; | ||
let logs: Map<string, string> = new Map<string, string>(); | ||
|
||
[status, logs] = await dt.changePhase('whoami'); | ||
|
||
expect(status).toBe(true); | ||
expect(logs.get('stdout')).toEqual(expect.any(String)); | ||
expect(logs.get('stderr')).toEqual(''); | ||
}); | ||
|
||
it('Should not change to invalid phase', async () => { | ||
const dt: DTLifeCycle = new LifeCycleManager(); | ||
let status: boolean = true; | ||
|
||
[status] = await dt.changePhase('asdfghjkl'); | ||
|
||
expect(status).toBe(false); | ||
}); | ||
|
||
it('Should return undefined if there has been no changePhase calls', async () => { | ||
const dt: DTLifeCycle = new LifeCycleManager(); | ||
let phase: Phase | undefined = { | ||
name: 'hello', | ||
status: 'valid', | ||
task: new ExecaCMDRunner(''), | ||
}; | ||
|
||
phase = dt.checkPhase(); | ||
|
||
expect(phase).toBe(undefined); | ||
}); | ||
|
||
it('Should hold correct phase history', async () => { | ||
const dt: DTLifeCycle = new LifeCycleManager(); | ||
const status: boolean[] = []; | ||
const pastPhases: Array<string> = ['date', 'whoami']; | ||
|
||
dt.changePhase(pastPhases[0]).then(([value]) => { | ||
status.push(value); | ||
}); | ||
dt.changePhase(pastPhases[1]).then(([value]) => { | ||
status.push(value); | ||
}); | ||
|
||
const pastPhasesActual = dt.checkHistory(); | ||
|
||
expect(pastPhasesActual).toStrictEqual(pastPhases); | ||
}); | ||
}); |
53 changes: 53 additions & 0 deletions
53
servers/execution/runner/test/integration/queue.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { describe, it, expect } from '@jest/globals'; | ||
import Queue from 'src/queue.service'; | ||
import { Phase } from 'src/interfaces/lifecycle.interface'; | ||
import ExecaCMDRunner from 'src/execaCMDRunner'; | ||
|
||
const phases: Phase[] = [ | ||
{ | ||
name: 'hello', | ||
status: 'valid', | ||
task: new ExecaCMDRunner(''), | ||
}, | ||
{ | ||
name: 'world', | ||
status: 'valid', | ||
task: new ExecaCMDRunner(''), | ||
}, | ||
{ | ||
name: 'terminate', | ||
status: 'invalid', | ||
task: new ExecaCMDRunner(''), | ||
}, | ||
]; | ||
|
||
describe('check Queue service', () => { | ||
it('should store a phase', async () => { | ||
const queue: Queue = new Queue(); | ||
|
||
expect(queue.enqueue(phases[0])).toBe(true); | ||
}); | ||
|
||
it('should return active phase as undefined when queue is empty', async () => { | ||
const queue: Queue = new Queue(); | ||
|
||
expect(queue.activePhase()).toBe(undefined); | ||
}); | ||
|
||
it('should return active phase when queue is non-empty', async () => { | ||
const queue: Queue = new Queue(); | ||
|
||
queue.enqueue(phases[0]); | ||
|
||
expect(queue.activePhase()).toBe(phases[0]); | ||
}); | ||
|
||
it('should return correct active phase when queue has more than one phase', async () => { | ||
const queue: Queue = new Queue(); | ||
|
||
queue.enqueue(phases[0]); | ||
queue.enqueue(phases[1]); | ||
|
||
expect(queue.activePhase()).toBe(phases[1]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters