go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/logutil/flags_test.go (about) 1 /* 2 3 Copyright (c) 2023 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package logutil 9 10 import ( 11 "fmt" 12 "log" 13 "testing" 14 15 . "go.charczuk.com/sdk/assert" 16 ) 17 18 func Test_Flags(t *testing.T) { 19 cases := [...]struct { 20 Input []string 21 Expected int 22 ExpectedErr error 23 }{ 24 {Input: []string{}, Expected: 0}, 25 {Input: []string{"Ltime"}, Expected: log.Ltime}, 26 {Input: []string{"Ldate", "Ltime", "Lmicroseconds", "Ldebug"}, Expected: log.Ldate | log.Ltime | log.Lmicroseconds | Ldebug}, 27 {Input: []string{"Ldate", "not-real", "Lmicroseconds", "Ldebug"}, Expected: 0, ExpectedErr: fmt.Errorf("invalid flag: %s", "not-real")}, 28 } 29 30 for _, tc := range cases { 31 fv, err := Flags(tc.Input...) 32 if tc.ExpectedErr != nil { 33 ItsNotNil(t, err) 34 ItsEqual(t, tc.ExpectedErr.Error(), err.Error()) 35 } else { 36 ItsEqual(t, tc.Expected, fv) 37 } 38 } 39 }