carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package usage
2
3import (
4 "context"
5 "encoding/json"
6 "testing"
7 "time"
8
9 "github.com/carlosframework/platform/internal/release"
10)
11
12func TestUpsertScanDayUsesUTCDate(t *testing.T) {
13 s := release.NewDirStore(t.TempDir())
14 ctx := context.Background()
15 at := time.Date(2026, 9, 8, 23, 59, 0, 0, time.UTC)
16
17 if err := UpsertScanDay(ctx, s, at, map[string]ScanRow{
18 "bab": {Objects: 2, Bytes: 30},
19 }); err != nil {
20 t.Fatal(err)
21 }
22 if err := UpsertScanDay(ctx, s, at.Add(time.Minute), map[string]ScanRow{
23 "bab": {Objects: 1, Bytes: 7},
24 }); err != nil {
25 t.Fatal(err)
26 }
27
28 for date, want := range map[string]ScanRow{
29 "2026-09-08": {Objects: 2, Bytes: 30},
30 "2026-09-09": {Objects: 1, Bytes: 7},
31 } {
32 raw, _, err := s.Get(ctx, ScanDayKey(date))
33 if err != nil {
34 t.Fatal(err)
35 }
36 var day ScanDay
37 if err := json.Unmarshal(raw, &day); err != nil {
38 t.Fatal(err)
39 }
40 if got := day.Accounts["bab"]; got != want {
41 t.Fatalf("%s row = %+v, want %+v", date, got, want)
42 }
43 }
44}
45
46func TestUpsertScanDayMergesAccountsAndTicks(t *testing.T) {
47 s := release.NewDirStore(t.TempDir())
48 ctx := context.Background()
49 at := time.Date(2026, 9, 8, 10, 0, 0, 0, time.UTC)
50 for _, deltas := range []map[string]ScanRow{
51 {"bab": {Objects: 2, Bytes: 20}},
52 {"bab": {Objects: 1, Bytes: 5}, "ops": {Objects: 3, Bytes: 30}},
53 } {
54 if err := UpsertScanDay(ctx, s, at, deltas); err != nil {
55 t.Fatal(err)
56 }
57 }
58 raw, _, err := s.Get(ctx, ScanDayKey("2026-09-08"))
59 if err != nil {
60 t.Fatal(err)
61 }
62 var day ScanDay
63 if err := json.Unmarshal(raw, &day); err != nil {
64 t.Fatal(err)
65 }
66 if got := day.Accounts["bab"]; got != (ScanRow{Objects: 3, Bytes: 25}) {
67 t.Fatalf("bab = %+v", got)
68 }
69 if got := day.Accounts["ops"]; got != (ScanRow{Objects: 3, Bytes: 30}) {
70 t.Fatalf("ops = %+v", got)
71 }
72}
73