Skip to content

Commit 5e7c421

Browse files
authored
feat: optionally submit the test result to a release tagging service (#16)
1 parent 5771db6 commit 5e7c421

File tree

5 files changed

+116
-10
lines changed

5 files changed

+116
-10
lines changed

package-lock.json

Lines changed: 9 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@mojaloop/ml-testing-toolkit-client-lib",
33
"description": "Testing Toolkit Client Library",
4-
"version": "1.5.1",
4+
"version": "1.6.0-snapshot.1",
55
"license": "Apache-2.0",
66
"author": "Vijaya Kumar Guthi, ModusBox Inc. ",
77
"contributors": [
@@ -63,7 +63,7 @@
6363
"snapshot": "npx standard-version --no-verify --skip.changelog --prerelease snapshot --releaseCommitMessageFormat 'chore(snapshot): {{currentTag}}'"
6464
},
6565
"dependencies": {
66-
"@mojaloop/central-services-logger": "11.5.4",
66+
"@mojaloop/central-services-logger": "11.5.5",
6767
"@mojaloop/ml-testing-toolkit-shared-lib": "14.0.3",
6868
"@mojaloop/sdk-standard-components": "19.6.4",
6969
"@slack/webhook": "7.0.4",
@@ -80,7 +80,7 @@
8080
"node-strings": "1.0.2",
8181
"parse-strings-in-object": "1.6.0",
8282
"path": "0.12.7",
83-
"rc": "1.2.8",
83+
"rc": "^1.2.8",
8484
"socket.io-client": "4.8.1"
8585
},
8686
"devDependencies": {

src/extras/release-cd.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*****
2+
License
3+
--------------
4+
Copyright © 2017 Bill & Melinda Gates Foundation
5+
The Mojaloop files are made available by the Bill & Melinda Gates Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
8+
Contributors
9+
--------------
10+
This is the official list of the Mojaloop project contributors for this file.
11+
Names of the original copyright holders (individuals or organizations)
12+
should be listed with a '*' in the first column. People who have
13+
contributed from an organization can be listed under the organization
14+
that actually holds the copyright for their contributions (see the
15+
Gates Foundation organization for an example). Those individuals should have
16+
their names indented and be marked with a '-'. Email address can be added
17+
optionally within square brackets <email>.
18+
* Gates Foundation
19+
20+
* Infitx
21+
- Kalin Krustev <[email protected]> (Original Author)
22+
--------------
23+
******/
24+
const axios = require('axios').default
25+
const config = require('rc')('release_cd', {})
26+
27+
module.exports = async function (name, result) {
28+
if (!config.reportUrl) return
29+
const data = {
30+
[`tests.${name}`]: result
31+
}
32+
console.log(`Sending report to ${config.reportUrl}`, data)
33+
await axios({
34+
method: 'post',
35+
url: config.reportUrl,
36+
data
37+
})
38+
}

src/modes/outbound.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const fs = require('fs')
2929
const { promisify } = require('util')
3030
const objectStore = require('../objectStore')
3131
const slackBroadcast = require('../extras/slack-broadcast')
32+
const releaseCd = require('../extras/release-cd')
3233
const TemplateGenerator = require('../utils/templateGenerator')
3334
const { TraceHeaderUtils } = require('@mojaloop/ml-testing-toolkit-shared-lib')
3435

@@ -193,6 +194,11 @@ const handleIncomingProgress = async (progress) => {
193194
console.log(fStr.red(`Report not saved: ${progress.saveReportStatus.message}`))
194195
}
195196
}
197+
try {
198+
await releaseCd(config.reportName, progress.totalResult.runtimeInformation)
199+
} catch (err) {
200+
console.error(err)
201+
}
196202
await slackBroadcast.sendSlackNotification(progress.totalResult, resultReport.uploadedReportURL)
197203
} catch (err) {
198204
console.log(err)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*****
2+
License
3+
--------------
4+
Copyright © 2017 Bill & Melinda Gates Foundation
5+
The Mojaloop files are made available by the Bill & Melinda Gates Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
8+
Contributors
9+
--------------
10+
This is the official list of the Mojaloop project contributors for this file.
11+
Names of the original copyright holders (individuals or organizations)
12+
should be listed with a '*' in the first column. People who have
13+
contributed from an organization can be listed under the organization
14+
that actually holds the copyright for their contributions (see the
15+
Gates Foundation organization for an example). Those individuals should have
16+
their names indented and be marked with a '-'. Email address can be added
17+
optionally within square brackets <email>.
18+
* Gates Foundation
19+
20+
* Infitx
21+
- Kalin Krustev <[email protected]> (Original Author)
22+
--------------
23+
******/
24+
25+
const rc = require('rc')
26+
jest.mock('rc')
27+
const axios = require('axios')
28+
jest.spyOn(axios, 'default')
29+
axios.default.mockImplementation(() => Promise.resolve({}))
30+
31+
const config = {}
32+
rc.mockImplementation(() => config)
33+
34+
const releaseCd = require('../../../src/extras/release-cd')
35+
36+
describe('Release CD', () => {
37+
describe('Post test results', () => {
38+
it('Posts test result to configured URL', async () => {
39+
const name = 'test'
40+
const result = {}
41+
config.reportUrl = 'http://example.com'
42+
await releaseCd(name, result)
43+
expect(axios.default).toHaveBeenCalledWith({
44+
method: 'post',
45+
url: 'http://example.com',
46+
data: {
47+
[`tests.${name}`]: result
48+
}
49+
})
50+
})
51+
it('Does not post test result if no report URL is configured', async () => {
52+
const name = 'test'
53+
const result = {}
54+
config.reportUrl = undefined
55+
axios.default.mockClear()
56+
await releaseCd(name, result)
57+
expect(axios.default).not.toHaveBeenCalled()
58+
})
59+
})
60+
})

0 commit comments

Comments
 (0)