-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy patherrors.test.js
More file actions
89 lines (76 loc) · 2.85 KB
/
errors.test.js
File metadata and controls
89 lines (76 loc) · 2.85 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
89
/*
Copyright 2019 Adobe Inc. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
const { stdout } = require('stdout-stderr')
const TheCommand = require('../../../../../../src/commands/app/config/get/log-forwarding/errors.js')
const rtLib = require('@adobe/aio-lib-runtime')
jest.mock('@adobe/aio-lib-runtime', () => ({
init: jest.fn(),
utils: {
checkOpenWhiskCredentials: jest.fn()
}
}))
let command, logForwarding
beforeEach(async () => {
command = new TheCommand([])
command.config = global.createOclifMockConfig()
command.appConfig = {
aio: {
runtime: {
namespace: 'fake_ns',
auth: 'fake:auth',
apihost: 'https://adobeioruntime.net',
apiversion: 'v1',
package: 'sample-app-1.0.0'
}
}
}
logForwarding = {
getErrors: jest.fn()
}
rtLib.init.mockResolvedValue({ logForwarding })
})
test('get log forwarding errors with errors', async () => {
const errors = ['Error 1', 'Error 2']
logForwarding.getErrors.mockResolvedValue({
errors,
configured_forwarder: 'test-destination'
})
await command.run()
expect(stdout.output).toContain('Log forwarding errors for the last configured destination \'test-destination\':')
expect(stdout.output).toContain('Error 1')
expect(stdout.output).toContain('Error 2')
})
test('get log forwarding errors without errors', async () => {
logForwarding.getErrors.mockResolvedValue({
errors: [],
configured_forwarder: 'test-destination'
})
await command.run()
expect(stdout.output).toContain('No log forwarding errors for the last configured destination \'test-destination\'')
})
test('get log forwarding errors without configured forwarder', async () => {
logForwarding.getErrors.mockResolvedValue({
errors: ['Error 1']
})
await command.run()
expect(stdout.output).toContain('Log forwarding errors:')
expect(stdout.output).toContain('Error 1')
})
test('failed to get log forwarding errors', async () => {
logForwarding.getErrors.mockRejectedValue(new Error('mocked error'))
await expect(command.run()).rejects.toThrow('mocked error')
})
test('command aliases are set correctly', () => {
expect(TheCommand.aliases).toEqual(['app:config:get:log-forwarding:errors', 'app:config:get:lf:errors'])
})
test('command description is set correctly', () => {
expect(TheCommand.description).toBe('Get log forwarding errors')
})