69 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			69 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
// Package consts ...
 | 
						|
//
 | 
						|
// Description : consts ...
 | 
						|
//
 | 
						|
// Author : go_developer@163.com<白茶清欢>
 | 
						|
//
 | 
						|
// Date : 2025-01-22 15:36
 | 
						|
package consts
 | 
						|
 | 
						|
import (
 | 
						|
	"encoding/json"
 | 
						|
	. "github.com/smartystreets/goconvey/convey"
 | 
						|
	"testing"
 | 
						|
)
 | 
						|
 | 
						|
func TestLogLevel_String(t *testing.T) {
 | 
						|
	Convey("logger type字符串值", t, func() {
 | 
						|
		byteData, err := json.Marshal(LogLevelDebug)
 | 
						|
		So(err, ShouldBeNil)
 | 
						|
		So(LogLevelDebug.String(), ShouldEqual, "DEBUG")
 | 
						|
		So(string(byteData), ShouldEqual, `"DEBUG"`)
 | 
						|
	})
 | 
						|
	Convey("logger type MarshalJSON", t, func() {
 | 
						|
		str, err := LogLevelDebug.MarshalJSON()
 | 
						|
		So(err, ShouldBeNil)
 | 
						|
		So(string(str), ShouldEqual, `"DEBUG"`)
 | 
						|
		dataList := []LogLevel{LogLevelDebug}
 | 
						|
		jsonData, err := json.Marshal(dataList)
 | 
						|
		So(err, ShouldBeNil)
 | 
						|
		So(string(jsonData), ShouldEqual, `["DEBUG"]`)
 | 
						|
	})
 | 
						|
}
 | 
						|
 | 
						|
func TestLogLevel_IsValid(t *testing.T) {
 | 
						|
	Convey("logger type 非法验证", t, func() {
 | 
						|
		So(LogLevel("Invalid").IsValid(), ShouldBeFalse)
 | 
						|
	})
 | 
						|
	Convey("logger type 合法验证", t, func() {
 | 
						|
		So(LogLevelDebug.IsValid(), ShouldBeTrue)
 | 
						|
	})
 | 
						|
}
 | 
						|
 | 
						|
func TestLogSplit_String(t *testing.T) {
 | 
						|
	Convey("logger split 字符串值", t, func() {
 | 
						|
		byteData, err := json.Marshal(LogSplitHour)
 | 
						|
		So(err, ShouldBeNil)
 | 
						|
		So(LogSplitHour.String(), ShouldEqual, "HOUR")
 | 
						|
		So(string(byteData), ShouldEqual, `"HOUR"`)
 | 
						|
	})
 | 
						|
	Convey("logger split MarshalJSON", t, func() {
 | 
						|
		str, err := LogSplitHour.MarshalJSON()
 | 
						|
		So(err, ShouldBeNil)
 | 
						|
		So(string(str), ShouldEqual, `"HOUR"`)
 | 
						|
		dataList := []LogSplit{LogSplitHour}
 | 
						|
		jsonData, err := json.Marshal(dataList)
 | 
						|
		So(err, ShouldBeNil)
 | 
						|
		So(string(jsonData), ShouldEqual, `["HOUR"]`)
 | 
						|
	})
 | 
						|
}
 | 
						|
 | 
						|
func TestLogSplit_IsValid(t *testing.T) {
 | 
						|
	Convey("logger split 非法验证", t, func() {
 | 
						|
		So(LogSplit("Invalid").IsValid(), ShouldBeFalse)
 | 
						|
	})
 | 
						|
	Convey("logger split 合法验证", t, func() {
 | 
						|
		So(LogSplit("HOUR").IsValid(), ShouldBeTrue)
 | 
						|
	})
 | 
						|
}
 |