carlos / platform Public

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

Plain git — no account needed to clone.

Download

Download this file

1package main
2
3import (
4 "strings"
5 "testing"
6)
7
8func TestPrintBackhaulReport(t *testing.T) {
9 var b strings.Builder
10 printBackhaulReport(&b, backhaulReport{
11 Period: "mtd", CoveredDays: 3, PeriodDays: 10, EgressGB: 14, BackhaulGB: 5, BackhaulReq1k: 7,
12 ShareOfEgress: 5.0 / 14, InterRegionGBUSD: 0.02, AbsorbedUSD: 0.10,
13 Accounts: []backhaulAccount{
14 {Account: "bab", Name: "ops", EgressGB: 10, BackhaulGB: 2.5, BackhaulReq1k: 7, ShareOfEgress: 0.25, AbsorbedUSD: 0.225},
15 },
16 })
17 out := b.String()
18 for _, want := range []string{"backhaul mtd (3/10 days covered): 5.00 GB of 14.00 GB egress (35.7%)", "inter-region leg ≈ $0.10 at $0.020/GB, absorbed", "bab", "ops", "25.0%"} {
19 if !strings.Contains(out, want) {
20 t.Errorf("missing %q in:\n%s", want, out)
21 }
22 }
23 var empty strings.Builder
24 printBackhaulReport(&empty, backhaulReport{Period: "7d", PeriodDays: 7})
25 if !strings.Contains(empty.String(), "no account backhauled anything") {
26 t.Errorf("empty report printed a bare header:\n%s", empty.String())
27 }
28}
29