Browse Source

添加缓存测试

yjp 9 months ago
parent
commit
6f16c76750

+ 9 - 7
framework/core/infrastructure/infrastructure.go

@@ -21,13 +21,15 @@ type DatabaseConfig struct {
 }
 
 type CacheConfig struct {
-	Namespace string `json:"namespace" yaml:"namespace"`
-	Redis     *struct {
-		Address  string `json:"address" yaml:"address"`
-		UserName string `json:"user_name" yaml:"user_name"`
-		Password string `json:"password" yaml:"password"`
-		DB       int    `json:"db" yaml:"db"`
-	} `json:"redis" yaml:"redis"`
+	Namespace string       `json:"namespace" yaml:"namespace"`
+	Redis     *RedisConfig `json:"redis" yaml:"redis"`
+}
+
+type RedisConfig struct {
+	Address  string `json:"address" yaml:"address"`
+	UserName string `json:"user_name" yaml:"user_name"`
+	Password string `json:"password" yaml:"password"`
+	DB       int    `json:"db" yaml:"db"`
 }
 
 // Infrastructure 基础设施结构

+ 62 - 62
test/assign_tag_test.go

@@ -84,111 +84,111 @@ type AssignTagTo struct {
 
 func (to AssignTagTo) checkFields(t *testing.T, from AssignTagFrom) {
 	if from.StringField != to.StringField {
-		t.Fatalf("%+v", errors.Errorf("StringField not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("StringField not equal: from %v, to %v",
 			from.StringField, to.StringField))
 	}
 
 	if from.BoolField != to.BoolField {
-		t.Fatalf("%+v", errors.Errorf("BoolField not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("BoolField not equal: from %v, to %v",
 			from.BoolField, to.BoolField))
 	}
 
 	if from.Int8Field != to.Int8Field {
-		t.Fatalf("%+v", errors.Errorf("Int8Field not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("Int8Field not equal: from %v, to %v",
 			from.Int8Field, to.Int8Field))
 	}
 
 	if from.Int16Field != to.Int16Field {
-		t.Fatalf("%+v", errors.Errorf("Int16Field not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("Int16Field not equal: from %v, to %v",
 			from.Int16Field, to.Int16Field))
 	}
 
 	if from.Int32Field != to.Int32Field {
-		t.Fatalf("%+v", errors.Errorf("Int32Field not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("Int32Field not equal: from %v, to %v",
 			from.Int32Field, to.Int32Field))
 	}
 
 	if from.Int64Field != to.Int64Field {
-		t.Fatalf("%+v", errors.Errorf("Int64Field not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("Int64Field not equal: from %v, to %v",
 			from.Int64Field, to.Int64Field))
 	}
 
 	if from.Uint8Field != to.Uint8Field {
-		t.Fatalf("%+v", errors.Errorf("Uint8Field not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("Uint8Field not equal: from %v, to %v",
 			from.Uint8Field, to.Uint8Field))
 	}
 
 	if from.Uint16Field != to.Uint16Field {
-		t.Fatalf("%+v", errors.Errorf("Uint16Field not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("Uint16Field not equal: from %v, to %v",
 			from.Uint16Field, to.Uint16Field))
 	}
 
 	if from.Uint32Field != to.Uint32Field {
-		t.Fatalf("%+v", errors.Errorf("Uint32Field not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("Uint32Field not equal: from %v, to %v",
 			from.Uint32Field, to.Uint32Field))
 	}
 
 	if from.Uint64Field != to.Uint64Field {
-		t.Fatalf("%+v", errors.Errorf("Uint64Field not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("Uint64Field not equal: from %v, to %v",
 			from.Uint64Field, to.Uint64Field))
 	}
 
 	if from.Float32Field != to.Float32Field {
-		t.Fatalf("%+v", errors.Errorf("Float32Field not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("Float32Field not equal: from %v, to %v",
 			from.Float32Field, to.Float32Field))
 	}
 
 	if from.Float64Field != to.Float64Field {
-		t.Fatalf("%+v", errors.Errorf("Float64Field not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("Float64Field not equal: from %v, to %v",
 			from.Float64Field, to.Float64Field))
 	}
 
 	for i, value := range from.SliceField {
 		if value != to.SliceField[i] {
-			t.Fatalf("%+v", errors.Errorf("SliceField not equal: from %v, to %v",
+			t.Fatalf("%+v\n", errors.Errorf("SliceField not equal: from %v, to %v",
 				value, to.SliceField[i]))
 		}
 	}
 
 	for key, value := range from.MapField {
 		if value != to.MapField[key] {
-			t.Fatalf("%+v", errors.Errorf("MapField not equal: from %v, to %v",
+			t.Fatalf("%+v\n", errors.Errorf("MapField not equal: from %v, to %v",
 				value, to.MapField[key]))
 		}
 	}
 
 	if from.ChanField != to.ChanField {
-		t.Fatalf("%+v", errors.Errorf("ChanField not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("ChanField not equal: from %v, to %v",
 			from.ChanField, to.ChanField))
 	}
 
 	if from.FuncField() != to.FuncField() {
-		t.Fatalf("%+v", errors.Errorf("FuncField not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("FuncField not equal: from %v, to %v",
 			from.FuncField(), to.FuncField()))
 	}
 
 	if from.StructField.ID != to.StructField.ID {
-		t.Fatalf("%+v", errors.Errorf("StructField not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("StructField not equal: from %v, to %v",
 			from.StructField.ID, to.StructField.ID))
 	}
 
 	if strings.Join(from.FromStringSliceToStringField, "::") != to.FromStringSliceToStringField {
-		t.Fatalf("%+v", errors.Errorf("FromStringSliceToStringField not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("FromStringSliceToStringField not equal: from %v, to %v",
 			strings.Join(from.FromStringSliceToStringField, "::"), to.FromStringSliceToStringField))
 	}
 
 	if from.FromTimeToStringField.Format(time.DateTime) != to.FromTimeToStringField {
-		t.Fatalf("%+v", errors.Errorf("FromTimeToStringField not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("FromTimeToStringField not equal: from %v, to %v",
 			from.FromTimeToStringField.Format(time.DateTime), to.FromTimeToStringField))
 	}
 
 	if from.FromTimeToTimeField.Format(time.DateTime) != to.FromTimeToTimeField.Format(time.DateTime) {
-		t.Fatalf("%+v", errors.Errorf("FromTimeToTimeField not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("FromTimeToTimeField not equal: from %v, to %v",
 			from.FromTimeToTimeField.Format(time.DateTime), to.FromTimeToTimeField.Format(time.DateTime)))
 	}
 
 	if from.FromStringToTimeField != to.FromStringToTimeField.Format(time.DateTime) {
-		t.Fatalf("%+v", errors.Errorf("FromStringToTimeField not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("FromStringToTimeField not equal: from %v, to %v",
 			from.FromStringToTimeField, to.FromStringToTimeField.Format(time.DateTime)))
 	}
 }
@@ -219,111 +219,111 @@ type AssignTagToPointerField struct {
 
 func (to AssignTagToPointerField) checkFields(t *testing.T, from AssignTagFrom) {
 	if from.StringField != *to.StringField {
-		t.Fatalf("%+v", errors.Errorf("StringField not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("StringField not equal: from %v, to %v",
 			from.StringField, *to.StringField))
 	}
 
 	if from.BoolField != *to.BoolField {
-		t.Fatalf("%+v", errors.Errorf("BoolField not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("BoolField not equal: from %v, to %v",
 			from.BoolField, *to.BoolField))
 	}
 
 	if from.Int8Field != *to.Int8Field {
-		t.Fatalf("%+v", errors.Errorf("Int8Field not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("Int8Field not equal: from %v, to %v",
 			from.Int8Field, *to.Int8Field))
 	}
 
 	if from.Int16Field != *to.Int16Field {
-		t.Fatalf("%+v", errors.Errorf("Int16Field not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("Int16Field not equal: from %v, to %v",
 			from.Int16Field, *to.Int16Field))
 	}
 
 	if from.Int32Field != *to.Int32Field {
-		t.Fatalf("%+v", errors.Errorf("Int32Field not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("Int32Field not equal: from %v, to %v",
 			from.Int32Field, *to.Int32Field))
 	}
 
 	if from.Int64Field != *to.Int64Field {
-		t.Fatalf("%+v", errors.Errorf("Int64Field not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("Int64Field not equal: from %v, to %v",
 			from.Int64Field, *to.Int64Field))
 	}
 
 	if from.Uint8Field != *to.Uint8Field {
-		t.Fatalf("%+v", errors.Errorf("Uint8Field not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("Uint8Field not equal: from %v, to %v",
 			from.Uint8Field, *to.Uint8Field))
 	}
 
 	if from.Uint16Field != *to.Uint16Field {
-		t.Fatalf("%+v", errors.Errorf("Uint16Field not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("Uint16Field not equal: from %v, to %v",
 			from.Uint16Field, *to.Uint16Field))
 	}
 
 	if from.Uint32Field != *to.Uint32Field {
-		t.Fatalf("%+v", errors.Errorf("Uint32Field not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("Uint32Field not equal: from %v, to %v",
 			from.Uint32Field, *to.Uint32Field))
 	}
 
 	if from.Uint64Field != *to.Uint64Field {
-		t.Fatalf("%+v", errors.Errorf("Uint64Field not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("Uint64Field not equal: from %v, to %v",
 			from.Uint64Field, *to.Uint64Field))
 	}
 
 	if from.Float32Field != *to.Float32Field {
-		t.Fatalf("%+v", errors.Errorf("Float32Field not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("Float32Field not equal: from %v, to %v",
 			from.Float32Field, *to.Float32Field))
 	}
 
 	if from.Float64Field != *to.Float64Field {
-		t.Fatalf("%+v", errors.Errorf("Float64Field not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("Float64Field not equal: from %v, to %v",
 			from.Float64Field, *to.Float64Field))
 	}
 
 	for i, value := range from.SliceField {
 		if value != (*to.SliceField)[i] {
-			t.Fatalf("%+v", errors.Errorf("SliceField not equal: from %v, to %v",
+			t.Fatalf("%+v\n", errors.Errorf("SliceField not equal: from %v, to %v",
 				value, (*to.SliceField)[i]))
 		}
 	}
 
 	for key, value := range from.MapField {
 		if value != (*to.MapField)[key] {
-			t.Fatalf("%+v", errors.Errorf("MapField not equal: from %v, to %v",
+			t.Fatalf("%+v\n", errors.Errorf("MapField not equal: from %v, to %v",
 				value, (*to.MapField)[key]))
 		}
 	}
 
 	if from.ChanField != *to.ChanField {
-		t.Fatalf("%+v", errors.Errorf("ChanField not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("ChanField not equal: from %v, to %v",
 			from.ChanField, *to.ChanField))
 	}
 
 	if from.FuncField() != (*to.FuncField)() {
-		t.Fatalf("%+v", errors.Errorf("FuncField not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("FuncField not equal: from %v, to %v",
 			from.FuncField(), (*to.FuncField)()))
 	}
 
 	if from.StructField.ID != (*to.StructField).ID {
-		t.Fatalf("%+v", errors.Errorf("StructField not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("StructField not equal: from %v, to %v",
 			from.StructField.ID, (*to.StructField).ID))
 	}
 
 	if strings.Join(from.FromStringSliceToStringField, "::") != *to.FromStringSliceToStringField {
-		t.Fatalf("%+v", errors.Errorf("FromStringSliceToStringField not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("FromStringSliceToStringField not equal: from %v, to %v",
 			strings.Join(from.FromStringSliceToStringField, "::"), to.FromStringSliceToStringField))
 	}
 
 	if from.FromTimeToStringField.Format(time.DateTime) != *to.FromTimeToStringField {
-		t.Fatalf("%+v", errors.Errorf("FromTimeToStringField not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("FromTimeToStringField not equal: from %v, to %v",
 			from.FromTimeToStringField.Format(time.DateTime), to.FromTimeToStringField))
 	}
 
 	if from.FromTimeToTimeField.Format(time.DateTime) != (*to.FromTimeToTimeField).Format(time.DateTime) {
-		t.Fatalf("%+v", errors.Errorf("FromTimeToTimeField not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("FromTimeToTimeField not equal: from %v, to %v",
 			from.FromTimeToTimeField.Format(time.DateTime), (*to.FromTimeToTimeField).Format(time.DateTime)))
 	}
 
 	if from.FromStringToTimeField != (*to.FromStringToTimeField).Format(time.DateTime) {
-		t.Fatalf("%+v", errors.Errorf("FromStringToTimeField not equal: from %v, to %v",
+		t.Fatalf("%+v\n", errors.Errorf("FromStringToTimeField not equal: from %v, to %v",
 			from.FromStringToTimeField, (*to.FromStringToTimeField).Format(time.DateTime)))
 	}
 }
@@ -407,120 +407,120 @@ func TestAssignTagDefaultUsage(t *testing.T) {
 
 	err := assign.DefaultUsage(from, to)
 	if err == nil || err.Error() != "返回类型不是结构指针" {
-		t.Fatalf("%+v", errors.Errorf("没有检测出to参数必须是指针类型"))
+		t.Fatalf("%+v\n", errors.Errorf("没有检测出to参数必须是指针类型"))
 	}
 
 	err = assign.DefaultUsage(from, toPointer)
 	if err == nil || err.Error() != "返回类型不是结构指针" {
-		t.Fatalf("%+v", errors.Errorf("没有检测出to参数必须是指针类型"))
+		t.Fatalf("%+v\n", errors.Errorf("没有检测出to参数必须是指针类型"))
 	}
 
 	err = assign.DefaultUsage(fromPointer, to)
 	if err == nil || err.Error() != "返回类型不是结构指针" {
-		t.Fatalf("%+v", errors.Errorf("没有检测出to参数必须是指针类型"))
+		t.Fatalf("%+v\n", errors.Errorf("没有检测出to参数必须是指针类型"))
 	}
 
 	err = assign.DefaultUsage(fromPointer, toPointer)
 	if err == nil || err.Error() != "返回类型不是结构指针" {
-		t.Fatalf("%+v", errors.Errorf("没有检测出to参数必须是指针类型"))
+		t.Fatalf("%+v\n", errors.Errorf("没有检测出to参数必须是指针类型"))
 	}
 
 	err = assign.DefaultUsage(from, &to)
 	if err != nil {
-		t.Fatalf("%+v", err)
+		t.Fatalf("%+v\n", err)
 	}
 
 	to.checkFields(t, from)
 
 	err = assign.DefaultUsage(from, &toPointer)
 	if err != nil {
-		t.Fatalf("%+v", err)
+		t.Fatalf("%+v\n", err)
 	}
 
 	toPointer.checkFields(t, from)
 
 	err = assign.DefaultUsage(fromPointer, &to)
 	if err != nil {
-		t.Fatalf("%+v", err)
+		t.Fatalf("%+v\n", err)
 	}
 
 	to.checkFields(t, from)
 
 	err = assign.DefaultUsage(fromPointer, &toPointer)
 	if err != nil {
-		t.Fatalf("%+v", err)
+		t.Fatalf("%+v\n", err)
 	}
 
 	toPointer.checkFields(t, from)
 
 	err = assign.DefaultUsage(&from, to)
 	if err == nil || err.Error() != "返回类型不是结构指针" {
-		t.Fatalf("%+v", errors.Errorf("没有检测出to参数必须是指针类型"))
+		t.Fatalf("%+v\n", errors.Errorf("没有检测出to参数必须是指针类型"))
 	}
 
 	err = assign.DefaultUsage(&from, toPointer)
 	if err == nil || err.Error() != "返回类型不是结构指针" {
-		t.Fatalf("%+v", errors.Errorf("没有检测出to参数必须是指针类型"))
+		t.Fatalf("%+v\n", errors.Errorf("没有检测出to参数必须是指针类型"))
 	}
 
 	err = assign.DefaultUsage(&fromPointer, to)
 	if err == nil || err.Error() != "返回类型不是结构指针" {
-		t.Fatalf("%+v", errors.Errorf("没有检测出to参数必须是指针类型"))
+		t.Fatalf("%+v\n", errors.Errorf("没有检测出to参数必须是指针类型"))
 	}
 
 	err = assign.DefaultUsage(&fromPointer, toPointer)
 	if err == nil || err.Error() != "返回类型不是结构指针" {
-		t.Fatalf("%+v", errors.Errorf("没有检测出to参数必须是指针类型"))
+		t.Fatalf("%+v\n", errors.Errorf("没有检测出to参数必须是指针类型"))
 	}
 
 	err = assign.DefaultUsage(&from, &to)
 	if err != nil {
-		t.Fatalf("%+v", err)
+		t.Fatalf("%+v\n", err)
 	}
 
 	to.checkFields(t, from)
 
 	err = assign.DefaultUsage(&from, &toPointer)
 	if err != nil {
-		t.Fatalf("%+v", err)
+		t.Fatalf("%+v\n", err)
 	}
 
 	toPointer.checkFields(t, from)
 
 	err = assign.DefaultUsage(&fromPointer, &to)
 	if err != nil {
-		t.Fatalf("%+v", err)
+		t.Fatalf("%+v\n", err)
 	}
 
 	to.checkFields(t, from)
 
 	err = assign.DefaultUsage(&fromPointer, &toPointer)
 	if err != nil {
-		t.Fatalf("%+v", err)
+		t.Fatalf("%+v\n", err)
 	}
 
 	toPointer.checkFields(t, from)
 
 	err = assign.DefaultUsage(fromPointerNil, &to)
 	if err == nil || err.Error() != "无法设置值,请检查是否传递的是非指针结构变量且字段为nil" {
-		t.Fatalf("%+v", errors.Errorf("没有检测出from如果有nil字段,必须使用指针结构变量"))
+		t.Fatalf("%+v\n", errors.Errorf("没有检测出from如果有nil字段,必须使用指针结构变量"))
 	}
 
 	err = assign.DefaultUsage(fromPointerNil, &toPointer)
 	if err == nil || err.Error() != "无法设置值,请检查是否传递的是非指针结构变量且字段为nil" {
-		t.Fatalf("%+v", errors.Errorf("没有检测出from如果有nil字段,必须使用指针结构变量"))
+		t.Fatalf("%+v\n", errors.Errorf("没有检测出from如果有nil字段,必须使用指针结构变量"))
 	}
 
 	err = assign.DefaultUsage(&fromPointerNil, &to)
 	if err != nil {
-		t.Fatalf("%+v", err)
+		t.Fatalf("%+v\n", err)
 	}
 
 	to.checkFields(t, from)
 
 	err = assign.DefaultUsage(&fromPointerNil, &toPointer)
 	if err != nil {
-		t.Fatalf("%+v", err)
+		t.Fatalf("%+v\n", err)
 	}
 
 	toPointer.checkFields(t, from)

+ 233 - 0
test/cache_test.go

@@ -0,0 +1,233 @@
+package test
+
+import (
+	"git.sxidc.com/go-framework/baize/framework/core/infrastructure"
+	"git.sxidc.com/go-framework/baize/framework/core/infrastructure/cache/local"
+	"git.sxidc.com/go-framework/baize/framework/core/infrastructure/cache/redis"
+	"git.sxidc.com/go-tools/utils/strutils"
+	"testing"
+	"time"
+)
+
+func TestLocalCache(t *testing.T) {
+	cache := local.New("test")
+	testLocalCache(t, cache)
+}
+
+func TestRedisCache(t *testing.T) {
+	cache, err := redis.New("localhost:30379", "", "mtyzxhc", 1, "test")
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	testRedisCache(t, cache)
+}
+
+func TestCacheInfrastructure(t *testing.T) {
+	i := infrastructure.NewInfrastructure(infrastructure.Config{
+		CacheConfig: infrastructure.CacheConfig{
+			Namespace: "test",
+			Redis: &infrastructure.RedisConfig{
+				Address:  "localhost:30379",
+				UserName: "",
+				Password: "mtyzxhc",
+				DB:       1,
+			},
+		},
+	})
+
+	testLocalCache(t, i.LocalCache().(*local.Cache))
+	testRedisCache(t, i.RedisCache().(*redis.Cache))
+}
+
+func testLocalCache(t *testing.T, cache *local.Cache) {
+	err := cache.Set("test1", "test1-value", 0)
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	test1Value, err := cache.Get("test1")
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	if test1Value != "test1-value" {
+		t.Fatalf("Value Error: cache %v\n", test1Value)
+	}
+
+	err = cache.Set("test2", "test2-value", 0)
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	multiValues, err := cache.GetMulti([]string{"test1", "test2"})
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	if len(multiValues) != 2 {
+		t.Fatalf("Value Error: cache %v\n", multiValues)
+	}
+
+	if multiValues["test1"] != "test1-value" || multiValues["test2"] != "test2-value" {
+		t.Fatalf("Value Error: cache %v\n", multiValues)
+	}
+
+	allValues, err := cache.GetAll()
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	if len(allValues) != 2 {
+		t.Fatalf("Value Error: cache %v\n", allValues)
+	}
+
+	if allValues["test1"] != "test1-value" || allValues["test2"] != "test2-value" {
+		t.Fatalf("Value Error: cache %v\n", allValues)
+	}
+
+	err = cache.Delete("test2")
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	test2Value, err := cache.Get("test2")
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	if strutils.IsStringNotEmpty(test2Value) {
+		t.Fatalf("Delete Value Error: cache %v\n", test2Value)
+	}
+
+	err = cache.Clear()
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	allValues, err = cache.GetAll()
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	if len(allValues) != 0 {
+		t.Fatalf("Clear Value Error: cache %v\n", allValues)
+	}
+
+	err = cache.Set("test", "test-value", 1)
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	time.Sleep(1500 * time.Millisecond)
+
+	testValue, err := cache.Get("test")
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	if strutils.IsStringNotEmpty(testValue) {
+		t.Fatalf("Value Expire Error: cache %v\n", testValue)
+	}
+
+	err = cache.Clear()
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+}
+
+func testRedisCache(t *testing.T, cache *redis.Cache) {
+	err := cache.Set("test1", "test1-value", 0)
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	test1Value, err := cache.Get("test1")
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	if test1Value != "test1-value" {
+		t.Fatalf("Value Error: cache %v\n", test1Value)
+	}
+
+	err = cache.Set("test2", "test2-value", 0)
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	multiValues, err := cache.GetMulti([]string{"test1", "test2"})
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	if len(multiValues) != 2 {
+		t.Fatalf("Value Error: cache %v\n", multiValues)
+	}
+
+	if multiValues["test1"] != "test1-value" || multiValues["test2"] != "test2-value" {
+		t.Fatalf("Value Error: cache %v\n", multiValues)
+	}
+
+	allValues, err := cache.GetAll()
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	if len(allValues) != 2 {
+		t.Fatalf("Value Error: cache %v\n", allValues)
+	}
+
+	if allValues["test1"] != "test1-value" || allValues["test2"] != "test2-value" {
+		t.Fatalf("Value Error: cache %v\n", allValues)
+	}
+
+	err = cache.Delete("test2")
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	test2Value, err := cache.Get("test2")
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	if strutils.IsStringNotEmpty(test2Value) {
+		t.Fatalf("Delete Value Error: cache %v\n", test2Value)
+	}
+
+	err = cache.Clear()
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	allValues, err = cache.GetAll()
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	if len(allValues) != 0 {
+		t.Fatalf("Clear Value Error: cache %v\n", allValues)
+	}
+
+	err = cache.Set("test", "test-value", 1)
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	time.Sleep(1500 * time.Millisecond)
+
+	testValue, err := cache.Get("test")
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	if strutils.IsStringNotEmpty(testValue) {
+		t.Fatalf("Value Expire Error: cache %v\n", testValue)
+	}
+
+	err = cache.Clear()
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+}

+ 8 - 8
test/check_tag_test.go

@@ -37,48 +37,48 @@ func TestCustomCheckTag(t *testing.T) {
 	err := check.Struct(customCheckTagStruct, fieldMap).
 		CheckFields("Time")
 	if err != nil {
-		t.Fatalf("%+v", err)
+		t.Fatalf("%+v\n", err)
 	}
 
 	err = check.Struct(customCheckTagPointerStruct, fieldMap).
 		CheckFields("Time")
 	if err != nil {
-		t.Fatalf("%+v", err)
+		t.Fatalf("%+v\n", err)
 	}
 
 	err = check.Struct(&customCheckTagStruct, fieldMap).
 		CheckFields("Time")
 	if err != nil {
-		t.Fatalf("%+v", err)
+		t.Fatalf("%+v\n", err)
 	}
 
 	err = check.Struct(&customCheckTagPointerStruct, fieldMap).
 		CheckFields("Time")
 	if err != nil {
-		t.Fatalf("%+v", err)
+		t.Fatalf("%+v\n", err)
 	}
 
 	err = check.Struct(customCheckTagStructZero, fieldMap).
 		CheckFields("Time")
 	if err == nil || !strings.Contains(err.Error(), "使用了时间零值") {
-		t.Fatalf("%+v", errors.New("没有检测出使用了时间零值"))
+		t.Fatalf("%+v\n", errors.New("没有检测出使用了时间零值"))
 	}
 
 	err = check.Struct(customCheckTagPointerStructZero, fieldMap).
 		CheckFields("Time")
 	if err == nil || !strings.Contains(err.Error(), "使用了时间零值") {
-		t.Fatalf("%+v", errors.New("没有检测出使用了时间零值"))
+		t.Fatalf("%+v\n", errors.New("没有检测出使用了时间零值"))
 	}
 
 	err = check.Struct(&customCheckTagStructZero, fieldMap).
 		CheckFields("Time")
 	if err == nil || !strings.Contains(err.Error(), "使用了时间零值") {
-		t.Fatalf("%+v", errors.Errorf(err.Error()))
+		t.Fatalf("%+v\n", errors.Errorf(err.Error()))
 	}
 
 	err = check.Struct(&customCheckTagPointerStructZero, fieldMap).
 		CheckFields("Time")
 	if err == nil || !strings.Contains(err.Error(), "使用了时间零值") {
-		t.Fatalf("%+v", errors.Errorf(err.Error()))
+		t.Fatalf("%+v\n", errors.Errorf(err.Error()))
 	}
 }

+ 75 - 75
test/sql_mapping_tag_test.go

@@ -31,174 +31,174 @@ type SqlMappingTagStruct struct {
 
 func (s SqlMappingTagStruct) checkFields(t *testing.T, fields []sql_mapping.Field) {
 	if len(fields) != reflect.TypeOf(s).NumField()-1 {
-		t.Fatalf("%+v", errors.Errorf("有字段没有被解析"))
+		t.Fatalf("%+v\n", errors.Errorf("有字段没有被解析"))
 	}
 
 	for _, field := range fields {
 		if field.FieldName == "Ignore" || field.ColumnName == "ignore" {
-			t.Fatalf("%+v", errors.Errorf("忽略字段没有被忽略"))
+			t.Fatalf("%+v\n", errors.Errorf("忽略字段没有被忽略"))
 		}
 
 		switch field.FieldName {
 		case "Column":
 			if s.Column != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确: fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, s.Column, field.Value))
 			}
 
 			if field.ColumnName != "test_column" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 		case "Key":
 			if field.ColumnName != "key" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			if s.Key != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确: fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, s.Key, field.Value))
 			}
 
 			if !field.IsKey {
-				t.Fatalf("%+v", errors.Errorf("key解析错误"))
+				t.Fatalf("%+v\n", errors.Errorf("key解析错误"))
 			}
 		case "NotUpdate":
 			if field.ColumnName != "not_update" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			if s.NotUpdate != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, s.NotUpdate, field.Value))
 			}
 
 			if field.CanUpdate {
-				t.Fatalf("%+v", errors.Errorf("notUpdate解析错误"))
+				t.Fatalf("%+v\n", errors.Errorf("notUpdate解析错误"))
 			}
 		case "UpdateClear":
 			if field.ColumnName != "update_clear" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			if s.UpdateClear != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, s.UpdateClear, field.Value))
 			}
 
 			if !field.CanUpdateClear {
-				t.Fatalf("%+v", errors.Errorf("updateClear解析错误"))
+				t.Fatalf("%+v\n", errors.Errorf("updateClear解析错误"))
 			}
 		case "Aes":
 			if field.ColumnName != "aes" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			encrypted, err := encoding.AESEncrypt(s.Aes, "@MKU^*HF%p%G43Fd)UAHCVD#$XZSWQ@L")
 			if err != nil {
-				t.Fatalf("%+v", errors.Errorf(err.Error()))
+				t.Fatalf("%+v\n", errors.Errorf(err.Error()))
 			}
 
 			if encrypted != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, encrypted, field.Value))
 			}
 		case "JoinWith":
 			if field.ColumnName != "join_with" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			if strings.Join(s.JoinWith, "##") != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确: fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, strings.Join(s.JoinWith, "##"), field.Value))
 			}
 		case "Trim":
 			if field.ColumnName != "trim" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			if strings.Trim(s.Trim, "||") != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, strings.Trim(s.Trim, "||"), field.Value))
 			}
 		case "TrimPrefix":
 			if field.ColumnName != "trim_prefix" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			if strings.TrimPrefix(s.TrimPrefix, "{{") != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, strings.TrimPrefix(s.TrimPrefix, "{{"), field.Value))
 			}
 		case "TrimSuffix":
 			if field.ColumnName != "trim_suffix" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			if strings.TrimSuffix(s.TrimSuffix, "}}") != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, strings.TrimSuffix(s.TrimPrefix, "}}"), field.Value))
 			}
 		case "WrongAes":
 			if field.ColumnName != "wrong_aes" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			if s.WrongAes != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, s.WrongAes, field.Value))
 			}
 		case "WrongJoinWith":
 			if field.ColumnName != "wrong_join_with" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			if s.WrongJoinWith != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, s.WrongJoinWith, field.Value))
 			}
 		case "WrongTrim":
 			if field.ColumnName != "wrong_trim" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			if s.WrongTrim != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, s.WrongTrim, field.Value))
 			}
 		case "WrongTrimPrefix":
 			if field.ColumnName != "wrong_trim_prefix" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			if s.WrongTrimPrefix != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, s.WrongTrimPrefix, field.Value))
 			}
 		case "WrongTrimSuffix":
 			if field.ColumnName != "wrong_trim_suffix" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			if s.WrongTrimSuffix != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, s.WrongTrimPrefix, field.Value))
 			}
 		default:
