github.com/msales/pkg/v3@v3.24.0/clix/log_test.go (about)

     1  package clix_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/msales/pkg/v3/clix"
     7  	"github.com/msales/pkg/v3/log"
     8  	"github.com/stretchr/testify/assert"
     9  	"gopkg.in/urfave/cli.v1"
    10  )
    11  
    12  func TestNewLogger(t *testing.T) {
    13  	tests := []struct {
    14  		level  string
    15  		format string
    16  		tags   *cli.StringSlice
    17  
    18  		shouldErr bool
    19  	}{
    20  		{"info", "json", &cli.StringSlice{}, false},
    21  		{"info", "terminal", &cli.StringSlice{}, false},
    22  		{"info", "logfmt", &cli.StringSlice{}, false},
    23  		{"", "json", &cli.StringSlice{}, false},
    24  		{"info", "", &cli.StringSlice{}, false},
    25  		{"invalid", "json", &cli.StringSlice{}, true},
    26  		{"info", "invalid", &cli.StringSlice{}, true},
    27  		{"info", "json", &cli.StringSlice{"single"}, true},
    28  	}
    29  
    30  	for _, tt := range tests {
    31  		c, fs := newTestContext()
    32  		fs.String(clix.FlagLogLevel, tt.level, "doc")
    33  		fs.String(clix.FlagLogFormat, tt.format, "doc")
    34  		fs.Var(tt.tags, clix.FlagLogTags, "doc")
    35  
    36  		l, err := clix.NewLogger(c)
    37  
    38  		if tt.shouldErr {
    39  			assert.Error(t, err)
    40  		} else {
    41  			assert.NoError(t, err)
    42  			assert.Implements(t, (*log.Logger)(nil), l)
    43  		}
    44  	}
    45  }