@@ -44,19 +44,11 @@ func (a *DualWriteAndCommonTableTestcase) RunTests(ctx context.Context, t *testi
4444}
4545
4646func (a * DualWriteAndCommonTableTestcase ) testBasicRequest (ctx context.Context , t * testing.T ) {
47- resp , err := a .RequestToQuesma (ctx , "GET" , "/" , nil )
48- if err != nil {
49- t .Fatalf ("Failed to make GET request: %s" , err )
50- }
51- defer resp .Body .Close ()
47+ resp , _ := a .RequestToQuesma (ctx , t , "GET" , "/" , nil )
5248 assert .Equal (t , http .StatusOK , resp .StatusCode )
5349}
5450func (a * DualWriteAndCommonTableTestcase ) testIngestToCommonTableWorks (ctx context.Context , t * testing.T ) {
55- resp , err := a .RequestToQuesma (ctx , "POST" , "/logs-4/_doc" , []byte (`{"name": "Przemyslaw", "age": 31337}` ))
56- if err != nil {
57- t .Fatalf ("Failed to insert document: %s" , err )
58- }
59- defer resp .Body .Close ()
51+ resp , _ := a .RequestToQuesma (ctx , t , "POST" , "/logs-4/_doc" , []byte (`{"name": "Przemyslaw", "age": 31337}` ))
6052 assert .Equal (t , http .StatusOK , resp .StatusCode )
6153
6254 chQuery := "SELECT * FROM 'quesma_common_table'"
@@ -101,27 +93,14 @@ func (a *DualWriteAndCommonTableTestcase) testIngestToCommonTableWorks(ctx conte
10193 assert .Equal (t , 31337 , age )
10294 assert .Equal (t , "logs-4" , quesmaIndexName )
10395
104- resp , err = a .RequestToQuesma (ctx , "GET" , "/logs-4/_search" , []byte (`{"query": {"match_all": {}}}` ))
105- if err != nil {
106- t .Fatalf ("Failed to make GET request: %s" , err )
107- }
108- defer resp .Body .Close ()
109- bodyBytes , err := io .ReadAll (resp .Body )
110- if err != nil {
111- t .Fatalf ("Failed to read response body: %s" , err )
112- }
113-
96+ resp , bodyBytes := a .RequestToQuesma (ctx , t , "GET" , "/logs-4/_search" , []byte (`{"query": {"match_all": {}}}` ))
11497 assert .Equal (t , http .StatusOK , resp .StatusCode )
11598 assert .Contains (t , string (bodyBytes ), "Przemyslaw" )
11699 assert .Contains (t , "Clickhouse" , resp .Header .Get ("X-Quesma-Source" ))
117100}
118101
119102func (a * DualWriteAndCommonTableTestcase ) testDualQueryReturnsDataFromClickHouse (ctx context.Context , t * testing.T ) {
120- resp , err := a .RequestToQuesma (ctx , "POST" , "/logs-dual-query/_doc" , []byte (`{"name": "Przemyslaw", "age": 31337}` ))
121- if err != nil {
122- t .Fatalf ("Failed to insert document: %s" , err )
123- }
124- defer resp .Body .Close ()
103+ resp , _ := a .RequestToQuesma (ctx , t , "POST" , "/logs-dual-query/_doc" , []byte (`{"name": "Przemyslaw", "age": 31337}` ))
125104 assert .Equal (t , http .StatusOK , resp .StatusCode )
126105
127106 chQuery := "SELECT * FROM 'logs-dual-query'"
@@ -166,27 +145,14 @@ func (a *DualWriteAndCommonTableTestcase) testDualQueryReturnsDataFromClickHouse
166145 t .Fatalf ("Failed to make DELETE request: %s" , err )
167146 }
168147 // FINAL TEST - WHETHER QUESMA RETURNS DATA FROM CLICKHOUSE
169- resp , err = a .RequestToQuesma (ctx , "GET" , "/logs-dual-query/_search" , []byte (`{"query": {"match_all": {}}}` ))
170- if err != nil {
171- t .Fatalf ("Failed to make GET request: %s" , err )
172- }
173- defer resp .Body .Close ()
174- bodyBytes , err := io .ReadAll (resp .Body )
175- if err != nil {
176- t .Fatalf ("Failed to read response body: %s" , err )
177- }
178-
148+ resp , bodyBytes := a .RequestToQuesma (ctx , t , "GET" , "/logs-dual-query/_search" , []byte (`{"query": {"match_all": {}}}` ))
179149 assert .Equal (t , http .StatusOK , resp .StatusCode )
180150 assert .Contains (t , string (bodyBytes ), "Przemyslaw" )
181151 assert .Contains (t , "Clickhouse" , resp .Header .Get ("X-Quesma-Source" ))
182152}
183153
184154func (a * DualWriteAndCommonTableTestcase ) testIngestToClickHouseWorks (ctx context.Context , t * testing.T ) {
185- resp , err := a .RequestToQuesma (ctx , "POST" , "/logs-2/_doc" , []byte (`{"name": "Przemyslaw", "age": 31337}` ))
186- if err != nil {
187- t .Fatalf ("Failed to insert document: %s" , err )
188- }
189- defer resp .Body .Close ()
155+ resp , _ := a .RequestToQuesma (ctx , t , "POST" , "/logs-2/_doc" , []byte (`{"name": "Przemyslaw", "age": 31337}` ))
190156 assert .Equal (t , http .StatusOK , resp .StatusCode )
191157
192158 chQuery := "SELECT * FROM 'logs-2'"
@@ -241,11 +207,7 @@ func (a *DualWriteAndCommonTableTestcase) testIngestToClickHouseWorks(ctx contex
241207}
242208
243209func (a * DualWriteAndCommonTableTestcase ) testDualWritesWork (ctx context.Context , t * testing.T ) {
244- resp , err := a .RequestToQuesma (ctx , "POST" , "/logs-3/_doc" , []byte (`{"name": "Przemyslaw", "age": 31337}` ))
245- if err != nil {
246- t .Fatalf ("Failed to insert document: %s" , err )
247- }
248- defer resp .Body .Close ()
210+ resp , _ := a .RequestToQuesma (ctx , t , "POST" , "/logs-3/_doc" , []byte (`{"name": "Przemyslaw", "age": 31337}` ))
249211 assert .Equal (t , http .StatusOK , resp .StatusCode )
250212
251213 chQuery := "SELECT * FROM 'logs-3'"
@@ -313,15 +275,8 @@ func (a *DualWriteAndCommonTableTestcase) testWildcardGoesToElastic(ctx context.
313275 t .Fatalf ("Failed to refresh index: %s" , err )
314276 }
315277 // When Quesma searches for that document
316- resp , err := a .RequestToQuesma (ctx , "POST" , "/unmentioned_index/_search" , []byte (`{"query": {"match_all": {}}}` ))
317- if err != nil {
318- t .Fatalf ("Failed to make GET request: %s" , err )
319- }
320- defer resp .Body .Close ()
321- bodyBytes , err := io .ReadAll (resp .Body )
322- if err != nil {
323- t .Fatalf ("Failed to read response body: %s" , err )
324- }
278+ resp , bodyBytes := a .RequestToQuesma (ctx , t , "POST" , "/unmentioned_index/_search" , []byte (`{"query": {"match_all": {}}}` ))
279+
325280 var jsonResponse map [string ]interface {}
326281 if err := json .Unmarshal (bodyBytes , & jsonResponse ); err != nil {
327282 t .Fatalf ("Failed to unmarshal response body: %s" , err )
0 commit comments