代码拉取完成,页面将自动刷新
同步操作将从 水不要鱼/logit 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
// Copyright 2022 FishGoddess. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package logit
import (
"context"
"os"
"testing"
"github.com/FishGoddess/logit/core/appender"
)
// go test -v -cover -run=^TestOptions$
func TestOptions(t *testing.T) {
opts := Options()
if opts != nil {
t.Errorf("Options returns wrong options %+v", opts)
}
}
// go test -v -cover -run=^TestOptionsWithDebugLevel$
func TestOptionsWithDebugLevel(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.level = offLevel
opts.WithDebugLevel().Apply(logger)
if logger.level != debugLevel {
t.Errorf("logger's level %s is wrong", logger.level)
}
}
// go test -v -cover -run=^TestOptionsWithInfoLevel$
func TestOptionsWithInfoLevel(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.level = offLevel
opts.WithInfoLevel().Apply(logger)
if logger.level != infoLevel {
t.Errorf("logger's level %s is wrong", logger.level)
}
}
// go test -v -cover -run=^TestOptionsWithWarnLevel$
func TestOptionsWithWarnLevel(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.level = offLevel
opts.WithWarnLevel().Apply(logger)
if logger.level != warnLevel {
t.Errorf("logger's level %s is wrong", logger.level)
}
}
// go test -v -cover -run=^TestOptionsWithErrorLevel$
func TestOptionsWithErrorLevel(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.level = offLevel
opts.WithErrorLevel().Apply(logger)
if logger.level != errorLevel {
t.Errorf("logger's level %s is wrong", logger.level)
}
}
// go test -v -cover -run=^TestOptionsWithPrintLevel$
func TestOptionsWithPrintLevel(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.level = offLevel
opts.WithPrintLevel().Apply(logger)
if logger.level != printLevel {
t.Errorf("logger's level %s is wrong", logger.level)
}
}
// go test -v -cover -run=^TestOptionsWithOffLevel$
func TestOptionsWithOffLevel(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.level = debugLevel
opts.WithOffLevel().Apply(logger)
if logger.level != offLevel {
t.Errorf("logger's level %s is wrong", logger.level)
}
}
// go test -v -cover -run=^TestOptionsWithAppender$
func TestOptionsWithAppender(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.debugAppender = nil
logger.infoAppender = nil
logger.warnAppender = nil
logger.errorAppender = nil
logger.printAppender = nil
opts.WithAppender(appender.Text()).Apply(logger)
if logger.debugAppender != appender.Text() {
t.Errorf("logger's debugAppender %s is wrong", logger.debugAppender)
}
if logger.infoAppender != appender.Text() {
t.Errorf("logger's infoAppender %s is wrong", logger.infoAppender)
}
if logger.warnAppender != appender.Text() {
t.Errorf("logger's warnAppender %s is wrong", logger.warnAppender)
}
if logger.errorAppender != appender.Text() {
t.Errorf("logger's errorAppender %s is wrong", logger.errorAppender)
}
if logger.printAppender != appender.Text() {
t.Errorf("logger's printAppender %s is wrong", logger.printAppender)
}
logger.debugAppender = nil
logger.infoAppender = nil
logger.warnAppender = nil
logger.errorAppender = nil
logger.printAppender = nil
opts.WithAppender(appender.Json()).Apply(logger)
if logger.debugAppender != appender.Json() {
t.Errorf("logger's debugAppender %s is wrong", logger.debugAppender)
}
if logger.infoAppender != appender.Json() {
t.Errorf("logger's infoAppender %s is wrong", logger.infoAppender)
}
if logger.warnAppender != appender.Json() {
t.Errorf("logger's warnAppender %s is wrong", logger.warnAppender)
}
if logger.errorAppender != appender.Json() {
t.Errorf("logger's errorAppender %s is wrong", logger.errorAppender)
}
if logger.printAppender != appender.Json() {
t.Errorf("logger's printAppender %s is wrong", logger.printAppender)
}
}
// go test -v -cover -run=^TestOptionsWithDebugAppender$
func TestOptionsWithDebugAppender(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.debugAppender = nil
logger.infoAppender = nil
logger.warnAppender = nil
logger.errorAppender = nil
logger.printAppender = nil
opts.WithDebugAppender(appender.Text()).Apply(logger)
if logger.debugAppender != appender.Text() {
t.Errorf("logger's debugAppender %s is wrong", logger.debugAppender)
}
if logger.infoAppender != nil {
t.Errorf("logger's infoAppender %s is wrong", logger.infoAppender)
}
if logger.warnAppender != nil {
t.Errorf("logger's warnAppender %s is wrong", logger.warnAppender)
}
if logger.errorAppender != nil {
t.Errorf("logger's errorAppender %s is wrong", logger.errorAppender)
}
if logger.printAppender != nil {
t.Errorf("logger's printAppender %s is wrong", logger.printAppender)
}
}
// go test -v -cover -run=^TestOptionsWithInfoAppender$
func TestOptionsWithInfoAppender(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.debugAppender = nil
logger.infoAppender = nil
logger.warnAppender = nil
logger.errorAppender = nil
logger.printAppender = nil
opts.WithInfoAppender(appender.Text()).Apply(logger)
if logger.debugAppender != nil {
t.Errorf("logger's debugAppender %s is wrong", logger.debugAppender)
}
if logger.infoAppender != appender.Text() {
t.Errorf("logger's infoAppender %s is wrong", logger.infoAppender)
}
if logger.warnAppender != nil {
t.Errorf("logger's warnAppender %s is wrong", logger.warnAppender)
}
if logger.errorAppender != nil {
t.Errorf("logger's errorAppender %s is wrong", logger.errorAppender)
}
if logger.printAppender != nil {
t.Errorf("logger's printAppender %s is wrong", logger.printAppender)
}
}
// go test -v -cover -run=^TestOptionsWithWarnAppender$
func TestOptionsWithWarnAppender(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.debugAppender = nil
logger.infoAppender = nil
logger.warnAppender = nil
logger.errorAppender = nil
logger.printAppender = nil
opts.WithWarnAppender(appender.Text()).Apply(logger)
if logger.debugAppender != nil {
t.Errorf("logger's debugAppender %s is wrong", logger.debugAppender)
}
if logger.infoAppender != nil {
t.Errorf("logger's infoAppender %s is wrong", logger.infoAppender)
}
if logger.warnAppender != appender.Text() {
t.Errorf("logger's warnAppender %s is wrong", logger.warnAppender)
}
if logger.errorAppender != nil {
t.Errorf("logger's errorAppender %s is wrong", logger.errorAppender)
}
if logger.printAppender != nil {
t.Errorf("logger's printAppender %s is wrong", logger.printAppender)
}
}
// go test -v -cover -run=^TestOptionsWithErrorAppender$
func TestOptionsWithErrorAppender(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.debugAppender = nil
logger.infoAppender = nil
logger.warnAppender = nil
logger.errorAppender = nil
logger.printAppender = nil
opts.WithErrorAppender(appender.Text()).Apply(logger)
if logger.debugAppender != nil {
t.Errorf("logger's debugAppender %s is wrong", logger.debugAppender)
}
if logger.infoAppender != nil {
t.Errorf("logger's infoAppender %s is wrong", logger.infoAppender)
}
if logger.warnAppender != nil {
t.Errorf("logger's warnAppender %s is wrong", logger.warnAppender)
}
if logger.errorAppender != appender.Text() {
t.Errorf("logger's errorAppender %s is wrong", logger.errorAppender)
}
if logger.printAppender != nil {
t.Errorf("logger's printAppender %s is wrong", logger.printAppender)
}
}
// go test -v -cover -run=^TestOptionsWithPrintAppender$
func TestOptionsWithPrintAppender(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.debugAppender = nil
logger.infoAppender = nil
logger.warnAppender = nil
logger.errorAppender = nil
logger.printAppender = nil
opts.WithPrintAppender(appender.Text()).Apply(logger)
if logger.debugAppender != nil {
t.Errorf("logger's debugAppender %s is wrong", logger.debugAppender)
}
if logger.infoAppender != nil {
t.Errorf("logger's infoAppender %s is wrong", logger.infoAppender)
}
if logger.warnAppender != nil {
t.Errorf("logger's warnAppender %s is wrong", logger.warnAppender)
}
if logger.errorAppender != nil {
t.Errorf("logger's errorAppender %s is wrong", logger.errorAppender)
}
if logger.printAppender != appender.Text() {
t.Errorf("logger's printAppender %s is wrong", logger.printAppender)
}
}
// go test -v -cover -run=^TestOptionsWithWriter$
func TestOptionsWithWriter(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.debugWriter = nil
logger.infoWriter = nil
logger.warnWriter = nil
logger.errorWriter = nil
logger.printWriter = nil
opts.WithWriter(os.Stdout).Apply(logger)
if logger.debugWriter == nil {
t.Errorf("logger's debugWriter %s is wrong", logger.debugWriter)
}
if logger.infoWriter == nil {
t.Errorf("logger's infoWriter %s is wrong", logger.infoWriter)
}
if logger.warnWriter == nil {
t.Errorf("logger's warnWriter %s is wrong", logger.warnWriter)
}
if logger.errorWriter == nil {
t.Errorf("logger's errorWriter %s is wrong", logger.errorWriter)
}
if logger.printWriter == nil {
t.Errorf("logger's printWriter %s is wrong", logger.printWriter)
}
}
// go test -v -cover -run=^TestOptionsWithBufferWriter$
func TestOptionsWithBufferWriter(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.debugWriter = nil
logger.infoWriter = nil
logger.warnWriter = nil
logger.errorWriter = nil
logger.printWriter = nil
opts.WithBufferWriter(os.Stdout).Apply(logger)
if logger.debugWriter == nil {
t.Errorf("logger's debugWriter %s is wrong", logger.debugWriter)
}
if logger.infoWriter == nil {
t.Errorf("logger's infoWriter %s is wrong", logger.infoWriter)
}
if logger.warnWriter == nil {
t.Errorf("logger's warnWriter %s is wrong", logger.warnWriter)
}
if logger.errorWriter == nil {
t.Errorf("logger's errorWriter %s is wrong", logger.errorWriter)
}
if logger.printWriter == nil {
t.Errorf("logger's printWriter %s is wrong", logger.printWriter)
}
}
// go test -v -cover -run=^TestOptionsWithBatchWriter$
func TestOptionsWithBatchWriter(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.debugWriter = nil
logger.infoWriter = nil
logger.warnWriter = nil
logger.errorWriter = nil
logger.printWriter = nil
opts.WithBatchWriter(os.Stdout).Apply(logger)
if logger.debugWriter == nil {
t.Errorf("logger's debugWriter %s is wrong", logger.debugWriter)
}
if logger.infoWriter == nil {
t.Errorf("logger's infoWriter %s is wrong", logger.infoWriter)
}
if logger.warnWriter == nil {
t.Errorf("logger's warnWriter %s is wrong", logger.warnWriter)
}
if logger.errorWriter == nil {
t.Errorf("logger's errorWriter %s is wrong", logger.errorWriter)
}
if logger.printWriter == nil {
t.Errorf("logger's printWriter %s is wrong", logger.printWriter)
}
}
// go test -v -cover -run=^TestOptionsWithDebugWriter$
func TestOptionsWithDebugWriter(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.debugWriter = nil
logger.infoWriter = nil
logger.warnWriter = nil
logger.errorWriter = nil
logger.printWriter = nil
opts.WithDebugWriter(os.Stdout).Apply(logger)
if logger.debugWriter == nil {
t.Errorf("logger's debugWriter %s is wrong", logger.debugWriter)
}
if logger.infoWriter != nil {
t.Errorf("logger's infoWriter %s is wrong", logger.infoWriter)
}
if logger.warnWriter != nil {
t.Errorf("logger's warnWriter %s is wrong", logger.warnWriter)
}
if logger.errorWriter != nil {
t.Errorf("logger's errorWriter %s is wrong", logger.errorWriter)
}
if logger.printWriter != nil {
t.Errorf("logger's printWriter %s is wrong", logger.printWriter)
}
}
// go test -v -cover -run=^TestOptionsWithInfoWriter$
func TestOptionsWithInfoWriter(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.debugWriter = nil
logger.infoWriter = nil
logger.warnWriter = nil
logger.errorWriter = nil
logger.printWriter = nil
opts.WithInfoWriter(os.Stdout).Apply(logger)
if logger.debugWriter != nil {
t.Errorf("logger's debugWriter %s is wrong", logger.debugWriter)
}
if logger.infoWriter == nil {
t.Errorf("logger's infoWriter %s is wrong", logger.infoWriter)
}
if logger.warnWriter != nil {
t.Errorf("logger's warnWriter %s is wrong", logger.warnWriter)
}
if logger.errorWriter != nil {
t.Errorf("logger's errorWriter %s is wrong", logger.errorWriter)
}
if logger.printWriter != nil {
t.Errorf("logger's printWriter %s is wrong", logger.printWriter)
}
}
// go test -v -cover -run=^TestOptionsWithWarnWriter$
func TestOptionsWithWarnWriter(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.debugWriter = nil
logger.infoWriter = nil
logger.warnWriter = nil
logger.errorWriter = nil
logger.printWriter = nil
opts.WithWarnWriter(os.Stdout).Apply(logger)
if logger.debugWriter != nil {
t.Errorf("logger's debugWriter %s is wrong", logger.debugWriter)
}
if logger.infoWriter != nil {
t.Errorf("logger's infoWriter %s is wrong", logger.infoWriter)
}
if logger.warnWriter == nil {
t.Errorf("logger's warnWriter %s is wrong", logger.warnWriter)
}
if logger.errorWriter != nil {
t.Errorf("logger's errorWriter %s is wrong", logger.errorWriter)
}
if logger.printWriter != nil {
t.Errorf("logger's printWriter %s is wrong", logger.printWriter)
}
}
// go test -v -cover -run=^TestOptionsWithErrorWriter$
func TestOptionsWithErrorWriter(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.debugWriter = nil
logger.infoWriter = nil
logger.warnWriter = nil
logger.errorWriter = nil
logger.printWriter = nil
opts.WithErrorWriter(os.Stdout).Apply(logger)
if logger.debugWriter != nil {
t.Errorf("logger's debugWriter %s is wrong", logger.debugWriter)
}
if logger.infoWriter != nil {
t.Errorf("logger's infoWriter %s is wrong", logger.infoWriter)
}
if logger.warnWriter != nil {
t.Errorf("logger's warnWriter %s is wrong", logger.warnWriter)
}
if logger.errorWriter == nil {
t.Errorf("logger's errorWriter %s is wrong", logger.errorWriter)
}
if logger.printWriter != nil {
t.Errorf("logger's printWriter %s is wrong", logger.printWriter)
}
}
// go test -v -cover -run=^TestOptionsWithPrintWriter$
func TestOptionsWithPrintWriter(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.debugWriter = nil
logger.infoWriter = nil
logger.warnWriter = nil
logger.errorWriter = nil
logger.printWriter = nil
opts.WithPrintWriter(os.Stdout).Apply(logger)
if logger.debugWriter != nil {
t.Errorf("logger's debugWriter %s is wrong", logger.debugWriter)
}
if logger.infoWriter != nil {
t.Errorf("logger's infoWriter %s is wrong", logger.infoWriter)
}
if logger.warnWriter != nil {
t.Errorf("logger's warnWriter %s is wrong", logger.warnWriter)
}
if logger.errorWriter != nil {
t.Errorf("logger's errorWriter %s is wrong", logger.errorWriter)
}
if logger.printWriter == nil {
t.Errorf("logger's printWriter %s is wrong", logger.printWriter)
}
}
// go test -v -cover -run=^TestOptionsWithPID$
func TestOptionsWithPID(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.withPID = false
opts.WithPID().Apply(logger)
if logger.withPID != true {
t.Errorf("logger's withPID %+v is wrong", logger.withPID)
}
}
// go test -v -cover -run=^TestOptionsWithCaller$
func TestOptionsWithCaller(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.withCaller = false
opts.WithCaller().Apply(logger)
if logger.withCaller != true {
t.Errorf("logger's withCaller %+v is wrong", logger.withCaller)
}
}
// go test -v -cover -run=^TestOptionsWithMsgKey$
func TestOptionsWithMsgKey(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.msgKey = ""
opts.WithMsgKey("msg").Apply(logger)
if logger.msgKey != "msg" {
t.Errorf("logger's msgKey %+v is wrong", logger.msgKey)
}
}
// go test -v -cover -run=^TestOptionsWithTimeKey$
func TestOptionsWithTimeKey(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.timeKey = ""
opts.WithTimeKey("time").Apply(logger)
if logger.timeKey != "time" {
t.Errorf("logger's timeKey %+v is wrong", logger.timeKey)
}
}
// go test -v -cover -run=^TestOptionsWithLevelKey$
func TestOptionsWithLevelKey(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.levelKey = ""
opts.WithLevelKey("level").Apply(logger)
if logger.levelKey != "level" {
t.Errorf("logger's levelKey %+v is wrong", logger.levelKey)
}
}
// go test -v -cover -run=^TestOptionsWithPIDKey$
func TestOptionsWithPIDKey(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.pidKey = ""
opts.WithPIDKey("pid").Apply(logger)
if logger.pidKey != "pid" {
t.Errorf("logger's pidKey %+v is wrong", logger.pidKey)
}
}
// go test -v -cover -run=^TestOptionsWithFileKey$
func TestOptionsWithFileKey(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.fileKey = ""
opts.WithFileKey("file").Apply(logger)
if logger.fileKey != "file" {
t.Errorf("logger's fileKey %+v is wrong", logger.fileKey)
}
}
// go test -v -cover -run=^TestOptionsWithLineKey$
func TestOptionsWithLineKey(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.lineKey = ""
opts.WithLineKey("line").Apply(logger)
if logger.lineKey != "line" {
t.Errorf("logger's lineKey %+v is wrong", logger.lineKey)
}
}
// go test -v -cover -run=^TestOptionsWithFuncKey$
func TestOptionsWithFuncKey(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.funcKey = ""
opts.WithFuncKey("func").Apply(logger)
if logger.funcKey != "func" {
t.Errorf("logger's funcKey %+v is wrong", logger.funcKey)
}
}
// go test -v -cover -run=^TestOptionsWithErrorKey$
func TestOptionsWithErrorKey(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.errorKey = ""
opts.WithErrorKey("err").Apply(logger)
if logger.errorKey != "err" {
t.Errorf("logger's errorKey %+v is wrong", logger.errorKey)
}
}
// go test -v -cover -run=^TestOptionsWithTimeFormat$
func TestOptionsWithTimeFormat(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.timeFormat = ""
opts.WithTimeFormat("20060102150405").Apply(logger)
if logger.timeFormat != "20060102150405" {
t.Errorf("logger's timeFormat %+v is wrong", logger.timeFormat)
}
}
// go test -v -cover -run=^TestOptionsWithCallerDepth$
func TestOptionsWithCallerDepth(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.callerDepth = 0
opts.WithCallerDepth(3).Apply(logger)
if logger.callerDepth != 3 {
t.Errorf("logger's callerDepth %d is wrong", logger.callerDepth)
}
}
// go test -v -cover -run=^TestOptionsWithInterceptors$
func TestOptionsWithInterceptors(t *testing.T) {
opts := Options()
logger := NewLogger()
logger.interceptors = nil
interceptors := []Interceptor{
func(ctx context.Context, log *Log) {},
func(ctx context.Context, log *Log) {},
func(ctx context.Context, log *Log) {},
}
opts.WithInterceptors(interceptors...).Apply(logger)
if len(logger.interceptors) != len(interceptors) {
t.Errorf("len(logger.interceptors) %d != len(interceptors) %d", len(logger.interceptors), len(interceptors))
}
logger.interceptors = nil
opts.WithInterceptors()
if len(logger.interceptors) != 0 {
t.Errorf("len(logger.interceptors) %d != 0", len(logger.interceptors))
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。