-
Notifications
You must be signed in to change notification settings - Fork 553
Expand file tree
/
Copy pathget-retry-options.test.ts
More file actions
88 lines (71 loc) · 2.71 KB
/
get-retry-options.test.ts
File metadata and controls
88 lines (71 loc) · 2.71 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
77
78
79
80
81
82
83
84
85
86
87
88
/* eslint-disable @typescript-eslint/no-explicit-any */
import {getRetryOptions} from '../src/retry-options'
describe('getRequestOptions', () => {
test('retries disabled if retries == 0', async () => {
const [retryOptions, requestOptions, throttlingOptions] = getRetryOptions(
0,
[400, 500, 502],
[]
)
expect(retryOptions.enabled).toBe(false)
expect(retryOptions.doNotRetry).toBeFalsy()
expect(requestOptions?.retries).toBeFalsy()
expect(throttlingOptions?.onRateLimit).toBeFalsy()
expect(throttlingOptions?.onSecondaryRateLimit).toBeFalsy()
})
test('properties set if retries > 0', async () => {
const [retryOptions, requestOptions, throttlingOptions] = getRetryOptions(
1,
[400, 500, 502],
[]
)
expect(retryOptions.enabled).toBe(true)
expect(retryOptions.doNotRetry).toEqual([400, 500, 502])
expect(requestOptions?.retries).toEqual(1)
expect(throttlingOptions?.onRateLimit).toBeDefined()
expect(throttlingOptions?.onSecondaryRateLimit).toBeDefined()
})
test('properties set if retries > 0', async () => {
const [retryOptions, requestOptions, throttlingOptions] = getRetryOptions(
1,
[400, 500, 502],
[]
)
expect(retryOptions.enabled).toBe(true)
expect(retryOptions.doNotRetry).toEqual([400, 500, 502])
expect(requestOptions?.retries).toEqual(1)
expect(throttlingOptions?.onRateLimit).toBeDefined()
expect(throttlingOptions?.onSecondaryRateLimit).toBeDefined()
})
test('retryOptions.doNotRetry not set if exemptStatusCodes isEmpty', async () => {
const [retryOptions, requestOptions, throttlingOptions] = getRetryOptions(
1,
[],
[]
)
expect(retryOptions.enabled).toBe(true)
expect(retryOptions.doNotRetry).toBeUndefined()
expect(requestOptions?.retries).toEqual(1)
expect(throttlingOptions?.onRateLimit).toBeDefined()
expect(throttlingOptions?.onSecondaryRateLimit).toBeDefined()
})
test('requestOptions does not override defaults from @actions/github', async () => {
const [retryOptions, requestOptions, throttlingOptions] = getRetryOptions(
1,
[],
{
request: {
agent: 'default-user-agent'
},
foo: 'bar'
}
)
expect(retryOptions.enabled).toBe(true)
expect(retryOptions.doNotRetry).toBeUndefined()
expect(requestOptions?.retries).toEqual(1)
expect(requestOptions?.agent).toEqual('default-user-agent')
expect(requestOptions?.foo).toBeUndefined() // this should not be in the `options.request` object, but at the same level as `request`
expect(throttlingOptions?.onRateLimit).toBeDefined()
expect(throttlingOptions?.onSecondaryRateLimit).toBeDefined()
})
})