Add monitoring service and database schema
- Implement monitoring service with heartbeat, lease tasks, resume tasks, and task result handling. - Create monitoring time utilities for business date calculations. - Add unit tests for date window resolution and business day handling. - Define database schema for monitoring-related tables including quotas, daily reports, and task management. - Establish migration scripts for creating and dropping monitoring tables.
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/geo-platform/tenant-api/internal/shared/response"
|
||||
)
|
||||
|
||||
func TestResolveDashboardDateWindowAtUsesBusinessTimezone(t *testing.T) {
|
||||
loc := time.FixedZone("CST", 8*60*60)
|
||||
now := time.Date(2026, 4, 12, 0, 5, 0, 0, loc)
|
||||
|
||||
startDate, endDate, err := resolveDashboardDateWindowAt(7, "2026-04-12", now, loc)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, time.Date(2026, 4, 6, 0, 0, 0, 0, loc), startDate)
|
||||
assert.Equal(t, time.Date(2026, 4, 12, 0, 0, 0, 0, loc), endDate)
|
||||
}
|
||||
|
||||
func TestResolveDashboardDateWindowAtRejectsFutureBusinessDay(t *testing.T) {
|
||||
loc := time.FixedZone("CST", 8*60*60)
|
||||
now := time.Date(2026, 4, 12, 0, 5, 0, 0, loc)
|
||||
|
||||
_, _, err := resolveDashboardDateWindowAt(7, "2026-04-13", now, loc)
|
||||
require.Error(t, err)
|
||||
|
||||
appErr := response.Normalize(err)
|
||||
assert.Equal(t, 40031, appErr.Code)
|
||||
assert.Equal(t, "invalid_business_date", appErr.Message)
|
||||
assert.Equal(t, "business_date must not be later than today", appErr.Detail)
|
||||
}
|
||||
|
||||
func TestParseDetailDateRangeAtDefaultsToCurrentBusinessDay(t *testing.T) {
|
||||
loc := time.FixedZone("CST", 8*60*60)
|
||||
now := time.Date(2026, 4, 12, 0, 5, 0, 0, loc)
|
||||
|
||||
fromDate, toDate, err := parseDetailDateRangeAt("", "", now, loc)
|
||||
require.NoError(t, err)
|
||||
|
||||
expected := time.Date(2026, 4, 12, 0, 0, 0, 0, loc)
|
||||
assert.Equal(t, expected, fromDate)
|
||||
assert.Equal(t, expected, toDate)
|
||||
}
|
||||
|
||||
func TestMonitoringBusinessDayAndDateAtUsesShanghaiTimezone(t *testing.T) {
|
||||
now := time.Date(2026, 4, 11, 17, 19, 0, 0, time.UTC)
|
||||
|
||||
businessDay, businessDate := monitoringBusinessDayAndDateAt(now)
|
||||
|
||||
assert.Equal(t, time.Date(2026, 4, 12, 0, 0, 0, 0, monitoringBusinessLocation()), businessDay)
|
||||
assert.Equal(t, "2026-04-12", businessDate)
|
||||
}
|
||||
|
||||
func TestEncodeMonitoringProjectionRebuildEnvelopePreservesBusinessDate(t *testing.T) {
|
||||
businessDay := time.Date(2026, 4, 12, 0, 0, 0, 0, monitoringBusinessLocation())
|
||||
|
||||
payload, err := encodeMonitoringProjectionRebuildEnvelope(1, 2, businessDay, "test")
|
||||
require.NoError(t, err)
|
||||
|
||||
envelope, err := decodeMonitoringProjectionRebuildEnvelope(payload)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "2026-04-12", envelope.BusinessDate)
|
||||
}
|
||||
Reference in New Issue
Block a user