MCPcopy Index your code
hub / github.com/assafmo/SQLiteQueryServer / TestMoreThanOneParam

Function TestMoreThanOneParam

main_test.go:206–253  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

204}
205
206func TestMoreThanOneParam(t *testing.T) {
207 log.SetOutput(&bytes.Buffer{})
208
209 reqString := "github.com,192.30.253.112\none.one.one.one,1.1.1.1"
210
211 req := httptest.NewRequest("POST",
212 "http://example.org/query",
213 strings.NewReader(reqString))
214 w := httptest.NewRecorder()
215 queryHandler, err := initQueryHandler(testDbPath,
216 "SELECT * FROM ip_dns WHERE dns = ? AND ip = ?",
217 0)
218 if err != nil {
219 t.Fatal(err)
220 }
221 queryHandler(w, req)
222
223 resp := w.Result()
224 defer resp.Body.Close()
225
226 if resp.StatusCode != http.StatusOK {
227 t.Fatalf(`resp.StatusCode (%d) != http.StatusOK (%d)`, resp.StatusCode, http.StatusOK)
228 }
229
230 if resp.Header.Get("Content-Type") != "application/json" {
231 t.Fatalf(`resp.Header.Get("Content-Type") (%s) != "application/json"`, resp.Header.Get("Content-Type"))
232 }
233
234 var fullResponse []queryResult
235 decoder := json.NewDecoder(resp.Body)
236 err = decoder.Decode(&fullResponse)
237 if err != nil {
238 t.Fatal(err)
239 }
240
241 expectedResponse := []queryResult{
242 queryResult{
243 Out: [][]interface{}{
244 []interface{}{"192.30.253.112", "github.com"},
245 }},
246 queryResult{
247 Out: [][]interface{}{
248 []interface{}{"1.1.1.1", "one.one.one.one"},
249 }},
250 }
251
252 compare(t, fullResponse, expectedResponse)
253}
254
255func TestZeroParams(t *testing.T) {
256 log.SetOutput(&bytes.Buffer{})

Callers

nothing calls this directly

Calls 2

initQueryHandlerFunction · 0.85
compareFunction · 0.85

Tested by

no test coverage detected