From 07f567f9c9ff0eb0c0a1d20ae8715ef64c0474f0 Mon Sep 17 00:00:00 2001 From: "Jakub A. W" Date: Mon, 8 Jun 2026 09:52:11 -0400 Subject: [PATCH] test(usage): table-driven transcription no-usage cases Convert TestExtractFromTranscriptionResponse_NoUsage to a table-driven structure with named subtests, per CLAUDE.md's table-driven test preference and post-merge review feedback on #372. Test-only; no behavior change. Co-Authored-By: Claude Opus 4.8 (1M context) --- internal/usage/audio_test.go | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/internal/usage/audio_test.go b/internal/usage/audio_test.go index b3cefe22..fd2eca1f 100644 --- a/internal/usage/audio_test.go +++ b/internal/usage/audio_test.go @@ -97,18 +97,24 @@ func TestExtractFromTranscriptionResponse_PerSecondCost(t *testing.T) { func TestExtractFromTranscriptionResponse_NoUsage(t *testing.T) { // Whisper / text responses carry no usage; the interaction is still recorded. - for _, body := range [][]byte{ - []byte(`{"text":"hi"}`), - []byte("plain transcript text"), - nil, - } { - entry := ExtractFromTranscriptionResponse(body, "req", "whisper-1", "openai") - if entry == nil { - t.Fatalf("expected an entry for body %q", body) - } - if entry.TotalTokens != 0 || entry.RawData != nil { - t.Errorf("expected zero-usage entry for body %q, got %+v", body, entry) - } + tests := []struct { + name string + body []byte + }{ + {"json without usage", []byte(`{"text":"hi"}`)}, + {"plain text", []byte("plain transcript text")}, + {"nil body", nil}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + entry := ExtractFromTranscriptionResponse(tt.body, "req", "whisper-1", "openai") + if entry == nil { + t.Fatal("expected an entry") + } + if entry.TotalTokens != 0 || entry.RawData != nil { + t.Errorf("expected zero-usage entry, got %+v", entry) + } + }) } }