@@ -304,6 +304,9 @@ var _ = Describe("Zap log level flag options setup", func() {
304
304
var (
305
305
fromFlags Options
306
306
fs flag.FlagSet
307
+ info = "info text"
308
+ debug1 = "debug 1 text"
309
+ debug2 = "debug 2 text"
307
310
)
308
311
309
312
BeforeEach (func () {
@@ -315,77 +318,75 @@ var _ = Describe("Zap log level flag options setup", func() {
315
318
It ("Should set info/debug zap-log-level flags." , func () {
316
319
args := []string {"--zap-log-level=debug" }
317
320
fromFlags .BindFlags (& fs )
318
- if err := fs .Parse (args ); err != nil {
319
- Expect (err ).ToNot (HaveOccurred ())
320
- }
321
+ err := fs .Parse (args )
322
+ Expect (err ).ToNot (HaveOccurred ())
321
323
logOut := new (bytes.Buffer )
322
324
323
325
logger := New (UseFlagOptions (& fromFlags ), WriteTo (logOut ))
324
- logger .V (0 ).Info (" info text" )
325
- logger .V (1 ).Info ("debug 1 text" )
326
+ logger .V (0 ).Info (info )
327
+ logger .V (1 ).Info (debug1 )
326
328
327
329
outRaw := logOut .Bytes ()
328
330
329
- Expect (string (outRaw )).Should (ContainSubstring (" info text" ))
330
- Expect (string (outRaw )).Should (ContainSubstring ("debug 1 text" ))
331
+ Expect (string (outRaw )).Should (ContainSubstring (info ))
332
+ Expect (string (outRaw )).Should (ContainSubstring (debug1 ))
331
333
332
334
})
333
335
334
336
It ("Should set error zap-log-level flags." , func () {
335
337
args := []string {"--zap-log-level=error" }
336
338
fromFlags .BindFlags (& fs )
337
- if err := fs .Parse (args ); err != nil {
338
- Expect (err ).ToNot (HaveOccurred ())
339
- }
339
+ err := fs .Parse (args )
340
+ Expect (err ).ToNot (HaveOccurred ())
341
+
340
342
logOut := new (bytes.Buffer )
341
343
342
344
logger := New (UseFlagOptions (& fromFlags ), WriteTo (logOut ))
343
- logger .V (0 ).Info (" info text" )
344
- logger .V (1 ).Info ("debug 1 text" )
345
+ logger .V (0 ).Info (info )
346
+ logger .V (1 ).Info (debug1 )
345
347
346
348
outRaw := logOut .Bytes ()
347
349
348
350
Expect (outRaw ).To (BeEmpty ())
349
351
})
350
352
351
- It ("Should set level 1 debug zap-log-level flags." , func () {
353
+ })
354
+
355
+ Context ("with zap-log-level with increased verbosity." , func () {
356
+ It ("Should set integer debug level 1 for zap-log-level flag." , func () {
352
357
args := []string {"--zap-log-level=1" }
353
358
fromFlags .BindFlags (& fs )
354
- if err := fs .Parse (args ); err != nil {
355
- Expect (err ).ToNot (HaveOccurred ())
356
- }
359
+ err := fs .Parse (args )
360
+ Expect (err ).ToNot (HaveOccurred ())
357
361
logOut := new (bytes.Buffer )
358
362
359
363
logger := New (UseFlagOptions (& fromFlags ), WriteTo (logOut ))
360
- logger .V (0 ).Info (" info text" )
361
- logger .V (1 ).Info ("debug 1 text" )
364
+ logger .V (0 ).Info (info )
365
+ logger .V (1 ).Info (debug1 )
362
366
363
367
outRaw := logOut .Bytes ()
364
368
365
- Expect (string (outRaw )).Should (ContainSubstring (" info text" ))
366
- Expect (string (outRaw )).Should (ContainSubstring ("debug 1 text" ))
369
+ Expect (string (outRaw )).Should (ContainSubstring (info ))
370
+ Expect (string (outRaw )).Should (ContainSubstring (debug1 ))
367
371
})
368
- })
369
372
370
- Context ("with zap-log-level with increased verbosity." , func () {
371
- It ("Should set Level 2 increased verbosity for zap-log-level flags." , func () {
373
+ It ("Should set integer debug level 2 for zap-log-level flag." , func () {
372
374
args := []string {"--zap-log-level=2" }
373
375
fromFlags .BindFlags (& fs )
374
- if err := fs .Parse (args ); err != nil {
375
- Expect (err ).ToNot (HaveOccurred ())
376
- }
376
+ err := fs .Parse (args )
377
+ Expect (err ).ToNot (HaveOccurred ())
377
378
logOut := new (bytes.Buffer )
378
379
379
380
logger := New (UseFlagOptions (& fromFlags ), WriteTo (logOut ))
380
- logger .V (0 ).Info (" info text" )
381
- logger .V (1 ).Info ("debug 1 text" )
382
- logger .V (2 ).Info ("debug 2 text" )
381
+ logger .V (0 ).Info (info )
382
+ logger .V (1 ).Info (debug1 )
383
+ logger .V (2 ).Info (debug2 )
383
384
384
385
outRaw := logOut .Bytes ()
385
386
386
- Expect (string (outRaw )).Should (ContainSubstring (" info text" ))
387
- Expect (string (outRaw )).Should (ContainSubstring ("debug 1 text" ))
388
- Expect (string (outRaw )).Should (ContainSubstring ("debug 2 text" ))
387
+ Expect (string (outRaw )).Should (ContainSubstring (info ))
388
+ Expect (string (outRaw )).Should (ContainSubstring (debug1 ))
389
+ Expect (string (outRaw )).Should (ContainSubstring (debug2 ))
389
390
390
391
})
391
392
@@ -396,9 +397,8 @@ var _ = Describe("Zap log level flag options setup", func() {
396
397
It ("Should set info stacktrace for zap-stacktrace-level flags." , func () {
397
398
args := []string {"--zap-stacktrace-level=info" , "--zap-devel=true" }
398
399
fromFlags .BindFlags (& fs )
399
- if err := fs .Parse (args ); err != nil {
400
- Expect (err ).ToNot (HaveOccurred ())
401
- }
400
+ err := fs .Parse (args )
401
+ Expect (err ).ToNot (HaveOccurred ())
402
402
out := Options {}
403
403
UseFlagOptions (& fromFlags )(& out )
404
404
@@ -408,9 +408,8 @@ var _ = Describe("Zap log level flag options setup", func() {
408
408
It ("Should set error stacktrace for zap-stacktrace-level flags." , func () {
409
409
args := []string {"--zap-stacktrace-level=error" , "--zap-devel=true" }
410
410
fromFlags .BindFlags (& fs )
411
- if err := fs .Parse (args ); err != nil {
412
- Expect (err ).ToNot (HaveOccurred ())
413
- }
411
+ err := fs .Parse (args )
412
+ Expect (err ).ToNot (HaveOccurred ())
414
413
out := Options {}
415
414
UseFlagOptions (& fromFlags )(& out )
416
415
@@ -420,9 +419,8 @@ var _ = Describe("Zap log level flag options setup", func() {
420
419
It ("Should disable stacktrace for zap-stacktrace-level flags." , func () {
421
420
args := []string {"--zap-stacktrace-level=disabled" , "--zap-devel=true" }
422
421
fromFlags .BindFlags (& fs )
423
- if err := fs .Parse (args ); err != nil {
424
- Expect (err ).ToNot (HaveOccurred ())
425
- }
422
+ err := fs .Parse (args )
423
+ Expect (err ).ToNot (HaveOccurred ())
426
424
out := Options {}
427
425
UseFlagOptions (& fromFlags )(& out )
428
426
0 commit comments