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

Function TestAnswersRows

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

Source from the content-addressed store, hash-verified

152}
153
154func TestAnswersRows(t *testing.T) {
155 log.SetOutput(&bytes.Buffer{})
156
157 reqString := "github.com\none.one.one.one\ngoogle-public-dns-a.google.com"
158
159 req := httptest.NewRequest("POST",
160 "http://example.org/query",
161 strings.NewReader(reqString))
162 w := httptest.NewRecorder()
163 queryHandler, err := initQueryHandler(testDbPath, "SELECT * FROM ip_dns WHERE dns = ?", 0)
164 if err != nil {
165 t.Fatal(err)
166 }
167 queryHandler(w, req)
168
169 resp := w.Result()
170 defer resp.Body.Close()
171
172 if resp.StatusCode != http.StatusOK {
173 t.Fatalf(`resp.StatusCode (%d) != http.StatusOK (%d)`, resp.StatusCode, http.StatusOK)
174 }
175
176 if resp.Header.Get("Content-Type") != "application/json" {
177 t.Fatalf(`resp.Header.Get("Content-Type") (%s) != "application/json"`, resp.Header.Get("Content-Type"))
178 }
179
180 var fullResponse []queryResult
181 decoder := json.NewDecoder(resp.Body)
182 err = decoder.Decode(&fullResponse)
183 if err != nil {
184 t.Fatal(err)
185 }
186
187 expectedResponse := []queryResult{
188 queryResult{
189 Out: [][]interface{}{
190 []interface{}{"192.30.253.112", "github.com"},
191 []interface{}{"192.30.253.113", "github.com"},
192 }},
193 queryResult{
194 Out: [][]interface{}{
195 []interface{}{"1.1.1.1", "one.one.one.one"},
196 }},
197 queryResult{
198 Out: [][]interface{}{
199 []interface{}{"8.8.8.8", "google-public-dns-a.google.com"},
200 }},
201 }
202
203 compare(t, fullResponse, expectedResponse)
204}
205
206func TestMoreThanOneParam(t *testing.T) {
207 log.SetOutput(&bytes.Buffer{})

Callers

nothing calls this directly

Calls 2

initQueryHandlerFunction · 0.85
compareFunction · 0.85

Tested by

no test coverage detected