-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsetup-environment.js
More file actions
170 lines (141 loc) · 4.36 KB
/
Copy pathsetup-environment.js
File metadata and controls
170 lines (141 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
const test = require('tape-await')
const { makeEnvironment, resolveConfiguration } = require('../src/common.js')
const defaults = require('../src/defaults.js')
const cache = (obj) => ({
read: () => JSON.stringify(obj),
write: () => {},
})
test('build runtime environment based on defaults', async function (t) {
t.plan(1)
const argv = {
name: '2.39.0',
getCache: () => cache(null),
}
const cfg = await resolveConfiguration(argv)
const actual = makeEnvironment(cfg)
const expected = {
DHIS2_HOME: '/opt/dhis2',
DHIS2_CORE_NAME: '2.39.0',
DHIS2_CORE_CONTEXT_PATH: '',
DHIS2_CORE_IMAGE: 'dhis2/core:2.39.0',
DHIS2_CORE_VERSION: '2.39.0',
DHIS2_CORE_DB_VERSION: '2.39.0',
DHIS2_CORE_PORT: defaults.port,
}
t.deepEqual(actual, expected, 'default environment')
})
test('build runtime environment based on args', async function (t) {
t.plan(1)
const argv = {
name: 'dev',
customContext: true,
dhis2Version: '2.33',
dbVersion: '2.32',
channel: 'canary',
variant: 'jetty-slackware',
port: 8233,
getCache: () => cache(null),
}
const cfg = await resolveConfiguration(argv)
const actual = makeEnvironment(cfg)
const expected = {
DHIS2_HOME: '/DHIS2_home',
DHIS2_CORE_NAME: 'dev',
DHIS2_CORE_CONTEXT_PATH: '/dev',
DHIS2_CORE_IMAGE: 'dhis2/core-canary:2.33-jetty-slackware',
DHIS2_CORE_VERSION: '2.33',
DHIS2_CORE_DB_VERSION: '2.32',
DHIS2_CORE_PORT: 8233,
}
t.deepEqual(actual, expected, 'args environment')
})
test('build runtime environment based on mixed args and config', async function (t) {
t.plan(1)
const config = {
dhis2Version: 'master',
port: 8233,
channel: 'dev',
dbVersion: 'dev',
}
const argv = {
name: 'mydev',
customContext: true,
cluster: config,
getCache: () => cache(null),
}
const cfg = await resolveConfiguration(argv)
const actual = makeEnvironment(cfg)
const expected = {
DHIS2_HOME: '/opt/dhis2',
DHIS2_CORE_NAME: 'mydev',
DHIS2_CORE_CONTEXT_PATH: '/mydev',
DHIS2_CORE_IMAGE: 'dhis2/core-dev:latest',
DHIS2_CORE_VERSION: 'master',
DHIS2_CORE_DB_VERSION: 'dev',
DHIS2_CORE_PORT: 8233,
}
t.deepEqual(actual, expected, 'args and config environment')
})
test('build runtime environment based on mixed args, cache, config and defaults', async function (t) {
t.plan(1)
const config = {
port: 8233,
dhis2Version: 'master',
}
const argv = {
name: 'mydev',
cluster: config,
getCache: () =>
cache({
customContext: true,
image: 'dhis2/core-canary:master-20190523',
}),
}
const cfg = await resolveConfiguration(argv)
const actual = makeEnvironment(cfg)
const expected = {
DHIS2_HOME: '/opt/dhis2',
DHIS2_CORE_NAME: 'mydev',
DHIS2_CORE_CONTEXT_PATH: '/mydev',
DHIS2_CORE_IMAGE: 'dhis2/core-canary:master-20190523',
DHIS2_CORE_VERSION: 'master',
DHIS2_CORE_DB_VERSION: 'dev',
DHIS2_CORE_PORT: 8233,
}
t.deepEqual(actual, expected, 'merged environment')
})
test('build runtime environment based on mixed args, cache, config, custom per-cluster config and defaults', async function (t) {
t.plan(1)
const config = {
port: 8233,
dhis2Version: 'master',
dbVersion: 'dev',
clusters: {
2330: {
port: 9999,
dhis2Version: '2.38.2',
},
},
}
const argv = {
name: '2330',
cluster: config,
getCache: () =>
cache({
customContext: true,
image: 'dhis2/core-canary:master-20190523',
}),
}
const cfg = await resolveConfiguration(argv)
const actual = makeEnvironment(cfg)
const expected = {
DHIS2_HOME: '/opt/dhis2',
DHIS2_CORE_NAME: '2330',
DHIS2_CORE_CONTEXT_PATH: '/2330',
DHIS2_CORE_IMAGE: 'dhis2/core-canary:master-20190523',
DHIS2_CORE_VERSION: '2.38.2',
DHIS2_CORE_DB_VERSION: 'dev',
DHIS2_CORE_PORT: 9999,
}
t.deepEqual(actual, expected, 'merged environment')
})