generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.test.js
75 lines (68 loc) · 1.68 KB
/
index.test.js
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
const { checkRunner } = require('./index');
const mockGetJson = jest.fn();
jest.mock('@actions/http-client', () => {
return {
HttpClient: jest.fn().mockImplementation(() => {
return {
getJson: mockGetJson,
};
}),
BearerCredentialHandler: jest.fn(),
};
});
describe('checkRunner', () => {
it('should use the primary runner if it is online', async () => {
mockGetJson.mockResolvedValue({
statusCode: 200,
result: {
runners: [
{
status: 'online',
labels: [
{ name: 'self-hosted' },
{ name: 'linux' },
],
},
],
},
});
const result = await checkRunner({
token: 'fake-token',
owner: 'fake-owner',
repo: 'fake-repo',
primaryRunnerLabels: ['self-hosted', 'linux'],
fallbackRunner: 'ubuntu-latest',
});
expect(result).toEqual({
useRunner: '["self-hosted","linux"]',
primaryIsOnline: true,
});
});
it('should use the fallback runner if the primary is not online', async () => {
mockGetJson.mockResolvedValue({
statusCode: 200,
result: {
runners: [
{
status: 'offline',
labels: [
{ name: 'self-hosted' },
{ name: 'linux' },
],
},
],
},
});
const result = await checkRunner({
token: 'fake-token',
owner: 'fake-owner',
repo: 'fake-repo',
primaryRunnerLabels: ['self-hosted', 'linux'],
fallbackRunner: 'ubuntu-latest',
});
expect(result).toEqual({
useRunner: '["ubuntu-latest"]',
primaryIsOnline: false,
});
});
});