-			t.Fatalf("%+v", errors.Errorf("未知的字段名: tag fieldName: %v", field.FieldName))
+			t.Fatalf("%+v\n", errors.Errorf("未知的字段名: tag fieldName: %v", field.FieldName))
 		}
 	}
 }
@@ -224,169 +224,169 @@ type SqlMappingTagPointerFieldsStruct struct {
 func (s SqlMappingTagPointerFieldsStruct) checkFields(t *testing.T, fields []sql_mapping.Field) {
 	for _, field := range fields {
 		if field.FieldName == "Ignore" || field.ColumnName == "ignore" {
-			t.Fatalf("%+v", errors.Errorf("忽略字段没有被忽略"))
+			t.Fatalf("%+v\n", errors.Errorf("忽略字段没有被忽略"))
 		}
 
 		switch field.FieldName {
 		case "Column":
 			if *s.Column != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, s.Column, field.Value))
 			}
 
 			if field.ColumnName != "test_column" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 		case "Key":
 			if field.ColumnName != "key" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			if *s.Key != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确: fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, s.Key, field.Value))
 			}
 
 			if !field.IsKey {
-				t.Fatalf("%+v", errors.Errorf("key解析错误"))
+				t.Fatalf("%+v\n", errors.Errorf("key解析错误"))
 			}
 		case "NotUpdate":
 			if field.ColumnName != "not_update" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			if *s.NotUpdate != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, s.NotUpdate, field.Value))
 			}
 
 			if field.CanUpdate {
-				t.Fatalf("%+v", errors.Errorf("notUpdate解析错误"))
+				t.Fatalf("%+v\n", errors.Errorf("notUpdate解析错误"))
 			}
 		case "UpdateClear":
 			if field.ColumnName != "update_clear" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			if *s.UpdateClear != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, s.UpdateClear, field.Value))
 			}
 
 			if !field.CanUpdateClear {
-				t.Fatalf("%+v", errors.Errorf("updateClear解析错误"))
+				t.Fatalf("%+v\n", errors.Errorf("updateClear解析错误"))
 			}
 		case "Aes":
 			if field.ColumnName != "aes" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			encrypted, err := encoding.AESEncrypt(*s.Aes, "@MKU^*HF%p%G43Fd)UAHCVD#$XZSWQ@L")
 			if err != nil {
-				t.Fatalf("%+v", errors.Errorf(err.Error()))
+				t.Fatalf("%+v\n", errors.Errorf(err.Error()))
 			}
 
 			if encrypted != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, encrypted, field.Value))
 			}
 		case "JoinWith":
 			if field.ColumnName != "join_with" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			if strings.Join(*s.JoinWith, "##") != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确: fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, strings.Join(*s.JoinWith, "##"), field.Value))
 			}
 		case "Trim":
 			if field.ColumnName != "trim" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			if strings.Trim(*s.Trim, "||") != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, strings.Trim(*s.Trim, "||"), field.Value))
 			}
 		case "TrimPrefix":
 			if field.ColumnName != "trim_prefix" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			if strings.TrimPrefix(*s.TrimPrefix, "{{") != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, strings.TrimPrefix(*s.TrimPrefix, "{{"), field.Value))
 			}
 		case "TrimSuffix":
 			if field.ColumnName != "trim_suffix" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			if strings.TrimSuffix(*s.TrimSuffix, "}}") != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, strings.TrimSuffix(*s.TrimPrefix, "}}"), field.Value))
 			}
 		case "WrongAes":
 			if field.ColumnName != "wrong_aes" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			if *s.WrongAes != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, s.WrongAes, field.Value))
 			}
 		case "WrongJoinWith":
 			if field.ColumnName != "wrong_join_with" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			if *s.WrongJoinWith != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, s.WrongJoinWith, field.Value))
 			}
 		case "WrongTrim":
 			if field.ColumnName != "wrong_trim" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			if *s.WrongTrim != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, s.WrongTrim, field.Value))
 			}
 		case "WrongTrimPrefix":
 			if field.ColumnName != "wrong_trim_prefix" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			if *s.WrongTrimPrefix != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, s.WrongTrimPrefix, field.Value))
 			}
 		case "WrongTrimSuffix":
 			if field.ColumnName != "wrong_trim_suffix" {
-				t.Fatalf("%+v", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
+				t.Fatalf("%+v\n", errors.Errorf("列名解析测试错误: fieldName: %v, actual columnName: %v",
 					field.FieldName, field.ColumnName))
 			}
 
 			if *s.WrongTrimSuffix != field.Value {
-				t.Fatalf("%+v", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确:fieldName: %v, fieldValue %v, tagValue %v",
 					field.FieldName, s.WrongTrimPrefix, field.Value))
 			}
 		default:
