github.com/wangyougui/gf/v2@v2.6.5/os/glog/glog_z_unit_config_test.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/wangyougui/gf. 6 7 package glog 8 9 import ( 10 "bytes" 11 "strings" 12 "testing" 13 14 "github.com/wangyougui/gf/v2/test/gtest" 15 ) 16 17 func Test_SetConfigWithMap(t *testing.T) { 18 gtest.C(t, func(t *gtest.T) { 19 l := New() 20 m := map[string]interface{}{ 21 "path": "/var/log", 22 "level": "all", 23 "stdout": false, 24 "StStatus": 0, 25 } 26 err := l.SetConfigWithMap(m) 27 t.AssertNil(err) 28 t.Assert(l.config.Path, m["path"]) 29 t.Assert(l.config.Level, LEVEL_ALL) 30 t.Assert(l.config.StdoutPrint, m["stdout"]) 31 }) 32 } 33 34 func Test_SetConfigWithMap_LevelStr(t *testing.T) { 35 gtest.C(t, func(t *gtest.T) { 36 buffer := bytes.NewBuffer(nil) 37 l := New() 38 m := map[string]interface{}{ 39 "level": "all", 40 } 41 err := l.SetConfigWithMap(m) 42 t.AssertNil(err) 43 44 l.SetWriter(buffer) 45 46 l.Debug(ctx, "test") 47 l.Warning(ctx, "test") 48 t.Assert(strings.Contains(buffer.String(), "DEBU"), true) 49 t.Assert(strings.Contains(buffer.String(), "WARN"), true) 50 }) 51 52 gtest.C(t, func(t *gtest.T) { 53 buffer := bytes.NewBuffer(nil) 54 l := New() 55 m := map[string]interface{}{ 56 "level": "warn", 57 } 58 err := l.SetConfigWithMap(m) 59 t.AssertNil(err) 60 l.SetWriter(buffer) 61 l.Debug(ctx, "test") 62 l.Warning(ctx, "test") 63 t.Assert(strings.Contains(buffer.String(), "DEBU"), false) 64 t.Assert(strings.Contains(buffer.String(), "WARN"), true) 65 }) 66 }