trpc.group/trpc-go/trpc-go@v1.0.3/log/writer_factory_test.go (about) 1 // 2 // 3 // Tencent is pleased to support the open source community by making tRPC available. 4 // 5 // Copyright (C) 2023 THL A29 Limited, a Tencent company. 6 // All rights reserved. 7 // 8 // If you have downloaded a copy of the tRPC source code from Tencent, 9 // please note that tRPC source code is licensed under the Apache 2.0 License, 10 // A copy of the Apache 2.0 License is included in this file. 11 // 12 // 13 14 package log_test 15 16 import ( 17 "testing" 18 19 "github.com/stretchr/testify/assert" 20 21 "trpc.group/trpc-go/trpc-go/log" 22 ) 23 24 func TestWriterFactory(t *testing.T) { 25 f1 := &log.ConsoleWriterFactory{} 26 assert.Equal(t, "log", f1.Type()) 27 28 // empty decoder 29 err := f1.Setup("default", nil) 30 assert.NotNil(t, err) 31 32 f2 := &log.FileWriterFactory{} 33 assert.Equal(t, "log", f2.Type()) 34 // empty decoder 35 err = f2.Setup("default", nil) 36 assert.NotNil(t, err) 37 38 f3 := &log.ConsoleWriterFactory{} 39 assert.Equal(t, "log", f3.Type()) 40 err = f3.Setup("default", &fakeDecoder{}) 41 assert.NotNil(t, err) 42 43 f4 := &log.FileWriterFactory{} 44 assert.Equal(t, "log", f4.Type()) 45 err = f4.Setup("default", &fakeDecoder{}) 46 assert.NotNil(t, err) 47 } 48 49 func TestFileWriterFactory_Setup(t *testing.T) { 50 var fileCfg = []log.OutputConfig{ 51 { 52 Writer: "file", 53 WriteConfig: log.WriteConfig{ 54 Filename: "trpc_time.log", 55 MaxAge: 7, 56 MaxBackups: 10, 57 MaxSize: 100, 58 TimeUnit: log.Day, 59 LogPath: "log", 60 }, 61 }, 62 } 63 logger := log.NewZapLog(fileCfg) 64 assert.NotNil(t, logger) 65 }