package api
import (
"fmt"
"strings"
"testing"
)
func TestFakeF(t *testing.T) {
var capturedName, capturedIn string
f := &Fake{
FFunc: func(name, in string) (string, error) {
capturedName, capturedIn = name, in
return "echo: " + in, nil
},
}
out, err := f.F("greet", "world")
if err != nil {
t.Fatalf("F: %v", err)
}
if out != "echo: world" {
t.Errorf("Out: got %q, want %q", out, "echo: world")
}
if capturedName != "greet" || capturedIn != "world" {
t.Errorf("captured: name=%q in=%q",
capturedName, capturedIn)
}
}
func TestFakeFUnset(t *testing.T) {
f := &Fake{}
_, err := f.F("any", "any")
if err == nil {
t.Fatal("expected error, got nil")
}
if !strings.Contains(err.Error(), "no handler") {
t.Errorf("error: %v", err)
}
}
func TestFakeMessagesError(t *testing.T) {
f := &Fake{
MessagesFunc: func(
req MessagesRequest,
) (*MessagesResponse, error) {
return nil, fmt.Errorf("synthetic")
},
}
_, err := f.Messages(MessagesRequest{Model: "test"})
if err == nil {
t.Fatal("expected error, got nil")
}
}