-
Notifications
You must be signed in to change notification settings - Fork 2
89 lines (87 loc) · 3.14 KB
/
test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: Test
on:
workflow_dispatch:
pull_request:
# When all changes are Markdown files, this workflow will not run
paths-ignore:
- '**.md'
push:
branches:
- master
jobs:
test-pipeline:
name: Test Pipeline
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest, macos-latest]
version: [ '18.x', '20.x', '21.x' ]
steps:
- uses: actions/checkout@v3
- name: Setup node ${{ matrix.version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.version }}
- name: Build and Install @sophos-factory/api-client
run: |
npm ci
npm run build
mkdir -p ../test
npm pack
cp sophos-factory-api-client-*.tgz ../test/api-client.tgz
cd ../test
npm init -f -y
npm install api-client.tgz
- name: Create Test Scripts
working-directory: ../test
run: |
cat << SCRIPT > ./testProjects.js
const { factoryApi } = require('@sophos-factory/api-client')
const accessToken = process.env.TOKEN;
const proj = '61ccbe03d42b9bdcc88365d8';
const config = new factoryApi.Configuration({
accessToken: accessToken,
basePath: 'https://api.dev.factory.sophos.com/v1'
});
const client = new factoryApi.ProjectsApi(config);
(async () => {
const res = await client.getProject(proj);
if (res.data.name.includes('CRUD Testing')) console.info('Everything looks good!');
})().catch(e => {
if (e.response && e.response.status) {
console.error(`Request failed with status code: ${e.response.status}`);
console.error('Response body:');
console.error(e.response.data);
} else {
console.error(`Request failed with error: ${e}`);
}
});
SCRIPT
cat << SCRIPT > ./testOrganizations.js
const { factoryAuthApi } = require('@sophos-factory/api-client')
const accessToken = process.env.TOKEN;
const config = new factoryAuthApi.Configuration({
accessToken: accessToken,
basePath: 'https://api.dev.factory.sophos.com/v1'
});
const client = new factoryAuthApi.OrganizationsApi(config);
(async () => {
const res = await client.getOrganizationsPublic();
if (res.length > 0) console.info('Everything looks good!');
})().catch(e => {
if (e.response && e.response.status) {
console.error(`Request failed with status code: ${e.response.status}`);
console.error('Response body:');
console.error(e.response.data);
} else {
console.error(`Request failed with error: ${e}`);
}
});
SCRIPT
- name: Run Smoke Test
working-directory: ../test
env:
TOKEN: ${{ secrets.FACTORY_API_TOKEN }}
run: |
node testProjects.js
node testOrganizations.js