@@ -26,6 +26,7 @@ import (
26
26
"github.com/go-logr/logr"
27
27
. "github.com/onsi/ginkgo"
28
28
. "github.com/onsi/gomega"
29
+ "go.uber.org/zap/zapcore"
29
30
kapi "k8s.io/api/core/v1"
30
31
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
31
32
"k8s.io/apimachinery/pkg/types"
@@ -364,9 +365,11 @@ var _ = Describe("Zap log level flag options setup", func() {
364
365
Expect (string (outRaw )).Should (ContainSubstring ("info text" ))
365
366
Expect (string (outRaw )).Should (ContainSubstring ("debug 1 text" ))
366
367
})
368
+ })
367
369
368
- It ("Should set stacktrace zap-stacktrace-level flags." , func () {
369
- args := []string {"--zap-stacktrace-level=disabled" }
370
+ Context ("with zap-log-level with increased verbosity." , func () {
371
+ It ("Should set Level 2 increased verbosity for zap-log-level flags." , func () {
372
+ args := []string {"--zap-log-level=2" }
370
373
fromFlags .BindFlags (& fs )
371
374
if err := fs .Parse (args ); err != nil {
372
375
Expect (err ).ToNot (HaveOccurred ())
@@ -376,31 +379,55 @@ var _ = Describe("Zap log level flag options setup", func() {
376
379
logger := New (UseFlagOptions (& fromFlags ), WriteTo (logOut ))
377
380
logger .V (0 ).Info ("info text" )
378
381
logger .V (1 ).Info ("debug 1 text" )
382
+ logger .V (2 ).Info ("debug 2 text" )
379
383
380
384
outRaw := logOut .Bytes ()
381
385
382
- Expect (outRaw ).To (BeEmpty ())
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" ))
389
+
383
390
})
384
391
385
- It ("Should set Level 2 increased verbosity for zap-log-level flags." , func () {
386
- args := []string {"--zap-log-level=2" }
392
+ })
393
+
394
+ Context ("with zap-stacktrace-level options provided" , func () {
395
+
396
+ It ("Should set info stacktrace for zap-stacktrace-level flags." , func () {
397
+ args := []string {"--zap-stacktrace-level=info" , "--zap-devel=true" }
387
398
fromFlags .BindFlags (& fs )
388
399
if err := fs .Parse (args ); err != nil {
389
400
Expect (err ).ToNot (HaveOccurred ())
390
401
}
391
- logOut := new (bytes.Buffer )
402
+ out := Options {}
403
+ UseFlagOptions (& fromFlags )(& out )
392
404
393
- logger := New (UseFlagOptions (& fromFlags ), WriteTo (logOut ))
394
- logger .V (0 ).Info ("info text" )
395
- logger .V (1 ).Info ("debug 1 text" )
396
- logger .V (2 ).Info ("debug 2 text" )
405
+ Expect (out .StacktraceLevel .Enabled (zapcore .InfoLevel )).To (BeTrue ())
406
+ })
397
407
398
- outRaw := logOut .Bytes ()
408
+ It ("Should set error stacktrace for zap-stacktrace-level flags." , func () {
409
+ args := []string {"--zap-stacktrace-level=error" , "--zap-devel=true" }
410
+ fromFlags .BindFlags (& fs )
411
+ if err := fs .Parse (args ); err != nil {
412
+ Expect (err ).ToNot (HaveOccurred ())
413
+ }
414
+ out := Options {}
415
+ UseFlagOptions (& fromFlags )(& out )
399
416
400
- Expect (string (outRaw )).Should (ContainSubstring ("info text" ))
401
- Expect (string (outRaw )).Should (ContainSubstring ("debug 1 text" ))
402
- Expect (string (outRaw )).Should (ContainSubstring ("debug 2 text" ))
417
+ Expect (out .StacktraceLevel .Enabled (zapcore .ErrorLevel )).To (BeTrue ())
418
+ })
419
+
420
+ It ("Should disable stacktrace for zap-stacktrace-level flags." , func () {
421
+ args := []string {"--zap-stacktrace-level=disabled" , "--zap-devel=true" }
422
+ fromFlags .BindFlags (& fs )
423
+ if err := fs .Parse (args ); err != nil {
424
+ Expect (err ).ToNot (HaveOccurred ())
425
+ }
426
+ out := Options {}
427
+ UseFlagOptions (& fromFlags )(& out )
403
428
429
+ Expect (out .StacktraceLevel .Enabled (zapcore .FatalLevel )).To (BeTrue ())
404
430
})
405
431
})
432
+
406
433
})
0 commit comments