@@ -1170,12 +1170,14 @@ func makeEventLogger() record.EventRecorder {
1170
1170
func TestOpenTracingConfiguration (t * testing.T ) {
1171
1171
t .Parallel ()
1172
1172
tests := []struct {
1173
- configMap * v1.ConfigMap
1174
- enabled bool
1175
- loadModule bool
1176
- tracer string
1177
- tracerConfig string
1178
- msg string
1173
+ configMap * v1.ConfigMap
1174
+ isPlus bool
1175
+ expectedOpenTracingEnabled bool
1176
+ expectedLoadModule bool
1177
+ expectedTracer string
1178
+ expectedTracerConfig string
1179
+ expectedConfigOk bool
1180
+ msg string
1179
1181
}{
1180
1182
{
1181
1183
configMap : & v1.ConfigMap {
@@ -1185,11 +1187,42 @@ func TestOpenTracingConfiguration(t *testing.T) {
1185
1187
"opentracing-tracer-config" : "/etc/nginx/opentracing.json" ,
1186
1188
},
1187
1189
},
1188
- enabled : true ,
1189
- loadModule : true ,
1190
- tracer : "/usr/local/lib/libjaegertracing.so" ,
1191
- tracerConfig : "/etc/nginx/opentracing.json" ,
1192
- msg : "opentracing enabled" ,
1190
+ isPlus : false ,
1191
+ expectedOpenTracingEnabled : true ,
1192
+ expectedLoadModule : true ,
1193
+ expectedTracer : "/usr/local/lib/libjaegertracing.so" ,
1194
+ expectedTracerConfig : "/etc/nginx/opentracing.json" ,
1195
+ expectedConfigOk : true ,
1196
+ msg : "oss: opentracing enabled (valid)" ,
1197
+ },
1198
+ {
1199
+ configMap : & v1.ConfigMap {
1200
+ Data : map [string ]string {
1201
+ "opentracing" : "true" ,
1202
+ "opentracing-tracer" : "/usr/local/lib/libjaegertracing.so" ,
1203
+ },
1204
+ },
1205
+ isPlus : false ,
1206
+ expectedOpenTracingEnabled : false ,
1207
+ expectedLoadModule : false ,
1208
+ expectedTracer : "/usr/local/lib/libjaegertracing.so" ,
1209
+ expectedTracerConfig : "" ,
1210
+ expectedConfigOk : false ,
1211
+ msg : "oss: opentracing enabled, tracer-config not set (invalid)" ,
1212
+ },
1213
+ {
1214
+ configMap : & v1.ConfigMap {
1215
+ Data : map [string ]string {
1216
+ "opentracing" : "true" ,
1217
+ },
1218
+ },
1219
+ isPlus : false ,
1220
+ expectedOpenTracingEnabled : false ,
1221
+ expectedLoadModule : false ,
1222
+ expectedTracer : "" ,
1223
+ expectedTracerConfig : "" ,
1224
+ expectedConfigOk : false ,
1225
+ msg : "oss: opentracing enabled, tracer and tracer-config not set (invalid)" ,
1193
1226
},
1194
1227
{
1195
1228
configMap : & v1.ConfigMap {
@@ -1199,56 +1232,132 @@ func TestOpenTracingConfiguration(t *testing.T) {
1199
1232
"opentracing-tracer-config" : "/etc/nginx/opentracing.json" ,
1200
1233
},
1201
1234
},
1202
- enabled : false ,
1203
- loadModule : false ,
1204
- tracer : "" ,
1205
- tracerConfig : "" ,
1206
- msg : "opentracing disabled" ,
1235
+ isPlus : false ,
1236
+ expectedOpenTracingEnabled : false ,
1237
+ expectedLoadModule : false ,
1238
+ expectedTracer : "" ,
1239
+ expectedTracerConfig : "" ,
1240
+ expectedConfigOk : true ,
1241
+ msg : "oss: opentracing disabled, tracer and tracer-config set (valid)" ,
1207
1242
},
1208
1243
{
1209
1244
configMap : & v1.ConfigMap {
1210
1245
Data : map [string ]string {
1211
1246
"opentracing" : "false" ,
1212
1247
},
1213
1248
},
1214
- enabled : false ,
1215
- loadModule : false ,
1216
- tracer : "" ,
1217
- tracerConfig : "" ,
1218
- msg : "opentracing disabled" ,
1249
+ isPlus : false ,
1250
+ expectedOpenTracingEnabled : false ,
1251
+ expectedLoadModule : false ,
1252
+ expectedTracer : "" ,
1253
+ expectedTracerConfig : "" ,
1254
+ expectedConfigOk : true ,
1255
+ msg : "oss: opentracing disabled (valid)" ,
1256
+ },
1257
+ {
1258
+ configMap : & v1.ConfigMap {
1259
+ Data : map [string ]string {
1260
+ "opentracing" : "false" ,
1261
+ },
1262
+ },
1263
+ isPlus : true ,
1264
+ expectedOpenTracingEnabled : false ,
1265
+ expectedLoadModule : false ,
1266
+ expectedTracer : "" ,
1267
+ expectedTracerConfig : "" ,
1268
+ expectedConfigOk : true ,
1269
+ msg : "plus: opentracing explicitly disabled (valid)" ,
1270
+ },
1271
+ {
1272
+ configMap : & v1.ConfigMap{
1273
+ Data : map [string ]string {},
1274
+ },
1275
+ isPlus : true ,
1276
+ expectedOpenTracingEnabled : false ,
1277
+ expectedLoadModule : false ,
1278
+ expectedTracer : "" ,
1279
+ expectedTracerConfig : "" ,
1280
+ expectedConfigOk : true ,
1281
+ msg : "plus: no opentracing keys set (valid)" ,
1282
+ },
1283
+ {
1284
+ configMap : & v1.ConfigMap {
1285
+ Data : map [string ]string {
1286
+ "opentracing" : "false" ,
1287
+ "opentracing-tracer" : "/usr/local/lib/libjaegertracing.so" ,
1288
+ "opentracing-tracer-config" : "/etc/nginx/opentracing.json" ,
1289
+ },
1290
+ },
1291
+ isPlus : true ,
1292
+ expectedOpenTracingEnabled : false ,
1293
+ expectedLoadModule : false ,
1294
+ expectedTracer : "" ,
1295
+ expectedTracerConfig : "" ,
1296
+ expectedConfigOk : true ,
1297
+ msg : "plus: opentracing disabled, tracer and tracer-config set (valid)" ,
1298
+ },
1299
+ {
1300
+ configMap : & v1.ConfigMap {
1301
+ Data : map [string ]string {
1302
+ "opentracing" : "true" ,
1303
+ },
1304
+ },
1305
+ isPlus : true ,
1306
+ expectedOpenTracingEnabled : false ,
1307
+ expectedLoadModule : false ,
1308
+ expectedTracer : "" ,
1309
+ expectedTracerConfig : "" ,
1310
+ expectedConfigOk : false ,
1311
+ msg : "plus: opentracing enabled (invalid)" ,
1312
+ },
1313
+ {
1314
+ configMap : & v1.ConfigMap {
1315
+ Data : map [string ]string {
1316
+ "opentracing" : "true" ,
1317
+ "opentracing-tracer" : "/usr/local/lib/libjaegertracing.so" ,
1318
+ "opentracing-tracer-config" : "/etc/nginx/opentracing.json" ,
1319
+ },
1320
+ },
1321
+ isPlus : true ,
1322
+ expectedOpenTracingEnabled : false ,
1323
+ expectedLoadModule : false ,
1324
+ expectedTracer : "" ,
1325
+ expectedTracerConfig : "" ,
1326
+ expectedConfigOk : false ,
1327
+ msg : "plus: opentracing enabled, tracer and tracer-config set (invalid)" ,
1219
1328
},
1220
1329
}
1221
- nginxPlus := false
1330
+
1222
1331
hasAppProtect := false
1223
1332
hasAppProtectDos := false
1224
1333
hasTLSPassthrough := false
1225
1334
1226
1335
for _ , test := range tests {
1227
1336
t .Run (test .msg , func (t * testing.T ) {
1228
- result , configOk := ParseConfigMap (context .Background (), test .configMap , nginxPlus ,
1337
+ result , configOk := ParseConfigMap (context .Background (), test .configMap , test . isPlus ,
1229
1338
hasAppProtect , hasAppProtectDos , hasTLSPassthrough , makeEventLogger ())
1230
1339
1231
- if ! configOk {
1232
- t .Errorf ("Expected valid config , got invalid" )
1340
+ if configOk != test . expectedConfigOk {
1341
+ t .Errorf ("configOk: want %v , got %v" , test . expectedConfigOk , configOk )
1233
1342
}
1234
- if result .MainOpenTracingEnabled != test .enabled {
1343
+ if result .MainOpenTracingEnabled != test .expectedOpenTracingEnabled {
1235
1344
t .Errorf ("MainOpenTracingEnabled: want %v, got %v" ,
1236
- test .enabled , result .MainOpenTracingEnabled )
1345
+ test .expectedOpenTracingEnabled , result .MainOpenTracingEnabled )
1237
1346
}
1238
1347
1239
- if result .MainOpenTracingLoadModule != test .loadModule {
1348
+ if result .MainOpenTracingLoadModule != test .expectedLoadModule {
1240
1349
t .Errorf ("MainOpenTracingLoadModule: want %v, got %v" ,
1241
- test .loadModule , result .MainOpenTracingLoadModule )
1350
+ test .expectedLoadModule , result .MainOpenTracingLoadModule )
1242
1351
}
1243
1352
1244
- if result .MainOpenTracingTracer != test .tracer {
1353
+ if result .MainOpenTracingTracer != test .expectedTracer {
1245
1354
t .Errorf ("MainOpenTracingTracer: want %q, got %q" ,
1246
- test .tracer , result .MainOpenTracingTracer )
1355
+ test .expectedTracer , result .MainOpenTracingTracer )
1247
1356
}
1248
1357
1249
- if result .MainOpenTracingTracerConfig != test .tracerConfig {
1358
+ if result .MainOpenTracingTracerConfig != test .expectedTracerConfig {
1250
1359
t .Errorf ("MainOpenTracingTracerConfig: want %q, got %q" ,
1251
- test .tracerConfig , result .MainOpenTracingTracerConfig )
1360
+ test .expectedTracerConfig , result .MainOpenTracingTracerConfig )
1252
1361
}
1253
1362
})
1254
1363
}
0 commit comments