@@ -18,8 +18,9 @@ func TestFindConfigFileFromConnectionParameters(t *testing.T) {
18
18
createFile (t , defaultConfigName , "random content" , dirs .predefinedDir1 )
19
19
createFile (t , defaultConfigName , "random content" , dirs .predefinedDir2 )
20
20
21
- clientConfigFilePath := findClientConfigFilePath (connParameterConfigPath , predefinedTestDirs (dirs ))
21
+ clientConfigFilePath , err := findClientConfigFilePath (connParameterConfigPath , predefinedTestDirs (dirs ))
22
22
23
+ assertEqualE (t , err , nil )
23
24
assertEqualE (t , clientConfigFilePath , connParameterConfigPath , "config file path" )
24
25
}
25
26
@@ -30,8 +31,9 @@ func TestFindConfigFileFromEnvVariable(t *testing.T) {
30
31
createFile (t , defaultConfigName , "random content" , dirs .predefinedDir1 )
31
32
createFile (t , defaultConfigName , "random content" , dirs .predefinedDir2 )
32
33
33
- clientConfigFilePath := findClientConfigFilePath ("" , predefinedTestDirs (dirs ))
34
+ clientConfigFilePath , err := findClientConfigFilePath ("" , predefinedTestDirs (dirs ))
34
35
36
+ assertEqualE (t , err , nil )
35
37
assertEqualE (t , clientConfigFilePath , envConfigPath , "config file path" )
36
38
}
37
39
@@ -40,8 +42,9 @@ func TestFindConfigFileFromFirstPredefinedDir(t *testing.T) {
40
42
configPath := createFile (t , defaultConfigName , "random content" , dirs .predefinedDir1 )
41
43
createFile (t , defaultConfigName , "random content" , dirs .predefinedDir2 )
42
44
43
- clientConfigFilePath := findClientConfigFilePath ("" , predefinedTestDirs (dirs ))
45
+ clientConfigFilePath , err := findClientConfigFilePath ("" , predefinedTestDirs (dirs ))
44
46
47
+ assertEqualE (t , err , nil )
45
48
assertEqualE (t , clientConfigFilePath , configPath , "config file path" )
46
49
}
47
50
@@ -50,8 +53,9 @@ func TestFindConfigFileFromSubsequentDirectoryIfNotFoundInPreviousOne(t *testing
50
53
createFile (t , "wrong_file_name.json" , "random content" , dirs .predefinedDir1 )
51
54
configPath := createFile (t , defaultConfigName , "random content" , dirs .predefinedDir2 )
52
55
53
- clientConfigFilePath := findClientConfigFilePath ("" , predefinedTestDirs (dirs ))
56
+ clientConfigFilePath , err := findClientConfigFilePath ("" , predefinedTestDirs (dirs ))
54
57
58
+ assertEqualE (t , err , nil )
55
59
assertEqualE (t , clientConfigFilePath , configPath , "config file path" )
56
60
}
57
61
@@ -60,8 +64,9 @@ func TestNotFindConfigFileWhenNotDefined(t *testing.T) {
60
64
createFile (t , "wrong_file_name.json" , "random content" , dirs .predefinedDir1 )
61
65
createFile (t , "wrong_file_name.json" , "random content" , dirs .predefinedDir2 )
62
66
63
- clientConfigFilePath := findClientConfigFilePath ("" , predefinedTestDirs (dirs ))
67
+ clientConfigFilePath , err := findClientConfigFilePath ("" , predefinedTestDirs (dirs ))
64
68
69
+ assertEqualE (t , err , nil )
65
70
assertEqualE (t , clientConfigFilePath , "" , "config file path" )
66
71
}
67
72
@@ -71,10 +76,9 @@ func TestCreatePredefinedDirs(t *testing.T) {
71
76
72
77
locations := clientConfigPredefinedDirs ()
73
78
74
- assertEqualF (t , len (locations ), 3 , "size" )
79
+ assertEqualF (t , len (locations ), 2 , "size" )
75
80
assertEqualE (t , locations [0 ], "." , "driver directory" )
76
81
assertEqualE (t , locations [1 ], homeDir , "home directory" )
77
- assertEqualE (t , locations [2 ], os .TempDir (), "temp directory" )
78
82
}
79
83
80
84
func TestGetClientConfig (t * testing.T ) {
@@ -84,7 +88,7 @@ func TestGetClientConfig(t *testing.T) {
84
88
createFile (t , fileName , configContents , dir )
85
89
filePath := path .Join (dir , fileName )
86
90
87
- clientConfigFilePath , err := getClientConfig (filePath )
91
+ clientConfigFilePath , _ , err := getClientConfig (filePath )
88
92
89
93
assertNilF (t , err )
90
94
assertNotNilF (t , clientConfigFilePath )
@@ -93,7 +97,7 @@ func TestGetClientConfig(t *testing.T) {
93
97
}
94
98
95
99
func TestNoResultForGetClientConfigWhenNoFileFound (t * testing.T ) {
96
- clientConfigFilePath , err := getClientConfig ("" )
100
+ clientConfigFilePath , _ , err := getClientConfig ("" )
97
101
98
102
assertNilF (t , err )
99
103
assertNilF (t , clientConfigFilePath )
@@ -223,6 +227,76 @@ func TestParseConfigurationFails(t *testing.T) {
223
227
}
224
228
}
225
229
230
+ func TestUnknownValues (t * testing.T ) {
231
+ testCases := []struct {
232
+ testName string
233
+ inputString string
234
+ expectedOutput map [string ]string
235
+ }{
236
+ {
237
+ testName : "EmptyCommon" ,
238
+ inputString : `{
239
+ "common": {}
240
+ }` ,
241
+ expectedOutput : map [string ]string {},
242
+ },
243
+ {
244
+ testName : "CommonMissing" ,
245
+ inputString : `{
246
+ }` ,
247
+ expectedOutput : map [string ]string {},
248
+ },
249
+ {
250
+ testName : "UnknownProperty" ,
251
+ inputString : `{
252
+ "common": {
253
+ "unknown_key": "unknown_value"
254
+ }
255
+ }` ,
256
+ expectedOutput : map [string ]string {
257
+ "unknown_key" : "unknown_value" ,
258
+ },
259
+ },
260
+ {
261
+ testName : "KnownAndUnknownProperty" ,
262
+ inputString : `{
263
+ "common": {
264
+ "lOg_level": "level",
265
+ "log_PATH": "path",
266
+ "unknown_key": "unknown_value"
267
+ }
268
+ }` ,
269
+ expectedOutput : map [string ]string {
270
+ "unknown_key" : "unknown_value" ,
271
+ },
272
+ },
273
+ {
274
+ testName : "KnownProperties" ,
275
+ inputString : `{
276
+ "common": {
277
+ "log_level": "level",
278
+ "log_path": "path"
279
+ }
280
+ }` ,
281
+ expectedOutput : map [string ]string {},
282
+ },
283
+
284
+ {
285
+ testName : "EmptyInput" ,
286
+ inputString : "" ,
287
+ expectedOutput : map [string ]string {},
288
+ },
289
+ }
290
+
291
+ for _ , tc := range testCases {
292
+ t .Run (tc .testName , func (t * testing.T ) {
293
+ inputBytes := []byte (tc .inputString )
294
+ result := getUnknownValues (inputBytes )
295
+ assertEqualE (t , fmt .Sprint (result ), fmt .Sprint (tc .expectedOutput ))
296
+ })
297
+ }
298
+ }
299
+
226
300
func createFile (t * testing.T , fileName string , fileContents string , directory string ) string {
227
301
fullFileName := path .Join (directory , fileName )
228
302
err := os .WriteFile (fullFileName , []byte (fileContents ), 0644 )
@@ -237,10 +311,10 @@ func createTestDirectories(t *testing.T) struct {
237
311
} {
238
312
dir := t .TempDir ()
239
313
predefinedDir1 := path .Join (dir , "dir1" )
240
- err := os .Mkdir (predefinedDir1 , 0755 )
314
+ err := os .Mkdir (predefinedDir1 , 0700 )
241
315
assertNilF (t , err , "predefined dir1 error" )
242
316
predefinedDir2 := path .Join (dir , "dir2" )
243
- err = os .Mkdir (predefinedDir2 , 0755 )
317
+ err = os .Mkdir (predefinedDir2 , 0700 )
244
318
assertNilF (t , err , "predefined dir2 error" )
245
319
return struct {
246
320
dir string
0 commit comments