Sfoglia il codice sorgente

增加测试代码

liuyong_awesome 4 anni fa
parent
commit
03a20ece5f
2 ha cambiato i file con 36 aggiunte e 1 eliminazioni
  1. 1 1
      log.go
  2. 35 0
      log_test.go

+ 1 - 1
log.go

@@ -32,7 +32,7 @@ func NewLoggerByLogName(path string, options ...RotateOption) (*logrus.Logger, e
 		v(co)
 	}
 	writer, err := rotatelogs.New(
-		path+"log%Y%m%d%H%M%S",
+		path+"log.%Y%m%d%H%M%S",
 		rotatelogs.WithLinkName(path),
 		rotatelogs.WithMaxAge(co.MaxAge),
 		rotatelogs.WithRotationTime(co.RotationTime),

+ 35 - 0
log_test.go

@@ -0,0 +1,35 @@
+package go_chat_api_util
+
+import (
+	"github.com/sirupsen/logrus"
+	"testing"
+)
+
+func TestNewLoggerByLogName(t *testing.T) {
+	type args struct {
+		path    string
+		options []RotateOption
+	}
+
+	tests := []struct {
+		name    string
+		args    args
+		want    *logrus.Logger
+		wantErr bool
+	}{
+		{name: "first", args: args{path: "/Users/kok/go/src/go_chat_api_util/logs/"}, wantErr: false},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			got, err := NewLoggerByLogName(tt.args.path, tt.args.options...)
+			if (err != nil) != tt.wantErr {
+				t.Errorf("NewLoggerByLogName() error = %v, wantErr %v", err, tt.wantErr)
+				return
+			}
+			got.Error("hello33")
+			//if !reflect.DeepEqual(got, tt.want) {
+			//	t.Errorf("NewLoggerByLogName() got = %v, want %v", got, tt.want)
+			//}
+		})
+	}
+}