|
2 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this
|
3 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
4 | 4 | // @flow
|
| 5 | + |
| 6 | +import fs from 'fs'; |
5 | 7 | import { config, loadConfigForTestsOnly as loadConfig } from '../../src/config';
|
6 | 8 |
|
7 | 9 | describe('config.js', () => {
|
@@ -35,4 +37,34 @@ describe('config.js', () => {
|
35 | 37 | expect(() => loadConfig()).toThrow();
|
36 | 38 | process.env.NODE_ENV = 'test';
|
37 | 39 | });
|
| 40 | + |
| 41 | + it('accepts mocked google authentication paths', () => { |
| 42 | + process.env.GCS_AUTHENTICATION_PATH = 'MOCKED'; |
| 43 | + expect(loadConfig().googleAuthenticationFilePath).toEqual('MOCKED'); |
| 44 | + delete process.env.GCS_AUTHENTICATION_PATH; |
| 45 | + }); |
| 46 | + |
| 47 | + it('accepts valid google authentication paths', () => { |
| 48 | + const filePath = '/path/to/file'; |
| 49 | + jest.spyOn(fs, 'accessSync').mockReturnValue(); |
| 50 | + process.env.GCS_AUTHENTICATION_PATH = filePath; |
| 51 | + expect(loadConfig().googleAuthenticationFilePath).toEqual(filePath); |
| 52 | + delete process.env.GCS_AUTHENTICATION_PATH; |
| 53 | + }); |
| 54 | + |
| 55 | + it('rejects google authentication paths that are not readable', () => { |
| 56 | + const filePath = '/path/to/file'; |
| 57 | + jest.spyOn(process.stdout, 'write').mockImplementation(() => {}); |
| 58 | + jest.spyOn(fs, 'accessSync').mockImplementation(() => { |
| 59 | + throw new Error(); |
| 60 | + }); |
| 61 | + process.env.GCS_AUTHENTICATION_PATH = filePath; |
| 62 | + expect(() => loadConfig()).toThrow( |
| 63 | + 'The authentication file is missing or not readable.' |
| 64 | + ); |
| 65 | + expect(process.stdout.write).toHaveBeenCalledWith( |
| 66 | + expect.stringContaining('CRITICAL') |
| 67 | + ); |
| 68 | + delete process.env.GCS_AUTHENTICATION_PATH; |
| 69 | + }); |
38 | 70 | });
|
0 commit comments