|
4 | 4 | } from './mocks'; |
5 | 5 | import { |
6 | 6 | isDirectConnectionString, |
| 7 | + isLocalhostConnectionString, |
7 | 8 | isPooledConnectionString, |
8 | 9 | postgresConnectionString, |
9 | 10 | } from './postgres-connection-string'; |
@@ -79,3 +80,31 @@ describe('isPooledConnectionString', () => { |
79 | 80 | ); |
80 | 81 | }); |
81 | 82 | }); |
| 83 | + |
| 84 | +describe('isLocalhostConnectionString', () => { |
| 85 | + it.each(['localhost', 'http', 'foobar', 'blah'])( |
| 86 | + 'returns false for invalid connection strings: %s', |
| 87 | + (connectionString) => { |
| 88 | + expect(isLocalhostConnectionString(connectionString)).toEqual(false); |
| 89 | + }, |
| 90 | + ); |
| 91 | + it.each([ |
| 92 | + 'postgresql://localhost', |
| 93 | + 'postgresql://localhost:5432', |
| 94 | + 'postgresql://localhost/mydb', |
| 95 | + 'postgresql://user@localhost', |
| 96 | + 'postgresql://user:secret@localhost', |
| 97 | + 'postgresql://other@localhost/otherdb?connect_timeout=10&application_name=myapp', |
| 98 | + 'postgresql://localhost/mydb?user=other&password=secret', |
| 99 | + ])( |
| 100 | + 'returns true for a valid localhost connection string', |
| 101 | + (connectionString) => { |
| 102 | + expect(isLocalhostConnectionString(connectionString)).toEqual(true); |
| 103 | + }, |
| 104 | + ); |
| 105 | + it('returns false for a valid non-localhost connection string', () => { |
| 106 | + expect( |
| 107 | + isLocalhostConnectionString(MOCKED_POOLED_CONNECTION_STRING), |
| 108 | + ).toEqual(false); |
| 109 | + }); |
| 110 | +}); |
0 commit comments