Skip to content

Commit e76bc8e

Browse files
committed
chore(test): set up ci for e2e and add a basic authenticated test
1 parent ae90ee8 commit e76bc8e

File tree

5 files changed

+90
-0
lines changed

5 files changed

+90
-0
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ jobs:
2424
- run: npm version
2525
- run: npm install
2626
- run: npm test
27+
- run: npm run e2e
28+
env:
29+
E2E_CLIENT_ID: ${{ secrets.E2E_CLIENT_ID }}
30+
E2E_CLIENT_SECRET: ${{ secrets.E2E_CLIENT_SECRET }}
31+
E2E_TA_EMAIL: ${{ secrets.E2E_TA_EMAIL }}
32+
E2E_IMS_ORG_ID: ${{ secrets.E2E_IMS_ORG_ID }}
33+
E2E_PRIVATE_KEY_B64: ${{ secrets.E2E_PRIVATE_KEY_B64 }}
2734
- run: npm run semantic-release-dry-run
2835
- name: Codecov
2936
uses: codecov/[email protected]

.github/workflows/release.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ jobs:
2121
run: npm install
2222
- name: Test
2323
run: npm test
24+
- name: End to End Test
25+
run: npm run e2e
26+
env:
27+
E2E_CLIENT_ID: ${{ secrets.E2E_CLIENT_ID }}
28+
E2E_CLIENT_SECRET: ${{ secrets.E2E_CLIENT_SECRET }}
29+
E2E_TA_EMAIL: ${{ secrets.E2E_TA_EMAIL }}
30+
E2E_IMS_ORG_ID: ${{ secrets.E2E_IMS_ORG_ID }}
31+
E2E_PRIVATE_KEY_B64: ${{ secrets.E2E_PRIVATE_KEY_B64 }}
2432
- name: Codecov
2533
uses: codecov/[email protected]
2634
with:

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ junit.xml
1515
/package-lock.json
1616
.aio
1717
permissions.json
18+
.env
19+
.secrets
20+
certificate_pub.crt
21+
private.key

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,30 @@ npm install
14171417

14181418
Of course this should not replace proper unit testing.
14191419

1420+
## End-to-End (E2E) Testing
1421+
1422+
To execute the end-to-end tests, create a file named `.env` in the project directory and configure it with your JWT credentials:
1423+
1424+
```
1425+
E2E_CLIENT_ID=<CLIENT ID>
1426+
E2E_CLIENT_SECRET=<CLIENT SECRET>
1427+
E2E_TA_EMAIL=<TECHNICAL ACCOUNT EMAIL>
1428+
E2E_IMS_ORG_ID=<ORG ID>
1429+
E2E_PRIVATE_KEY_B64=<Base64-Encoded PRIVATE KEY>
1430+
```
1431+
1432+
Note that the private key **must** be base64 encoded, e.g. by running
1433+
1434+
```
1435+
$ base64 -i private.key
1436+
```
1437+
1438+
With this in place the end-to-end tests can be run with
1439+
1440+
```
1441+
npm run e2e
1442+
```
1443+
14201444
# Standalone Use
14211445

14221446
In rare circumstances, it may be useful to run this plugin separately from the Adobe I/O CLI. To do this, install this npm module directly, i.e.

e2e/e2e.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,44 @@ OF ANY KIND, either express or implied. See the License for the specific languag
99
governing permissions and limitations under the License.
1010
*/
1111

12+
jest.unmock('@adobe/aio-lib-ims')
13+
jest.unmock('@adobe/aio-lib-core-config')
14+
1215
const execa = require('execa')
1316
const chalk = require('chalk')
1417
const { stdout } = require('stdout-stderr')
18+
const { context } = require('@adobe/aio-lib-ims')
1519
const fs = require('fs')
1620

21+
const CONTEXT_NAME = 'aio-cli-plugin-cloudmanager-e2e'
22+
23+
const CONTEXT_ARGS = ['--imsContextName', CONTEXT_NAME]
24+
1725
stdout.print = true
1826

27+
beforeEach(async () => {
28+
await clearAuthContext()
29+
})
30+
31+
const clearAuthContext = async () => {
32+
await context.set(CONTEXT_NAME, {})
33+
}
34+
35+
const bootstrapAuthContext = async () => {
36+
const contextObj = {
37+
client_id: process.env.E2E_CLIENT_ID,
38+
client_secret: process.env.E2E_CLIENT_SECRET,
39+
technical_account_id: process.env.E2E_TA_EMAIL,
40+
ims_org_id: process.env.E2E_IMS_ORG_ID,
41+
meta_scopes: [
42+
'ent_cloudmgr_sdk',
43+
],
44+
private_key: Buffer.from(process.env.E2E_PRIVATE_KEY_B64, 'base64').toString(),
45+
}
46+
47+
await context.set(CONTEXT_NAME, contextObj)
48+
}
49+
1950
test('plugin-cloudmanager help test', async () => {
2051
const packagejson = JSON.parse(fs.readFileSync('package.json').toString())
2152
const name = `${packagejson.name}`
@@ -26,3 +57,19 @@ test('plugin-cloudmanager help test', async () => {
2657

2758
console.log(chalk.green(` - done for ${chalk.bold(name)}`))
2859
})
60+
61+
test('plugin-cloudmanager list-programs', async () => {
62+
await bootstrapAuthContext()
63+
const packagejson = JSON.parse(fs.readFileSync('package.json').toString())
64+
const name = `${packagejson.name}`
65+
console.log(chalk.blue(`> e2e tests for ${chalk.bold(name)}`))
66+
67+
console.log(chalk.dim(' - plugin-cloudmanager list-programs ..'))
68+
69+
let result
70+
expect(() => { result = execa.sync('./bin/run', ['cloudmanager:list-programs', ...CONTEXT_ARGS, '--json'], { stderr: 'inherit' }) }).not.toThrow()
71+
const parsed = JSON.parse(result.stdout)
72+
expect(parsed).toSatisfy(arr => arr.length > 0)
73+
74+
console.log(chalk.green(` - done for ${chalk.bold(name)}`))
75+
})

0 commit comments

Comments
 (0)