package usage import ( "context" "encoding/json" "testing" "time" "github.com/carlosframework/platform/internal/release" ) func TestUpsertScanDayUsesUTCDate(t *testing.T) { s := release.NewDirStore(t.TempDir()) ctx := context.Background() at := time.Date(2026, 9, 8, 23, 59, 0, 0, time.UTC) if err := UpsertScanDay(ctx, s, at, map[string]ScanRow{ "bab": {Objects: 2, Bytes: 30}, }); err != nil { t.Fatal(err) } if err := UpsertScanDay(ctx, s, at.Add(time.Minute), map[string]ScanRow{ "bab": {Objects: 1, Bytes: 7}, }); err != nil { t.Fatal(err) } for date, want := range map[string]ScanRow{ "2026-09-08": {Objects: 2, Bytes: 30}, "2026-09-09": {Objects: 1, Bytes: 7}, } { raw, _, err := s.Get(ctx, ScanDayKey(date)) if err != nil { t.Fatal(err) } var day ScanDay if err := json.Unmarshal(raw, &day); err != nil { t.Fatal(err) } if got := day.Accounts["bab"]; got != want { t.Fatalf("%s row = %+v, want %+v", date, got, want) } } } func TestUpsertScanDayMergesAccountsAndTicks(t *testing.T) { s := release.NewDirStore(t.TempDir()) ctx := context.Background() at := time.Date(2026, 9, 8, 10, 0, 0, 0, time.UTC) for _, deltas := range []map[string]ScanRow{ {"bab": {Objects: 2, Bytes: 20}}, {"bab": {Objects: 1, Bytes: 5}, "ops": {Objects: 3, Bytes: 30}}, } { if err := UpsertScanDay(ctx, s, at, deltas); err != nil { t.Fatal(err) } } raw, _, err := s.Get(ctx, ScanDayKey("2026-09-08")) if err != nil { t.Fatal(err) } var day ScanDay if err := json.Unmarshal(raw, &day); err != nil { t.Fatal(err) } if got := day.Accounts["bab"]; got != (ScanRow{Objects: 3, Bytes: 25}) { t.Fatalf("bab = %+v", got) } if got := day.Accounts["ops"]; got != (ScanRow{Objects: 3, Bytes: 30}) { t.Fatalf("ops = %+v", got) } }