github.com/verrazzano/verrazzano@v1.7.1/pkg/log/vzlog/vzlog_test.go (about)

     1  // Copyright (c) 2022, 2023, 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 vzlog
     5  
     6  import (
     7  	"github.com/stretchr/testify/assert"
     8  	"go.uber.org/zap"
     9  	"testing"
    10  )
    11  
    12  // TestLog tests the ProgressLogger function periodic logging
    13  // GIVEN a ProgressLogger with a frequency of 3 seconds
    14  // WHEN log is called 5 times in 5 seconds to log the same message
    15  // THEN ensure that 2 messages are logged
    16  func TestLog(t *testing.T) {
    17  	const (
    18  		name      = "name"
    19  		namespace = "namespace"
    20  		uid       = "uid"
    21  		gen       = 100
    22  	)
    23  
    24  	assert.NotNil(t, DefaultLogger())
    25  
    26  	log, err := EnsureResourceLogger(&ResourceConfig{
    27  		Name:           name,
    28  		Namespace:      namespace,
    29  		ID:             uid,
    30  		Generation:     gen,
    31  		ControllerName: "verrazzano",
    32  	})
    33  	assert.NoError(t, err)
    34  	assert.NotNil(t, log)
    35  
    36  	r := ResourceConfig{
    37  		Name:           name,
    38  		Namespace:      namespace,
    39  		ID:             uid,
    40  		Generation:     gen,
    41  		ControllerName: "verrazzano",
    42  	}
    43  	log = ForZapLogger(&r, zap.S())
    44  	assert.NotNil(t, log)
    45  }