MCPcopy
hub / github.com/weaviate/weaviate / TestClient

Function TestClient

modules/text2vec-jinaai/clients/jinaai_test.go:32–128  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

30)
31
32func TestClient(t *testing.T) {
33 t.Run("when all is fine", func(t *testing.T) {
34 server := httptest.NewServer(&fakeHandler{t: t})
35 defer server.Close()
36
37 c := New("apiKey", 0, nullLogger())
38
39 expected := &modulecomponents.VectorizationResult[[]float32]{
40 Text: []string{"This is my text"},
41 Vector: [][]float32{{0.1, 0.2, 0.3}},
42 Dimensions: 3,
43 }
44 res, _, _, err := c.Vectorize(context.Background(), []string{"This is my text"}, fakeClassConfig{classConfig: map[string]interface{}{"Model": "jina-embedding-v2", "baseURL": server.URL}})
45
46 assert.Nil(t, err)
47 assert.Equal(t, expected, res)
48 })
49
50 t.Run("when the context is expired", func(t *testing.T) {
51 server := httptest.NewServer(&fakeHandler{t: t})
52 defer server.Close()
53 c := New("apiKey", 0, nullLogger())
54
55 ctx, cancel := context.WithDeadline(context.Background(), time.Now())
56 defer cancel()
57
58 _, _, _, err := c.Vectorize(ctx, []string{"This is my text"}, fakeClassConfig{classConfig: map[string]interface{}{}})
59
60 require.NotNil(t, err)
61 assert.Contains(t, err.Error(), "context deadline exceeded")
62 })
63
64 t.Run("when the server returns an error", func(t *testing.T) {
65 server := httptest.NewServer(&fakeHandler{
66 t: t,
67 serverError: errors.Errorf("nope, not gonna happen"),
68 })
69 defer server.Close()
70 c := New("apiKey", 0, nullLogger())
71
72 _, _, _, err := c.Vectorize(context.Background(), []string{"This is my text"}, fakeClassConfig{classConfig: map[string]interface{}{"baseURL": server.URL}})
73
74 require.NotNil(t, err)
75 assert.EqualError(t, err, "connection to: JinaAI API failed with status: 500 error: nope, not gonna happen")
76 })
77
78 t.Run("when JinaAI key is passed using X-Jinaai-Api-Key header", func(t *testing.T) {
79 server := httptest.NewServer(&fakeHandler{t: t})
80 defer server.Close()
81 c := New("", 0, nullLogger())
82
83 ctxWithValue := context.WithValue(context.Background(),
84 "X-Jinaai-Api-Key", []string{"some-key"})
85
86 expected := &modulecomponents.VectorizationResult[[]float32]{
87 Text: []string{"This is my text"},
88 Vector: [][]float32{{0.1, 0.2, 0.3}},
89 Dimensions: 3,

Callers

nothing calls this directly

Calls 10

CloseMethod · 0.95
EqualMethod · 0.80
ErrorfMethod · 0.80
NewFunction · 0.70
nullLoggerFunction · 0.70
VectorizeMethod · 0.65
NowMethod · 0.65
ContainsMethod · 0.65
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…