github.com/gogf/gf@v1.16.9/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/gogf/gf. 6 7 package glog 8 9 import ( 10 "bytes" 11 "github.com/gogf/gf/test/gtest" 12 "strings" 13 "testing" 14 ) 15 16 func Test_SetConfigWithMap(t *testing.T) { 17 gtest.C(t, func(t *gtest.T) { 18 l := New() 19 m := map[string]interface{}{ 20 "path": "/var/log", 21 "level": "all", 22 "stdout": false, 23 "StStatus": 0, 24 } 25 err := l.SetConfigWithMap(m) 26 t.Assert(err, nil) 27 t.Assert(l.config.Path, m["path"]) 28 t.Assert(l.config.Level, LEVEL_ALL) 29 t.Assert(l.config.StdoutPrint, m["stdout"]) 30 }) 31 } 32 33 func Test_SetConfigWithMap_LevelStr(t *testing.T) { 34 gtest.C(t, func(t *gtest.T) { 35 buffer := bytes.NewBuffer(nil) 36 l := New() 37 m := map[string]interface{}{ 38 "level": "all", 39 } 40 err := l.SetConfigWithMap(m) 41 t.Assert(err, nil) 42 43 l.SetWriter(buffer) 44 45 l.Debug("test") 46 l.Warning("test") 47 t.Assert(strings.Contains(buffer.String(), "DEBU"), true) 48 t.Assert(strings.Contains(buffer.String(), "WARN"), true) 49 }) 50 51 gtest.C(t, func(t *gtest.T) { 52 buffer := bytes.NewBuffer(nil) 53 l := New() 54 m := map[string]interface{}{ 55 "level": "warn", 56 } 57 err := l.SetConfigWithMap(m) 58 t.Assert(err, nil) 59 l.SetWriter(buffer) 60 l.Debug("test") 61 l.Warning("test") 62 t.Assert(strings.Contains(buffer.String(), "DEBU"), false) 63 t.Assert(strings.Contains(buffer.String(), "WARN"), true) 64 }) 65 }