|
| 1 | +import { LEGACY_HELLO_COMMAND, MongoClient } from '../mongodb'; |
| 2 | + |
| 3 | +/** |
| 4 | + * ATLAS_CONNECTIVITY env variable is JSON |
| 5 | + * Here's some typescript describing the shape: |
| 6 | + * |
| 7 | + * ```typescript |
| 8 | + * interface AtlasConnectivity { |
| 9 | + * [atlasDeployment: string]: [normalUri: string, srvUri: string] |
| 10 | + * } |
| 11 | + * ``` |
| 12 | + * |
| 13 | + * It should be an object with descriptive strings about the deployment type and version (i.e. sharded_cluster_3_4) |
| 14 | + * that map to a two string tuple that are the normal URI and SRV URI, order doesn't matter, but it should be that order. |
| 15 | + */ |
| 16 | + |
| 17 | +describe('Atlas Connectivity', function () { |
| 18 | + const { ATLAS_CONNECTIVITY = '' } = process.env; |
| 19 | + if (ATLAS_CONNECTIVITY === '') throw new Error('ATLAS_CONNECTIVITY not defined in env'); |
| 20 | + |
| 21 | + const CONFIGS: Record<string, [normalUri: string, srvUri: string]> = |
| 22 | + JSON.parse(ATLAS_CONNECTIVITY); |
| 23 | + |
| 24 | + let client: MongoClient; |
| 25 | + |
| 26 | + afterEach(async function () { |
| 27 | + await client.close(); |
| 28 | + }); |
| 29 | + |
| 30 | + for (const configName of Object.keys(CONFIGS)) { |
| 31 | + context(configName, function () { |
| 32 | + for (const connectionString of CONFIGS[configName]) { |
| 33 | + const name = connectionString.includes('mongodb+srv') ? 'mongodb+srv' : 'normal'; |
| 34 | + |
| 35 | + beforeEach(function () { |
| 36 | + if (configName === 'replica_set_4_4_free') { |
| 37 | + const today = new Date(); |
| 38 | + // Making this April 1st so it is a monday |
| 39 | + const april1st2024 = new Date('2024-04-01'); |
| 40 | + if (today < april1st2024) { |
| 41 | + if (this.currentTest) |
| 42 | + this.currentTest.skipReason = |
| 43 | + 'TODO(NODE-6027): Un-skip replica_set_4_4_free after March 29th 2024'; |
| 44 | + this.skip(); |
| 45 | + } |
| 46 | + } |
| 47 | + }); |
| 48 | + |
| 49 | + it(name, async function () { |
| 50 | + this.timeout(40000); |
| 51 | + |
| 52 | + client = new MongoClient(connectionString); |
| 53 | + |
| 54 | + await client.connect(); |
| 55 | + await client.db('admin').command({ [LEGACY_HELLO_COMMAND]: 1 }); |
| 56 | + await client.db('test').collection('test').findOne({}); |
| 57 | + }); |
| 58 | + } |
| 59 | + }); |
| 60 | + } |
| 61 | +}); |
0 commit comments