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('getServiceNames', function () {
|
10 | const assert = chai.assert;
|
11 | const getServiceNamesPath = resolve(__dirname, '../js/getServiceNames.js');
|
12 | const projectDir = resolve(__dirname, 'fixtures/project-a');
|
13 |
|
14 | async function getServiceNames(args = [], dcFile, expected) {
|
15 | const { stdout, stderr } = await execFile(getServiceNamesPath, args, {
|
16 | cwd: projectDir,
|
17 | env: { ...process.env, COMPOSE_FILE: dcFile }
|
18 | });
|
19 | if (stderr) {
|
20 | console.error(' - stdout:', stdout);
|
21 | throw new Error(stderr);
|
22 | }
|
23 | assert.deepEqual(stdout.trim().split(' ').filter(n => n.length).sort(), expected.sort());
|
24 | }
|
25 |
|
26 | describe('get all service names:', function () {
|
27 | const prodNames = ['back-a', 'back-b', 'back-c', 'ext-a', 'front-a', 'front-b', 'store-a'];
|
28 | const testNames = ['test-back-a', 'test-back-b', 'test-store-a'];
|
29 |
|
30 | it('COMPOSE_FILE = dc.prod.yml', async () => {
|
31 | await getServiceNames([], 'dc.prod.yml', prodNames);
|
32 | });
|
33 |
|
34 | it('COMPOSE_FILE = dc.test.yml', async () => {
|
35 | await getServiceNames([], 'dc.test.yml', testNames);
|
36 | });
|
37 |
|
38 | it('--composefile = dc.prod.yml', async () => {
|
39 | await getServiceNames(['--composefile', 'dc.prod.yml'], undefined, prodNames);
|
40 | });
|
41 |
|
42 | it('--composefile = dc.test.yml', async () => {
|
43 | await getServiceNames(['--composefile', 'dc.test.yml'], undefined, testNames);
|
44 | });
|
45 |
|
46 | });
|
47 |
|
48 | describe('get front service names:', function () {
|
49 | const prodNames = ['front-a', 'front-b'];
|
50 | const testNames = [];
|
51 |
|
52 | it('COMPOSE_FILE = dc.prod.yml', async () => {
|
53 | await getServiceNames(['--front'], 'dc.prod.yml', prodNames);
|
54 | });
|
55 |
|
56 | it('COMPOSE_FILE = dc.test.yml', async () => {
|
57 | await getServiceNames(['--front'], 'dc.test.yml', testNames);
|
58 | });
|
59 |
|
60 | it('--composefile = dc.prod.yml', async () => {
|
61 | await getServiceNames(['--front', '--composefile', 'dc.prod.yml'], undefined, prodNames);
|
62 | });
|
63 |
|
64 | it('--composefile = dc.test.yml', async () => {
|
65 | await getServiceNames(['--front', '--composefile', 'dc.test.yml'], undefined, testNames);
|
66 | });
|
67 |
|
68 | });
|
69 |
|
70 | describe('get testable service names:', function () {
|
71 | const prodNames = ['back-a', 'back-b'];
|
72 | const testNames = ['back-a', 'back-b'];
|
73 |
|
74 | it('COMPOSE_FILE = dc.prod.yml', async () => {
|
75 | await getServiceNames(['--testable'], 'dc.prod.yml', prodNames);
|
76 | });
|
77 |
|
78 | it('COMPOSE_FILE = dc.test.yml', async () => {
|
79 | await getServiceNames(['--testable'], 'dc.test.yml', testNames);
|
80 | });
|
81 |
|
82 | it('--composefile = dc.prod.yml', async () => {
|
83 | await getServiceNames(['--testable', '--composefile', 'dc.prod.yml'], undefined, prodNames);
|
84 | });
|
85 |
|
86 | it('--composefile = dc.test.yml', async () => {
|
87 | await getServiceNames(['--testable', '--composefile', 'dc.test.yml'], undefined, testNames);
|
88 | });
|
89 |
|
90 | });
|
91 |
|
92 | describe('get all watchable service names:', function () {
|
93 | const prodNames = ['back-a', 'back-c', 'front-a'];
|
94 | const testNames = ['back-a', 'back-b'];
|
95 |
|
96 | it('COMPOSE_FILE = dc.prod.yml', async () => {
|
97 | await getServiceNames(['--watchable'], 'dc.prod.yml', prodNames);
|
98 | });
|
99 |
|
100 | });
|
101 |
|
102 | describe('get test (and dependent) service names for:', function () {
|
103 |
|
104 | it('back-a in dc.prod.yml', async () => {
|
105 | await getServiceNames(['--test', 'back-a'], 'dc.prod.yml', [
|
106 | 'test-back-a',
|
107 | 'test-store-a'
|
108 | ]);
|
109 | });
|
110 |
|
111 | it('back-b in dc.prod.yml', async () => {
|
112 | await getServiceNames(['--test', 'back-b'], 'dc.prod.yml', [
|
113 | 'test-back-b'
|
114 | ]);
|
115 | });
|
116 |
|
117 | it('back-a in dc.test.yml', async () => {
|
118 | await getServiceNames(['--test', 'back-a'], 'dc.test.yml', [
|
119 | 'test-back-a',
|
120 | 'test-store-a'
|
121 | ]);
|
122 | });
|
123 |
|
124 | it('back-b in dc.test.yml', async () => {
|
125 | await getServiceNames(['--test', 'back-b'], 'dc.test.yml', [
|
126 | 'test-back-b'
|
127 | ]);
|
128 | });
|
129 |
|
130 | });
|
131 |
|
132 | });
|