Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
api: test reporting in the future (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmizerany authored Feb 16, 2023
1 parent 0838db6 commit 4c99883
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,15 +439,20 @@ func TestTierReport(t *testing.T) {
t.Fatal(err)
}

if err := tc.ReportUsage(ctx, "org:test", "feature:t", 10, &tier.ReportParams{
// Force 'now' at Stripe.
At: time.Time{}, // for 'now' on the server
report := func(n int, at time.Time, wantErr error) {
if err := tc.ReportUsage(ctx, "org:test", "feature:t", n, &tier.ReportParams{
// Force 'now' at Stripe.
At: time.Time{},

Clobber: false,
}); err != nil {
t.Fatal(err)
Clobber: false,
}); !errors.Is(err, wantErr) {
t.Errorf("err = %v; want %v", err, wantErr)
}
}

report(10, time.Time{}, nil)
report(10, clock.Now().Add(1*time.Minute), nil)

limit, used, err := tc.LookupLimit(ctx, "org:test", "feature:t")
if err != nil {
t.Fatal(err)
Expand All @@ -456,7 +461,7 @@ func TestTierReport(t *testing.T) {
if limit != control.Inf {
t.Errorf("limit = %d, want %d", control.Inf, limit)
}
if used != 10 {
if used != 20 {
t.Errorf("used = %d, want 10", used)
}
}
Expand Down

0 comments on commit 4c99883

Please sign in to comment.