1
- const chai = require ( 'chai' ) ;
2
- const fs = require ( 'fs' ) ;
3
- const path = require ( 'path' ) ;
4
- const { expect } = chai ;
5
- const ConfigLoader = require ( '../src/config/ConfigLoader' ) ;
6
- const { isValidGitUrl, isValidPath, isValidBranchName } = ConfigLoader ;
7
- const sinon = require ( 'sinon' ) ;
8
- const axios = require ( 'axios' ) ;
1
+ import fs from 'fs' ;
2
+ import path from 'path' ;
3
+ import { expect } from 'chai' ;
4
+ import { ConfigLoader , Configuration } from '../src/config/ConfigLoader' ;
5
+ import { isValidGitUrl , isValidPath , isValidBranchName } from '../src/config/ConfigLoader' ;
6
+ import sinon from 'sinon' ;
7
+ import axios from 'axios' ;
9
8
10
9
describe ( 'ConfigLoader' , ( ) => {
11
- let configLoader ;
12
- let tempDir ;
13
- let tempConfigFile ;
10
+ let configLoader : ConfigLoader ;
11
+ let tempDir : string ;
12
+ let tempConfigFile : string ;
14
13
15
14
beforeEach ( ( ) => {
16
15
// Create temp directory for test files
@@ -35,7 +34,11 @@ describe('ConfigLoader', () => {
35
34
fs . writeFileSync ( tempConfigFile , JSON . stringify ( testConfig ) ) ;
36
35
37
36
configLoader = new ConfigLoader ( { } ) ;
38
- const result = await configLoader . loadFromFile ( { path : tempConfigFile } ) ;
37
+ const result = await configLoader . loadFromFile ( {
38
+ type : 'file' ,
39
+ enabled : true ,
40
+ path : tempConfigFile ,
41
+ } ) ;
39
42
40
43
expect ( result ) . to . deep . equal ( testConfig ) ;
41
44
} ) ;
@@ -52,6 +55,8 @@ describe('ConfigLoader', () => {
52
55
53
56
configLoader = new ConfigLoader ( { } ) ;
54
57
const result = await configLoader . loadFromHttp ( {
58
+ type : 'http' ,
59
+ enabled : true ,
55
60
url : 'http://config-service/config' ,
56
61
headers : { } ,
57
62
} ) ;
@@ -64,6 +69,8 @@ describe('ConfigLoader', () => {
64
69
65
70
configLoader = new ConfigLoader ( { } ) ;
66
71
await configLoader . loadFromHttp ( {
72
+ type : 'http' ,
73
+ enabled : true ,
67
74
url : 'http://config-service/config' ,
68
75
auth : {
69
76
type : 'bearer' ,
@@ -81,7 +88,7 @@ describe('ConfigLoader', () => {
81
88
82
89
describe ( 'reloadConfiguration' , ( ) => {
83
90
it ( 'should emit configurationChanged event when config changes' , async ( ) => {
84
- const initialConfig = {
91
+ const initialConfig : Configuration = {
85
92
configurationSources : {
86
93
enabled : true ,
87
94
sources : [
@@ -91,6 +98,7 @@ describe('ConfigLoader', () => {
91
98
path : tempConfigFile ,
92
99
} ,
93
100
] ,
101
+ reloadIntervalSeconds : 0 ,
94
102
} ,
95
103
} ;
96
104
@@ -115,7 +123,7 @@ describe('ConfigLoader', () => {
115
123
proxyUrl : 'https://test.com' ,
116
124
} ;
117
125
118
- const config = {
126
+ const config : Configuration = {
119
127
configurationSources : {
120
128
enabled : true ,
121
129
sources : [
@@ -125,6 +133,7 @@ describe('ConfigLoader', () => {
125
133
path : tempConfigFile ,
126
134
} ,
127
135
] ,
136
+ reloadIntervalSeconds : 0 ,
128
137
} ,
129
138
} ;
130
139
@@ -169,15 +178,15 @@ describe('ConfigLoader', () => {
169
178
await configLoader . initialize ( ) ;
170
179
171
180
// Check if directory exists
172
- expect ( fs . existsSync ( configLoader . cacheDir ) ) . to . be . true ;
181
+ expect ( fs . existsSync ( configLoader . cacheDir ! ) ) . to . be . true ;
173
182
} ) ;
174
183
} ) ;
175
184
176
185
describe ( 'loadRemoteConfig' , ( ) => {
177
- let configLoader ;
186
+ let configLoader : ConfigLoader ;
178
187
beforeEach ( async ( ) => {
179
188
const configFilePath = path . join ( __dirname , '..' , 'proxy.config.json' ) ;
180
- const config = JSON . parse ( fs . readFileSync ( configFilePath ) ) ;
189
+ const config = JSON . parse ( fs . readFileSync ( configFilePath , 'utf-8' ) ) as Configuration ;
181
190
182
191
config . configurationSources . enabled = true ;
183
192
configLoader = new ConfigLoader ( config ) ;
@@ -189,10 +198,11 @@ describe('ConfigLoader', () => {
189
198
this . timeout ( 10000 ) ;
190
199
191
200
const source = {
192
- type : 'git' ,
201
+ type : 'git' as const ,
193
202
repository : 'https://github.com/finos/git-proxy.git' ,
194
203
path : 'proxy.config.json' ,
195
204
branch : 'main' ,
205
+ enabled : true ,
196
206
} ;
197
207
198
208
const config = await configLoader . loadFromGit ( source ) ;
@@ -205,10 +215,11 @@ describe('ConfigLoader', () => {
205
215
206
216
it ( 'should throw error for invalid configuration file path' , async function ( ) {
207
217
const source = {
208
- type : 'git' ,
218
+ type : 'git' as const ,
209
219
repository : 'https://github.com/finos/git-proxy.git' ,
210
220
path : '\0' , // Invalid path
211
221
branch : 'main' ,
222
+ enabled : true ,
212
223
} ;
213
224
214
225
try {
@@ -224,8 +235,9 @@ describe('ConfigLoader', () => {
224
235
this . timeout ( 10000 ) ;
225
236
226
237
const source = {
227
- type : 'http' ,
238
+ type : 'http' as const ,
228
239
url : 'https://raw.githubusercontent.com/finos/git-proxy/refs/heads/main/proxy.config.json' ,
240
+ enabled : true ,
229
241
} ;
230
242
231
243
const config = await configLoader . loadFromHttp ( source ) ;
@@ -238,7 +250,7 @@ describe('ConfigLoader', () => {
238
250
} ) ;
239
251
240
252
describe ( 'deepMerge' , ( ) => {
241
- let configLoader ;
253
+ let configLoader : ConfigLoader ;
242
254
243
255
beforeEach ( ( ) => {
244
256
configLoader = new ConfigLoader ( { } ) ;
@@ -401,7 +413,7 @@ describe('Validation Helpers', () => {
401
413
expect ( isValidBranchName ( 'fix_123' ) ) . to . be . true ;
402
414
expect ( isValidBranchName ( 'user/feature/branch' ) ) . to . be . true ;
403
415
404
- // // Invalid branch names
416
+ // Invalid branch names
405
417
expect ( isValidBranchName ( '.invalid' ) ) . to . be . false ;
406
418
expect ( isValidBranchName ( '-invalid' ) ) . to . be . false ;
407
419
expect ( isValidBranchName ( 'branch with spaces' ) ) . to . be . false ;
0 commit comments