package api import "testing" func TestContractValueLabel(t *testing.T) { cases := []struct { name string value *ContractValue want string }{ {"nil is silent", nil, ""}, {"nothing on offer", &ContractValue{}, ""}, {"cash only", &ContractValue{Cents: 25_000, Count: 1}, "$250"}, {"credits only", &ContractValue{Credits: 500, Count: 1}, "500 credits"}, {"both", &ContractValue{Cents: 10_000, Credits: 50, Count: 2}, "$100 + 50 credits"}, // A contract can exist with no value recorded yet; say nothing rather // than print a misleading "$0". {"counted but valueless", &ContractValue{Count: 1}, ""}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { if got := tc.value.Label(); got != tc.want { t.Fatalf("Label() = %q, want %q", got, tc.want) } }) } } func TestSuppressionsTotal(t *testing.T) { var empty Suppressions if empty.Total() != 0 { t.Fatalf("empty total = %d", empty.Total()) } s := Suppressions{ Repository: []Suppression{{Title: "a"}, {Title: "b"}}, Patterns: []Suppression{{Title: "c"}}, } if s.Total() != 3 { t.Fatalf("total = %d, want 3", s.Total()) } }