Repository navigation
Expand file tree
/
Copy pathpost.tests.ts
More file actions
76 lines (62 loc) · 2.64 KB
/
Copy pathpost.tests.ts
File metadata and controls
76 lines (62 loc) · 2.64 KB
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
import sinon from 'sinon';
import * as core from '@actions/core';
import { ContainerMapping } from '../lib/v1/container-mapping';
describe('postjob runPostJob', function() {
let getIDTokenStub: sinon.SinonStub;
let getStateStub: sinon.SinonStub;
let debugStub: sinon.SinonStub;
let infoStub: sinon.SinonStub;
beforeEach(() => {
infoStub = sinon.stub(core, 'info');
debugStub = sinon.stub(core, 'debug');
getStateStub = sinon.stub(core, 'getState').returns('2023-01-23T12:34:56.789Z');
getIDTokenStub = sinon.stub(core, 'getIDToken');
});
afterEach(() => {
infoStub.restore();
debugStub.restore();
getStateStub.restore();
getIDTokenStub.restore();
});
it('should handle missing OIDC token gracefully', async () => {
getIDTokenStub.rejects(new Error('Unable to get ACTIONS_ID_TOKEN_REQUEST_URL env variable'));
const cm = new ContainerMapping();
// runPostJob catches all errors internally
await cm.runPostJob();
sinon.assert.calledOnce(getIDTokenStub);
});
it('should skip container mapping if caller is not onboarded', async () => {
getIDTokenStub.resolves('mock-token');
// Stub the https request for checkCallerIsCustomer to return 403 (not onboarded)
const https = require('https');
const requestStub = sinon.stub(https, 'request');
requestStub.callsFake((_url: string, _options: any, callback: any) => {
const res = {
statusCode: 403,
on: (event: string, handler: any) => {
if (event === 'end') handler();
if (event === 'data') { /* no data */ }
}
};
callback(res);
return { on: sinon.stub(), end: sinon.stub(), write: sinon.stub() };
});
const cm = new ContainerMapping();
await cm.runPostJob();
sinon.assert.calledOnce(getIDTokenStub);
requestStub.restore();
});
it('should use fallback start time when PreJobStartTime is not set', async () => {
getStateStub.returns('');
getIDTokenStub.rejects(new Error('no token'));
const cm = new ContainerMapping();
await cm.runPostJob();
sinon.assert.calledWith(debugStub, sinon.match('PreJobStartTime not defined'));
});
});
describe('postjob ContainerMapping properties', function() {
it('should have succeedOnError set to true', () => {
const cm = new ContainerMapping();
sinon.assert.match(cm.succeedOnError, true);
});
});