github.com/msales/pkg/v3@v3.24.0/log/logger_test.go (about)

     1  package log_test
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/msales/pkg/v3/log"
     8  	"github.com/stretchr/testify/mock"
     9  )
    10  
    11  func TestDebug(t *testing.T) {
    12  	m := new(MockLogger)
    13  	m.On("Debug", "test log", []interface{}{"foo", "bar"})
    14  	ctx := log.WithLogger(context.Background(), m)
    15  
    16  	log.Debug(ctx, "test log", "foo", "bar")
    17  
    18  	m.AssertExpectations(t)
    19  }
    20  
    21  func TestInfo(t *testing.T) {
    22  	m := new(MockLogger)
    23  	m.On("Info", "test log", []interface{}{"foo", "bar"})
    24  	ctx := log.WithLogger(context.Background(), m)
    25  
    26  	log.Info(ctx, "test log", "foo", "bar")
    27  
    28  	m.AssertExpectations(t)
    29  }
    30  
    31  func TestError(t *testing.T) {
    32  	m := new(MockLogger)
    33  	m.On("Error", "test log", []interface{}{"foo", "bar"})
    34  	ctx := log.WithLogger(context.Background(), m)
    35  
    36  	log.Error(ctx, "test log", "foo", "bar")
    37  
    38  	m.AssertExpectations(t)
    39  }
    40  
    41  func TestNullLogger_Debug(t *testing.T) {
    42  	log.Null.Debug("test log", "foo", "bar")
    43  }
    44  
    45  func TestNullLogger_Info(t *testing.T) {
    46  	log.Null.Info("test log", "foo", "bar")
    47  }
    48  
    49  func TestNullLogger_Error(t *testing.T) {
    50  	log.Null.Error("test log", "foo", "bar")
    51  }
    52  
    53  type MockLogger struct {
    54  	mock.Mock
    55  }
    56  
    57  func (m *MockLogger) Debug(msg string, ctx ...interface{}) {
    58  	m.Called(msg, ctx)
    59  }
    60  
    61  func (m *MockLogger) Info(msg string, ctx ...interface{}) {
    62  	m.Called(msg, ctx)
    63  }
    64  
    65  func (m *MockLogger) Error(msg string, ctx ...interface{}) {
    66  	m.Called(msg, ctx)
    67  }