-			t.Fatalf("%+v", errors.Errorf("未知的字段名: tag fieldName: %v", field.FieldName))
+			t.Fatalf("%+v\n", errors.Errorf("未知的字段名: tag fieldName: %v", field.FieldName))
 		}
 	}
 }
@@ -448,40 +448,40 @@ func TestSqlMappingTagDefaultUsage(t *testing.T) {
 
 	fields, err := sql_mapping.DefaultUsage(s)
 	if err != nil {
-		t.Fatalf("%+v", err)
+		t.Fatalf("%+v\n", err)
 	}
 
 	s.checkFields(t, fields)
 
 	fields, err = sql_mapping.DefaultUsage(&s)
 	if err != nil {
-		t.Fatalf("%+v", err)
+		t.Fatalf("%+v\n", err)
 	}
 
 	s.checkFields(t, fields)
 
 	fields, err = sql_mapping.DefaultUsage(sPointerFields)
 	if err != nil {
-		t.Fatalf("%+v", err)
+		t.Fatalf("%+v\n", err)
 	}
 
 	sPointerFields.checkFields(t, fields)
 
 	fields, err = sql_mapping.DefaultUsage(&sPointerFields)
 	if err != nil {
-		t.Fatalf("%+v", err)
+		t.Fatalf("%+v\n", err)
 	}
 
 	sPointerFields.checkFields(t, fields)
 
 	fields, err = sql_mapping.DefaultUsage(sPointerFieldsNil)
 	if err == nil || err.Error() != "无法设置值,请检查是否传递的是非指针结构变量且字段为nil" {
-		t.Fatalf("%+v", errors.Errorf("没有检测出from如果有nil字段,必须使用指针结构变量"))
+		t.Fatalf("%+v\n", errors.Errorf("没有检测出from如果有nil字段,必须使用指针结构变量"))
 	}
 
 	fields, err = sql_mapping.DefaultUsage(&sPointerFieldsNil)
 	if err != nil {
-		t.Fatalf("%+v", err)
+		t.Fatalf("%+v\n", err)
 	}
 
 	sPointerFieldsNil.checkFields(t, fields)

+ 39 - 39
test/sql_result_tag_test.go

@@ -31,25 +31,25 @@ type SqlResultTagStruct struct {
 
 func (s SqlResultTagStruct) checkFields(t *testing.T, result map[string]any) {
 	if len(result) != reflect.TypeOf(s).NumField()-1 {
-		t.Fatalf("%+v", errors.Errorf("有字段没有被解析"))
+		t.Fatalf("%+v\n", errors.Errorf("有字段没有被解析"))
 	}
 
 	for columnName, value := range result {
 		if columnName == "ignore" {
-			t.Fatalf("%+v", errors.Errorf("忽略字段没有被忽略"))
+			t.Fatalf("%+v\n", errors.Errorf("忽略字段没有被忽略"))
 		}
 
 		switch columnName {
 		case "test_column":
 			if s.Column != value {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, s.Column, value))
 			}
 		case "time_layout":
 			resultValue := value.(string)
 
 			if s.TimeLayout.Format(time.DateOnly)+"T00:00:00" != resultValue {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, s.TimeLayout.Format(time.DateOnly), resultValue))
 			}
 		case "aes":
@@ -57,85 +57,85 @@ func (s SqlResultTagStruct) checkFields(t *testing.T, result map[string]any) {
 
 			decrypted, err := encoding.AESDecrypt(resultValue, "@MKU^*HF%p%G43Fd)UAHCVD#$XZSWQ@L")
 			if err != nil {
-				t.Fatalf("%+v", errors.Errorf(err.Error()))
+				t.Fatalf("%+v\n", errors.Errorf(err.Error()))
 			}
 
 			if s.Aes != decrypted {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, s.Aes, decrypted))
 			}
 		case "split_with":
 			resultValue := value.(string)
 
 			if strings.Join(s.SplitWith, "##") != resultValue {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, strings.Join(s.SplitWith, "##"), resultValue))
 			}
 		case "trim":
 			resultValue := value.(string)
 
 			if s.Trim != strings.Trim(resultValue, "||") {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, s.Trim, strings.Trim(resultValue, "||")))
 			}
 		case "trim_prefix":
 			resultValue := value.(string)
 
 			if s.TrimPrefix != strings.TrimPrefix(resultValue, "{{") {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, s.TrimPrefix, strings.TrimPrefix(resultValue, "{{")))
 			}
 		case "trim_suffix":
 			resultValue := value.(string)
 
 			if s.TrimSuffix != strings.TrimSuffix(resultValue, "}}") {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, s.TrimSuffix, strings.TrimSuffix(resultValue, "}}")))
 			}
 		case "wrong_time_layout":
 			resultValue := value.(int)
 
 			if s.WrongTimeLayout != resultValue {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, s.WrongTimeLayout, resultValue))
 			}
 		case "wrong_aes":
 			resultValue := value.(int)
 
 			if s.WrongAes != resultValue {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, s.WrongAes, resultValue))
 			}
 		case "wrong_split_with":
 			resultValue := value.(int)
 
 			if s.WrongSplitWith != resultValue {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, s.WrongSplitWith, resultValue))
 			}
 		case "wrong_trim":
 			resultValue := value.(int)
 
 			if s.WrongTrim != resultValue {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, s.WrongTrim, resultValue))
 			}
 		case "wrong_trim_prefix":
 			resultValue := value.(int)
 
 			if s.WrongTrimPrefix != resultValue {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, s.WrongTrimPrefix, resultValue))
 			}
 		case "wrong_trim_suffix":
 			resultValue := value.(int)
 
 			if s.WrongTrimSuffix != resultValue {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, s.WrongTrimSuffix, resultValue))
 			}
 		default:
