diff --git a/app_test.go b/app_test.go deleted file mode 100644 index cfbde7a..0000000 --- a/app_test.go +++ /dev/null @@ -1,9 +0,0 @@ -package golog - -import "testing" - -var a = App{} - -func TestApp(t *testing.T) { - a.Pgsql = nil -} diff --git a/client_test.go b/client_test.go deleted file mode 100644 index b69cdca..0000000 --- a/client_test.go +++ /dev/null @@ -1,10 +0,0 @@ -package golog - -import "testing" - -var c = &Client{} - -func TestClient(t *testing.T) { - c = NewClientGin(nil, "") - c = NewClientApi(nil, "") -} diff --git a/time_test.go b/time_test.go new file mode 100644 index 0000000..306a08f --- /dev/null +++ b/time_test.go @@ -0,0 +1,43 @@ +package golog + +import ( + "encoding/json" + "go.dtapp.net/gotime" + "gorm.io/driver/postgres" + "gorm.io/gorm" + "testing" +) + +func TestTest(t *testing.T) { + dsn := "host=119.29.14.159 user=dbadmin password=98jolg256s.* dbname=logs port=15432 sslmode=disable TimeZone=Asia/Shanghai" + pgsqlDB, _ := gorm.Open(postgres.Open(dsn), &gorm.Config{}) + + client := NewClientApi(pgsqlDB, "test") + + // 插入时间 + client.Api.Record(ApiPostgresqlLog{ + RequestTime: TimeString{Time: gotime.Current().Time}, //【请求】时间 + ResponseTime: TimeString{Time: gotime.Current().Time}, //【返回】时间 + }) + + // 查询数据 + var result ApiPostgresqlLog + client.Api.Query().Where("log_id = ?", 10).Take(&result) + + t.Log(result) + t.Logf("result:%v", result) + t.Logf("result.request_time:%v", result.RequestTime) + t.Logf("result:%+v", result) + t.Logf("result.request_time:%+v", result.RequestTime) + + marshal, err := json.Marshal(result) + t.Logf("Marshal:%s", marshal) + t.Logf("Marshal:%v", marshal) + t.Logf("err:%v", err) + + var jsonM ApiPostgresqlLog + err = json.Unmarshal(marshal, &jsonM) + t.Logf("Unmarshal:%v", jsonM) + t.Logf("Unmarshal:%+v", jsonM) + t.Logf("err:%v", err) +}