github.com/verrazzano/verrazzano@v1.7.0/tools/vz/pkg/analysis/internal/util/log/log_test.go (about)

     1  // Copyright (C) 2020, 2022, Oracle and/or its affiliates.
     2  // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
     3  
     4  package log
     5  
     6  import (
     7  	"testing"
     8  
     9  	kzap "sigs.k8s.io/controller-runtime/pkg/log/zap"
    10  
    11  	"github.com/stretchr/testify/assert"
    12  	"go.uber.org/zap"
    13  	"go.uber.org/zap/zapcore"
    14  )
    15  
    16  func TestInitLogsDefaultInfo(t *testing.T) {
    17  	InitLogs(kzap.Options{})
    18  	zap.S().Errorf("greeting %v", "hello")
    19  	zap.S().Infof("greeting %v", "hello")
    20  	zap.S().Debugf("greeting %v", "hello")
    21  	msg := "InfoLevel is enabled"
    22  	assert.NotNil(t, zap.L().Check(zapcore.InfoLevel, msg), msg)
    23  	msg = "ErrorLevel is enabled"
    24  	assert.NotNil(t, zap.L().Check(zapcore.ErrorLevel, msg), msg)
    25  	msg = "DebugLevel is disabled"
    26  	assert.Nil(t, zap.L().Check(zapcore.DebugLevel, msg), msg)
    27  }
    28  
    29  func TestInitLogsNonDefaultInfo(t *testing.T) {
    30  	testOpts := kzap.Options{}
    31  	testOpts.Development = true
    32  	testOpts.Level = zap.NewAtomicLevelAt(zap.InfoLevel)
    33  	InitLogs(testOpts)
    34  	zap.S().Errorf("greeting %v", "hello")
    35  	zap.S().Infof("greeting %v", "hello")
    36  	zap.S().Debugf("greeting %v", "hello")
    37  	msg := "InfoLevel is enabled"
    38  	assert.NotNil(t, zap.L().Check(zapcore.InfoLevel, msg), msg)
    39  	msg = "ErrorLevel is enabled"
    40  	assert.NotNil(t, zap.L().Check(zapcore.ErrorLevel, msg), msg)
    41  	msg = "DebugLevel is disabled"
    42  	assert.Nil(t, zap.L().Check(zapcore.DebugLevel, msg), msg)
    43  }