mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
test(log): expand handler, config, and metrics coverage
This commit is contained in:
@@ -51,7 +51,7 @@ func TestMaster_ListSelfLogs_FiltersByMaster(t *testing.T) {
|
||||
t.Fatalf("create log2: %v", err)
|
||||
}
|
||||
|
||||
mh := &MasterHandler{db: db}
|
||||
mh := &MasterHandler{db: db, logDB: db}
|
||||
|
||||
withMaster := func(next gin.HandlerFunc) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
@@ -69,7 +69,7 @@ func TestMaster_ListSelfLogs_FiltersByMaster(t *testing.T) {
|
||||
if rr.Code != http.StatusOK {
|
||||
t.Fatalf("expected 200, got %d body=%s", rr.Code, rr.Body.String())
|
||||
}
|
||||
var resp ListLogsResponse
|
||||
var resp ListMasterLogsResponse
|
||||
if err := json.Unmarshal(rr.Body.Bytes(), &resp); err != nil {
|
||||
t.Fatalf("unmarshal: %v", err)
|
||||
}
|
||||
@@ -79,6 +79,31 @@ func TestMaster_ListSelfLogs_FiltersByMaster(t *testing.T) {
|
||||
if resp.Items[0].KeyID != k1.ID {
|
||||
t.Fatalf("expected key_id %d, got %+v", k1.ID, resp.Items[0])
|
||||
}
|
||||
|
||||
var raw map[string]any
|
||||
if err := json.Unmarshal(rr.Body.Bytes(), &raw); err != nil {
|
||||
t.Fatalf("unmarshal raw: %v", err)
|
||||
}
|
||||
items, ok := raw["items"].([]any)
|
||||
if !ok || len(items) == 0 {
|
||||
t.Fatalf("expected items array in response")
|
||||
}
|
||||
first, ok := items[0].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("expected item object in response")
|
||||
}
|
||||
if _, ok := first["provider_id"]; ok {
|
||||
t.Fatalf("expected provider_id to be omitted")
|
||||
}
|
||||
if _, ok := first["provider_type"]; ok {
|
||||
t.Fatalf("expected provider_type to be omitted")
|
||||
}
|
||||
if _, ok := first["provider_name"]; ok {
|
||||
t.Fatalf("expected provider_name to be omitted")
|
||||
}
|
||||
if _, ok := first["client_ip"]; ok {
|
||||
t.Fatalf("expected client_ip to be omitted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdmin_DeleteLogs_BeforeFilters(t *testing.T) {
|
||||
@@ -114,7 +139,7 @@ func TestAdmin_DeleteLogs_BeforeFilters(t *testing.T) {
|
||||
t.Fatalf("create log3: %v", err)
|
||||
}
|
||||
|
||||
h := &Handler{db: db}
|
||||
h := &Handler{db: db, logDB: db}
|
||||
r := gin.New()
|
||||
r.DELETE("/admin/logs", h.DeleteLogs)
|
||||
|
||||
@@ -155,7 +180,7 @@ func TestAdmin_DeleteLogs_RequiresBefore(t *testing.T) {
|
||||
t.Fatalf("migrate: %v", err)
|
||||
}
|
||||
|
||||
h := &Handler{db: db}
|
||||
h := &Handler{db: db, logDB: db}
|
||||
r := gin.New()
|
||||
r.DELETE("/admin/logs", h.DeleteLogs)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user