dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts@v1.0.2/clients/logger/logger_test.go (about)

     1  //
     2  // Copyright (c) 2018 Cavium
     3  //
     4  // SPDX-License-Identifier: Apache-2.0
     5  //
     6  
     7  package logger
     8  
     9  import (
    10  	"testing"
    11  
    12  	"dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/models"
    13  
    14  	"github.com/stretchr/testify/assert"
    15  )
    16  
    17  func TestIsValidLogLevel(t *testing.T) {
    18  	var tests = []struct {
    19  		level string
    20  		res   bool
    21  	}{
    22  		{models.TraceLog, true},
    23  		{models.DebugLog, true},
    24  		{models.InfoLog, true},
    25  		{models.WarnLog, true},
    26  		{models.ErrorLog, true},
    27  		{"EERROR", false},
    28  		{"ERRORR", false},
    29  		{"INF", false},
    30  	}
    31  	for _, tt := range tests {
    32  		t.Run(tt.level, func(t *testing.T) {
    33  			r := isValidLogLevel(tt.level)
    34  			if r != tt.res {
    35  				t.Errorf("Level %s labeled as %v and should be %v",
    36  					tt.level, r, tt.res)
    37  			}
    38  		})
    39  	}
    40  }
    41  
    42  func TestLogLevel(t *testing.T) {
    43  	expectedLogLevel := models.DebugLog
    44  	lc := NewClient("testService", expectedLogLevel)
    45  	assert.Equal(t, expectedLogLevel, lc.LogLevel())
    46  }