| 132 | } |
| 133 | |
| 134 | func TestValidate(t *testing.T) { |
| 135 | t.Parallel() |
| 136 | |
| 137 | t.Run("PassesWhenAnyRowHasPricing", func(t *testing.T) { |
| 138 | t.Parallel() |
| 139 | rows := []priceRow{ |
| 140 | {Provider: "openai", Model: "no-prices"}, |
| 141 | {Provider: "anthropic", Model: "claude", InputPrice: int64Ptr(3_000_000)}, |
| 142 | } |
| 143 | require.NoError(t, validate(rows)) |
| 144 | }) |
| 145 | |
| 146 | t.Run("FailsWhenNoRowHasPricing", func(t *testing.T) { |
| 147 | t.Parallel() |
| 148 | // Mirrors what would happen if upstream renamed the `cost` key: |
| 149 | // Go's decoder silently drops it, every row gets all-null prices, |
| 150 | // and convert returns syntactically valid rows with no pricing. |
| 151 | rows := []priceRow{ |
| 152 | {Provider: "anthropic", Model: "claude-x"}, |
| 153 | {Provider: "openai", Model: "gpt-x"}, |
| 154 | } |
| 155 | err := validate(rows) |
| 156 | require.Error(t, err) |
| 157 | require.Contains(t, err.Error(), "converted rows have no pricing data") |
| 158 | }) |
| 159 | } |
| 160 | |
| 161 | func floatPtr(v float64) *float64 { return &v } |
| 162 | func int64Ptr(v int64) *int64 { return &v } |