MCPcopy
hub / github.com/weaviate/weaviate / TestGetAnswer

Function TestGetAnswer

modules/generative-cohere/clients/cohere_test.go:37–132  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

35}
36
37func TestGetAnswer(t *testing.T) {
38 props := []*modulecapabilities.GenerateProperties{{Text: map[string]string{"prop": "My name is john"}}}
39
40 tests := []struct {
41 name string
42 answer generateResponse
43 timeout time.Duration
44 expectedResult string
45 }{
46 {
47 name: "when the server has a successful aner",
48 answer: generateResponse{
49 Message: responseMessage{
50 Content: []responseContent{
51 {Text: "John"},
52 },
53 },
54 },
55 expectedResult: "John",
56 },
57 {
58 name: "when the server has a an error",
59 answer: generateResponse{
60 Message: responseMessage{
61 ErrorMessage: "some error from the server",
62 },
63 },
64 },
65 {
66 name: "when the server does not respond in time",
67 answer: generateResponse{
68 Message: responseMessage{
69 ErrorMessage: "context deadline exceeded",
70 },
71 },
72 timeout: time.Second,
73 },
74 }
75 for _, test := range tests {
76 t.Run(test.name, func(t *testing.T) {
77 handler := &testAnswerHandler{
78 t: t,
79 answer: test.answer,
80 timeout: test.timeout,
81 }
82 server := httptest.NewServer(handler)
83 defer server.Close()
84
85 c := New("apiKey", test.timeout, nullLogger())
86
87 cfg := &fakeClassConfig{baseURL: server.URL}
88 res, err := c.GenerateAllResults(context.Background(), props, "What is my name?", nil, false, cfg)
89
90 if test.answer.Message.ErrorMessage != "" {
91 assert.Contains(t, err.Error(), test.answer.Message.GetMessage())
92 } else {
93 assert.Equal(t, test.expectedResult, *res.Result)
94 }

Callers

nothing calls this directly

Calls 13

CloseMethod · 0.95
EqualMethod · 0.80
NewFunction · 0.70
nullLoggerFunction · 0.70
GenerateAllResultsMethod · 0.65
ContainsMethod · 0.65
EmptyMethod · 0.65
LenMethod · 0.65
RunMethod · 0.45
ErrorMethod · 0.45
GetMessageMethod · 0.45
getCohereUrlMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…