MCPcopy
hub / github.com/zincsearch/zincsearch / TestMultipleSearch

Function TestMultipleSearch

pkg/handlers/search/search_v2_test.go:102–167  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

100}
101
102func TestMultipleSearch(t *testing.T) {
103 indexName := "TestMultipleSearch.index_1"
104 type args struct {
105 code int
106 data string
107 params map[string]string
108 result string
109 }
110 tests := []struct {
111 name string
112 args args
113 }{
114 {
115 name: "normal",
116 args: args{
117 code: http.StatusOK,
118 data: `{"index":"` + indexName + `"}
119{"query":{"match_all":{}},"size":10}`,
120 params: map[string]string{"target": indexName},
121 result: "successful",
122 },
123 },
124 {
125 name: "multiple index",
126 args: args{
127 code: http.StatusOK,
128 data: `{"index":["` + indexName + `"]}
129{"query":{"match_all":{}},"size":10}`,
130 result: "successful",
131 },
132 },
133 {
134 name: "not exists",
135 args: args{
136 code: http.StatusOK,
137 data: `{"index":"TestMultipleSearch.notExists"}
138{"query":{"match_all":{}},"size":10}`,
139 result: "does not exists",
140 },
141 },
142 }
143
144 t.Run("prepare", func(t *testing.T) {
145 index, err := core.NewIndex(indexName, "disk", 2)
146 assert.NoError(t, err)
147 assert.NotNil(t, index)
148 err = core.StoreIndex(index)
149 assert.NoError(t, err)
150 })
151
152 for _, tt := range tests {
153 t.Run(tt.name, func(t *testing.T) {
154 c, w := utils.NewGinContext()
155 utils.SetGinRequestData(c, tt.args.data)
156 utils.SetGinRequestParams(c, tt.args.params)
157 MultipleSearch(c)
158 assert.Equal(t, tt.args.code, w.Code)
159 assert.Contains(t, w.Body.String(), tt.args.result)

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
MultipleSearchFunction · 0.85
ContainsMethod · 0.80

Tested by

no test coverage detected