-			t.Fatalf("%+v", errors.Errorf("未知的列: tag columnName: %v", columnName))
+			t.Fatalf("%+v\n", errors.Errorf("未知的列: tag columnName: %v", columnName))
 		}
 	}
 }
@@ -159,25 +159,25 @@ type SqlResultTagPointFieldsStruct struct {
 
 func (s SqlResultTagPointFieldsStruct) checkFields(t *testing.T, result map[string]any) {
 	if len(result) != reflect.TypeOf(s).NumField()-1 {
-		t.Fatalf("%+v", errors.Errorf("有字段没有被解析"))
+		t.Fatalf("%+v\n", errors.Errorf("有字段没有被解析"))
 	}
 
 	for columnName, value := range result {
 		if columnName == "ignore" {
-			t.Fatalf("%+v", errors.Errorf("忽略字段没有被忽略"))
+			t.Fatalf("%+v\n", errors.Errorf("忽略字段没有被忽略"))
 		}
 
 		switch columnName {
 		case "test_column":
 			if *s.Column != value {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, *s.Column, value))
 			}
 		case "time_layout":
 			resultValue := value.(string)
 
 			if (*s.TimeLayout).Format(time.DateOnly)+"T00:00:00" != resultValue {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, (*s.TimeLayout).Format(time.DateOnly), resultValue))
 			}
 		case "aes":
