MCPcopy
hub / github.com/zincsearch/zincsearch / TestSearchV1

Function TestSearchV1

pkg/handlers/search/search_v1_test.go:28–92  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26)
27
28func TestSearchV1(t *testing.T) {
29 indexName := "TestSearchV1.index_1"
30 type args struct {
31 code int
32 data string
33 params map[string]string
34 result string
35 }
36 tests := []struct {
37 name string
38 args args
39 }{
40 {
41 name: "normal",
42 args: args{
43 code: http.StatusOK,
44 data: `{"query_type":"match_all","max_results":10}`,
45 params: map[string]string{"target": indexName},
46 result: "{\"total\":",
47 },
48 },
49 {
50 name: "index not found",
51 args: args{
52 code: http.StatusBadRequest,
53 data: `{"query_type":"match_all","max_results":10}`,
54 params: map[string]string{"target": "NotExist" + indexName},
55 result: "does not exists",
56 },
57 },
58 {
59 name: "query jsone error",
60 args: args{
61 code: http.StatusBadRequest,
62 data: `{"query_type":"match_all","max_results":10,{x}}`,
63 params: map[string]string{"target": indexName},
64 result: "invalid character",
65 },
66 },
67 }
68
69 t.Run("prepare", func(t *testing.T) {
70 index, err := core.NewIndex(indexName, "disk", 2)
71 assert.NoError(t, err)
72 assert.NotNil(t, index)
73 err = core.StoreIndex(index)
74 assert.NoError(t, err)
75 })
76
77 for _, tt := range tests {
78 t.Run(tt.name, func(t *testing.T) {
79 c, w := utils.NewGinContext()
80 utils.SetGinRequestData(c, tt.args.data)
81 utils.SetGinRequestParams(c, tt.args.params)
82 SearchV1(c)
83 assert.Equal(t, tt.args.code, w.Code)
84 assert.Contains(t, w.Body.String(), tt.args.result)
85 })

Callers

nothing calls this directly

Calls 8

NewIndexFunction · 0.92
StoreIndexFunction · 0.92
NewGinContextFunction · 0.92
SetGinRequestDataFunction · 0.92
SetGinRequestParamsFunction · 0.92
DeleteIndexFunction · 0.92
SearchV1Function · 0.85
ContainsMethod · 0.80

Tested by

no test coverage detected