]> git.giacomolli.uk - onechat/blobdiff - model_fake_helper_test.go
Check forced-disconnect test setup failures
[onechat] / model_fake_helper_test.go
index f9d145121d0512e7efd9b42e5687aa390bdbe261..af94776633dbde9cc779a3dd46014aa71401b3bf 100644 (file)
@@ -49,22 +49,6 @@ func newModelFake(t *testing.T) *ModelFake {
        return f
 }
 
        return f
 }
 
-// Call returns call number n.
-func (f *ModelFake) Call(n int) ModelFakeCall {
-       f.mutex.Lock()
-       defer f.mutex.Unlock()
-
-       return f.calls[n]
-}
-
-// Calls returns the number of calls.
-func (f *ModelFake) Calls() int {
-       f.mutex.Lock()
-       defer f.mutex.Unlock()
-
-       return len(f.calls)
-}
-
 func (f *ModelFake) serve(w http.ResponseWriter, r *http.Request) {
        raw, err := io.ReadAll(r.Body)
        if err != nil {
 func (f *ModelFake) serve(w http.ResponseWriter, r *http.Request) {
        raw, err := io.ReadAll(r.Body)
        if err != nil {
@@ -95,12 +79,20 @@ func (f *ModelFake) serve(w http.ResponseWriter, r *http.Request) {
        reply(w, call)
 }
 
        reply(w, call)
 }
 
-func modelTestRequest() ModelRequest {
-       return ModelRequest{
-               Model:  "gpt-test",
-               Effort: "low",
-               Input:  []any{modelUserMessage("hello")},
-       }
+// Call returns call number n.
+func (f *ModelFake) Call(n int) ModelFakeCall {
+       f.mutex.Lock()
+       defer f.mutex.Unlock()
+
+       return f.calls[n]
+}
+
+// Calls returns the number of calls.
+func (f *ModelFake) Calls() int {
+       f.mutex.Lock()
+       defer f.mutex.Unlock()
+
+       return len(f.calls)
 }
 
 // modelWriteEvents writes events as a server-sent event stream.
 }
 
 // modelWriteEvents writes events as a server-sent event stream.
@@ -120,16 +112,6 @@ func modelWriteEvents(w http.ResponseWriter, events ...any) {
        }
 }
 
        }
 }
 
-func modelMessageItem(text string) map[string]any {
-       return map[string]any{
-               "type": "message",
-               "role": "assistant",
-               "content": []any{
-                       map[string]any{"type": "output_text", "text": text},
-               },
-       }
-}
-
 func modelCompletedEvent(output []any, input, cached, out int) map[string]any {
        if output == nil {
                output = []any{}
 func modelCompletedEvent(output []any, input, cached, out int) map[string]any {
        if output == nil {
                output = []any{}
@@ -148,6 +130,24 @@ func modelCompletedEvent(output []any, input, cached, out int) map[string]any {
        }
 }
 
        }
 }
 
+func modelMessageItem(text string) map[string]any {
+       return map[string]any{
+               "type": "message",
+               "role": "assistant",
+               "content": []any{
+                       map[string]any{"type": "output_text", "text": text},
+               },
+       }
+}
+
+func modelTestRequest() ModelRequest {
+       return ModelRequest{
+               Model:  "gpt-test",
+               Effort: "low",
+               Input:  []any{modelUserMessage("hello")},
+       }
+}
+
 func modelReadUsage(t *testing.T, path string) []ModelUsageRecord {
        t.Helper()
 
 func modelReadUsage(t *testing.T, path string) []ModelUsageRecord {
        t.Helper()