@@ -185,85 +185,85 @@ func (s SqlResultTagPointFieldsStruct) checkFields(t *testing.T, result map[stri
 
 			decrypted, err := encoding.AESDecrypt(resultValue, "@MKU^*HF%p%G43Fd)UAHCVD#$XZSWQ@L")
 			if err != nil {
-				t.Fatalf("%+v", errors.Errorf(err.Error()))
+				t.Fatalf("%+v\n", errors.Errorf(err.Error()))
 			}
 
 			if *s.Aes != decrypted {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, *s.Aes, decrypted))
 			}
 		case "split_with":
 			resultValue := value.(string)
 
 			if strings.Join(*s.SplitWith, "##") != resultValue {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, strings.Join(*s.SplitWith, "##"), resultValue))
 			}
 		case "trim":
 			resultValue := value.(string)
 
 			if *s.Trim != strings.Trim(resultValue, "||") {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, s.Trim, strings.Trim(resultValue, "||")))
 			}
 		case "trim_prefix":
 			resultValue := value.(string)
 
 			if *s.TrimPrefix != strings.TrimPrefix(resultValue, "{{") {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, s.TrimPrefix, strings.TrimPrefix(resultValue, "{{")))
 			}
 		case "trim_suffix":
 			resultValue := value.(string)
 
 			if *s.TrimSuffix != strings.TrimSuffix(resultValue, "}}") {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, s.TrimSuffix, strings.TrimSuffix(resultValue, "}}")))
 			}
 		case "wrong_time_layout":
 			resultValue := value.(int)
 
 			if *s.WrongTimeLayout != resultValue {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, s.WrongTimeLayout, resultValue))
 			}
 		case "wrong_aes":
 			resultValue := value.(int)
 
 			if *s.WrongAes != resultValue {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, s.WrongAes, resultValue))
 			}
 		case "wrong_split_with":
 			resultValue := value.(int)
 
 			if *s.WrongSplitWith != resultValue {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, s.WrongSplitWith, resultValue))
 			}
 		case "wrong_trim":
 			resultValue := value.(int)
 
 			if *s.WrongTrim != resultValue {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, s.WrongTrim, resultValue))
 			}
 		case "wrong_trim_prefix":
 			resultValue := value.(int)
 
 			if *s.WrongTrimPrefix != resultValue {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, s.WrongTrimPrefix, resultValue))
 			}
 		case "wrong_trim_suffix":
 			resultValue := value.(int)
 
 			if *s.WrongTrimSuffix != resultValue {
-				t.Fatalf("%+v", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
+				t.Fatalf("%+v\n", errors.Errorf("值不正确: columnName: %v, fieldValue %v, resultValue %v",
 					columnName, s.WrongTrimSuffix, resultValue))
 			}
 		default:
-			t.Fatalf("%+v", errors.Errorf("未知的列: tag columnName: %v", columnName))
+			t.Fatalf("%+v\n", errors.Errorf("未知的列: tag columnName: %v", columnName))
 		}
 	}
 }
