1 | 'use strict';
|
2 |
|
3 | const { resolve } = require('path');
|
4 |
|
5 | const chai = require('chai');
|
6 |
|
7 | const { execFile } = require('../js/utils');
|
8 |
|
9 | describe('getNetworkNames', function () {
|
10 | const assert = chai.assert;
|
11 | const getNetworkNamesPath = resolve(__dirname, '../js/getNetworkNames.js');
|
12 | const projectDir = resolve(__dirname, 'fixtures/project-a');
|
13 |
|
14 | async function getNetworkNames(args = [], dcFile, expected) {
|
15 | const { stdout, stderr } = await execFile(getNetworkNamesPath, args, {
|
16 | cwd: projectDir,
|
17 | env: {
|
18 | ...process.env,
|
19 | COMPOSE_FILE: dcFile,
|
20 | COMPOSE_PROJECT_NAME: 'dctools'
|
21 | }
|
22 | });
|
23 | if (stderr) {
|
24 | console.error(' - stdout:', stdout);
|
25 | throw new Error(stderr);
|
26 | }
|
27 | assert.deepEqual(stdout.trim().split(' ').filter(n => n.length).sort(), expected.sort());
|
28 | }
|
29 |
|
30 | it('get network names from COMPOSE_FILE = dc.prod.yml', async () => {
|
31 | await getNetworkNames([], 'dc.prod.yml', [
|
32 | 'network-a',
|
33 | 'network-b'
|
34 | ]);
|
35 | });
|
36 |
|
37 | it('get network names from --composefile = dc.prod.yml', async () => {
|
38 | await getNetworkNames(['--composefile', 'dc.prod.yml'], undefined, [
|
39 | 'network-a',
|
40 | 'network-b'
|
41 | ]);
|
42 | });
|
43 |
|
44 | it('get network names from --composefile = dc.test.yml', async () => {
|
45 | await getNetworkNames(['--composefile', 'dc.test.yml'], undefined, [
|
46 | 'default'
|
47 | ]);
|
48 | });
|
49 |
|
50 | it('get prepended network names from COMPOSE_FILE = dc.prod.yml', async () => {
|
51 | await getNetworkNames(['--prepend'], 'dc.prod.yml', [
|
52 | 'dctools_network-a',
|
53 | 'dctools_network-b'
|
54 | ]);
|
55 | });
|
56 |
|
57 | });
|