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

Function TestClient

modules/text2vec-databricks/clients/databricks_test.go:33–204  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 12

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
buildURLMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…