@@ -271,7 +271,7 @@ func (s SqlResultTagPointFieldsStruct) checkFields(t *testing.T, result map[stri
 func TestSqlResultTagDefaultUsage(t *testing.T) {
 	aesEncrypted, err := encoding.AESEncrypt(strutils.SimpleUUID(), "@MKU^*HF%p%G43Fd)UAHCVD#$XZSWQ@L")
 	if err != nil {
-		t.Fatalf("%+v", errors.Errorf(err.Error()))
+		t.Fatalf("%+v\n", errors.Errorf(err.Error()))
 	}
 
 	result := map[string]any{
@@ -295,24 +295,24 @@ func TestSqlResultTagDefaultUsage(t *testing.T) {
 
 	err = sql_result.DefaultUsage(result, s, "")
 	if err == nil || err.Error() != "参数不是结构指针" {
-		t.Fatalf("%+v", errors.Errorf("没有检测出参数必须是指针类型"))
+		t.Fatalf("%+v\n", errors.Errorf("没有检测出参数必须是指针类型"))
 	}
 
 	err = sql_result.DefaultUsage(result, sPointerField, "")
 	if err == nil || err.Error() != "参数不是结构指针" {
-		t.Fatalf("%+v", errors.Errorf("没有检测出参数必须是指针类型"))
+		t.Fatalf("%+v\n", errors.Errorf("没有检测出参数必须是指针类型"))
 	}
 
 	err = sql_result.DefaultUsage(result, &s, "")
 	if err != nil {
-		t.Fatalf("%+v", err)
+		t.Fatalf("%+v\n", err)
 	}
 
 	s.checkFields(t, result)
 
 	err = sql_result.DefaultUsage(result, &sPointerField, "")
 	if err != nil {
-		t.Fatalf("%+v", err)
+		t.Fatalf("%+v\n", err)
 	}
 
 	sPointerField.checkFields(t, result)