@@ -9,6 +9,8 @@ const postgres = require('../chronos_npm_package/controllers/postgres.js');
9
9
jest . mock ( '../chronos_npm_package/controllers/utilities.js' , ( ) => ( {
10
10
validateInput : jest . fn ( config => config ) ,
11
11
addNotifications : jest . fn ( config => config ) ,
12
+ testMetricsQuery : jest . fn ( config => config ) ,
13
+ getMetricsURI : jest . fn ( config => config ) ,
12
14
} ) ) ;
13
15
14
16
// mock propogate from Chronos
@@ -21,6 +23,7 @@ jest.mock('../chronos_npm_package/controllers/mongo.js', () => ({
21
23
docker : jest . fn ( config => config ) ,
22
24
health : jest . fn ( config => config ) ,
23
25
communications : jest . fn ( config => config ) ,
26
+ serverQuery : jest . fn ( config => config ) ,
24
27
} ) ) ;
25
28
26
29
jest . mock ( '../chronos_npm_package/controllers/postgres.js' , ( ) => ( {
@@ -29,6 +32,7 @@ jest.mock('../chronos_npm_package/controllers/postgres.js', () => ({
29
32
docker : jest . fn ( config => config ) ,
30
33
health : jest . fn ( config => config ) ,
31
34
communications : jest . fn ( config => config ) ,
35
+ serverQuery : jest . fn ( config => config ) ,
32
36
} ) ) ;
33
37
34
38
describe ( 'Chronos Config' , ( ) => {
@@ -139,4 +143,63 @@ describe('Chronos Config', () => {
139
143
}
140
144
} ) ;
141
145
} ) ;
146
+ describe ( 'kafka' , ( ) => {
147
+ test ( 'should check if kafka is functional' , async ( ) => {
148
+ const config = {
149
+ microservice : 'test' ,
150
+ interval : 300 ,
151
+ mode : 'micro' ,
152
+ dockerized : true ,
153
+ database : {
154
+ connection : 'REST' ,
155
+ type : 'MongoDB' ,
156
+ URI : process . env . CHRONOS_URI ,
157
+ } ,
158
+ notifications : [ ] ,
159
+ } ;
160
+ const { database, dockerized } = config ;
161
+ const falseDock = { dockerized : false } ;
162
+ const chronos = new Chronos ( config ) ;
163
+ chronos . kafka ( ) ;
164
+ await helpers . testMetricsQuery ( config ) ;
165
+ if ( database . type === 'MongoDB' ) {
166
+ expect ( mongo . connect ) . toHaveBeenCalledWith ( config ) ;
167
+ expect ( mongo . serverQuery ) . toHaveBeenCalledWith ( config ) ;
168
+ }
169
+ if ( database . type === 'PostgreSQL' ) {
170
+ expect ( postgres . connect ) . toHaveBeenCalledWith ( config ) ;
171
+ expect ( postgres . serverQuery ) . toHaveBeenCalledWith ( config ) ;
172
+ }
173
+ } ) ;
174
+ } ) ;
175
+
176
+ describe ( 'kubernetes' , ( ) => {
177
+ test ( 'should check if kubernetes is functional' , async ( ) => {
178
+ const config = {
179
+ microservice : 'test' ,
180
+ interval : 300 ,
181
+ mode : 'micro' ,
182
+ dockerized : true ,
183
+ database : {
184
+ connection : 'REST' ,
185
+ type : 'MongoDB' ,
186
+ URI : process . env . CHRONOS_URI ,
187
+ } ,
188
+ notifications : [ ] ,
189
+ } ;
190
+ const { database, dockerized } = config ;
191
+ const falseDock = { dockerized : false } ;
192
+ const chronos = new Chronos ( config ) ;
193
+ chronos . kubernetes ( ) ;
194
+ await helpers . testMetricsQuery ( config ) ;
195
+ if ( database . type === 'MongoDB' ) {
196
+ expect ( mongo . connect ) . toHaveBeenCalledWith ( config ) ;
197
+ expect ( mongo . serverQuery ) . toHaveBeenCalledWith ( config ) ;
198
+ }
199
+ if ( database . type === 'PostgreSQL' ) {
200
+ expect ( postgres . connect ) . toHaveBeenCalledWith ( config ) ;
201
+ expect ( postgres . serverQuery ) . toHaveBeenCalledWith ( config ) ;
202
+ }
203
+ } ) ;
204
+ } ) ;
142
205
} ) ;
0 commit comments