Skip to content

Commit 33a5e21

Browse files
committed
test: improve coverage for reasoning field support
- Add test for empty reasoning_content with reasoning fallback - Add error handling tests for invalid JSON - Coverage increased to 99.9%
1 parent 96433df commit 33a5e21

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

chat_reasoning_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ func TestChatCompletionStreamChoiceDelta_ReasoningFieldSupport(t *testing.T) {
4141
jsonData: `{"role":"assistant","content":"Hello"}`,
4242
expected: "",
4343
},
44+
{
45+
name: "Empty reasoning_content with reasoning value",
46+
jsonData: `{"role":"assistant","reasoning_content":"","reasoning":"Fallback value"}`,
47+
expected: "Fallback value",
48+
},
4449
}
4550

4651
for _, tt := range tests {
@@ -58,6 +63,16 @@ func TestChatCompletionStreamChoiceDelta_ReasoningFieldSupport(t *testing.T) {
5863
}
5964
}
6065

66+
// TestChatCompletionStreamChoiceDelta_UnmarshalError tests error handling.
67+
func TestChatCompletionStreamChoiceDelta_UnmarshalError(t *testing.T) {
68+
var delta openai.ChatCompletionStreamChoiceDelta
69+
invalidJSON := `{"role":"assistant","content":}`
70+
err := json.Unmarshal([]byte(invalidJSON), &delta)
71+
if err == nil {
72+
t.Error("Expected error when unmarshaling invalid JSON, got nil")
73+
}
74+
}
75+
6176
// TestChatCompletionMessage_ReasoningFieldSupport tests that both
6277
// reasoning_content and reasoning fields are properly supported in chat completion messages.
6378
func TestChatCompletionMessage_ReasoningFieldSupport(t *testing.T) {
@@ -92,6 +107,11 @@ func TestChatCompletionMessage_ReasoningFieldSupport(t *testing.T) {
92107
jsonData: `{"role":"assistant","content":"Hello"}`,
93108
expected: "",
94109
},
110+
{
111+
name: "Empty reasoning_content with reasoning value",
112+
jsonData: `{"role":"assistant","reasoning_content":"","reasoning":"Fallback value"}`,
113+
expected: "Fallback value",
114+
},
95115
}
96116

97117
for _, tt := range tests {
@@ -109,6 +129,16 @@ func TestChatCompletionMessage_ReasoningFieldSupport(t *testing.T) {
109129
}
110130
}
111131

132+
// TestChatCompletionMessage_UnmarshalError tests error handling.
133+
func TestChatCompletionMessage_UnmarshalError(t *testing.T) {
134+
var msg openai.ChatCompletionMessage
135+
invalidJSON := `{"role":"assistant","content":}`
136+
err := json.Unmarshal([]byte(invalidJSON), &msg)
137+
if err == nil {
138+
t.Error("Expected error when unmarshaling invalid JSON, got nil")
139+
}
140+
}
141+
112142
// TestChatCompletionMessage_MultiContent_ReasoningFieldSupport tests reasoning field support
113143
// with MultiContent messages.
114144
func TestChatCompletionMessage_MultiContent_ReasoningFieldSupport(t *testing.T) {

0 commit comments

Comments
 (0)