From 94e02c44009b9b2137779722344a2e0268325b76 Mon Sep 17 00:00:00 2001 From: bayraktugrul Date: Sat, 7 Sep 2024 15:45:57 +0300 Subject: [PATCH 1/3] test: separate integration tests and do some refactoring --- internal/testing/constants/constants.go | 7 +- internal/testing/elasticsearch_repository.go | 89 ++++++++++--- internal/testing/integration_test.go | 130 ------------------- internal/testing/query_string_test.go | 45 +++++++ internal/testing/search_response.go | 1 + internal/testing/suite_test.go | 7 +- internal/testing/term_query_test.go | 40 ++++++ internal/testing/terms_query_test.go | 46 +++++++ 8 files changed, 210 insertions(+), 155 deletions(-) delete mode 100644 internal/testing/integration_test.go create mode 100644 internal/testing/query_string_test.go create mode 100644 internal/testing/term_query_test.go create mode 100644 internal/testing/terms_query_test.go diff --git a/internal/testing/constants/constants.go b/internal/testing/constants/constants.go index 07ad196..e3eab5f 100644 --- a/internal/testing/constants/constants.go +++ b/internal/testing/constants/constants.go @@ -1,7 +1,8 @@ package constants const ( - Zero = 0 - True = "true" - StatusOK = 200 + Zero = 0 + True = "true" + StatusOK = 200 + TestIndex = "foo-index" ) diff --git a/internal/testing/elasticsearch_repository.go b/internal/testing/elasticsearch_repository.go index 50b95e7..09f318f 100644 --- a/internal/testing/elasticsearch_repository.go +++ b/internal/testing/elasticsearch_repository.go @@ -16,20 +16,22 @@ type elasticsearchRepository struct { } type ElasticsearchRepository interface { - Search(index, query string) ([]FooDocument, error) - Insert(indexName, docId, document string) error - Delete(indexName, docId string) error - DeleteByQuery(indexName, query string) error - Exists(indexName, docId string) bool + Search(query string) ([]FooDocument, error) + BulkInsert(documents []FooDocument) error + Insert(document FooDocument) error + BulkDelete(docIds []string) error + Delete(docId string) error + DeleteByQuery(query string) error + Exists(docId string) bool } func NewElasticsearchRepository(client *elasticsearch.Client) ElasticsearchRepository { return &elasticsearchRepository{client: client} } -func (e *elasticsearchRepository) Search(index, query string) ([]FooDocument, error) { +func (e *elasticsearchRepository) Search(query string) ([]FooDocument, error) { res, err := e.client.Search( - e.client.Search.WithIndex(index), + e.client.Search.WithIndex(constants.TestIndex), e.client.Search.WithBody(strings.NewReader(query)), ) defer func() { @@ -60,11 +62,41 @@ func (e *elasticsearchRepository) Search(index, query string) ([]FooDocument, er return result, nil } -func (e *elasticsearchRepository) Insert(indexName, docId, document string) error { +func (e *elasticsearchRepository) BulkInsert(documents []FooDocument) error { + var bulkRequestBody strings.Builder + + for i := range documents { + meta := fmt.Sprintf(`{"index":{"_index":"%s","_id":"%s"}}%s`, constants.TestIndex, documents[i], "\n") + bulkRequestBody.WriteString(meta) + + docJson, err := json.Marshal(documents[i]) + if err != nil { + return fmt.Errorf("failed to marshal document with Id %s: %w", documents[i].Id, err) + } + bulkRequestBody.WriteString(string(docJson) + "\n") + } + request := esapi.BulkRequest{ + Body: strings.NewReader(bulkRequestBody.String()), + Refresh: constants.True, + } + + res, err := request.Do(context.Background(), e.client) + if err != nil { + return fmt.Errorf("failed to execute bulk insert request: %w", err) + } + if res.IsError() { + return fmt.Errorf("bulk insert request returned error: %s", res.String()) + } + return nil +} + +func (e *elasticsearchRepository) Insert(document FooDocument) error { + fooDoc, _ := json.Marshal(document) + request := esapi.IndexRequest{ - Index: indexName, - DocumentID: docId, - Body: strings.NewReader(document), + Index: constants.TestIndex, + DocumentID: document.Id, + Body: strings.NewReader(string(fooDoc)), Refresh: constants.True, } @@ -78,9 +110,9 @@ func (e *elasticsearchRepository) Insert(indexName, docId, document string) erro return err } -func (e *elasticsearchRepository) Delete(indexName, docId string) error { +func (e *elasticsearchRepository) Delete(docId string) error { request := esapi.DeleteRequest{ - Index: indexName, + Index: constants.TestIndex, DocumentID: docId, } res, err := request.Do(context.Background(), e.client) @@ -93,9 +125,32 @@ func (e *elasticsearchRepository) Delete(indexName, docId string) error { return err } -func (e *elasticsearchRepository) DeleteByQuery(indexName, query string) error { +func (e *elasticsearchRepository) BulkDelete(docIds []string) error { + var bulkRequestBody strings.Builder + + for _, docId := range docIds { + meta := fmt.Sprintf(`{"delete":{"_index":"%s","_id":"%s"}}%s`, constants.TestIndex, docId, "\n") + bulkRequestBody.WriteString(meta) + } + + request := esapi.BulkRequest{ + Body: strings.NewReader(bulkRequestBody.String()), + Refresh: constants.True, + } + + res, err := request.Do(context.Background(), e.client) + if err != nil { + return fmt.Errorf("failed to execute bulk delete request: %w", err) + } + if res.IsError() { + return fmt.Errorf("bulk delete request returned error: %s", res.String()) + } + return nil +} + +func (e *elasticsearchRepository) DeleteByQuery(query string) error { request := esapi.DeleteByQueryRequest{ - Index: []string{indexName}, + Index: []string{constants.TestIndex}, Body: strings.NewReader(query), } res, err := request.Do(context.Background(), e.client) @@ -108,9 +163,9 @@ func (e *elasticsearchRepository) DeleteByQuery(indexName, query string) error { return err } -func (e *elasticsearchRepository) Exists(indexName, docId string) bool { +func (e *elasticsearchRepository) Exists(docId string) bool { request := esapi.ExistsRequest{ - Index: indexName, + Index: constants.TestIndex, DocumentID: docId, } res, _ := request.Do(context.Background(), e.client) diff --git a/internal/testing/integration_test.go b/internal/testing/integration_test.go deleted file mode 100644 index 8140cca..0000000 --- a/internal/testing/integration_test.go +++ /dev/null @@ -1,130 +0,0 @@ -package testing - -import ( - "encoding/json" - - "github.com/Trendyol/es-query-builder/es" - "github.com/bayraktugrul/go-await" - "github.com/stretchr/testify/assert" -) - -func (s *testSuite) Test_it_should_return_documents_that_filtered_by_term_query() { - // Given - foo := FooDocument{ - Foo: "foo", - } - bar := FooDocument{ - Foo: "bar", - } - - fooDoc, _ := json.Marshal(foo) - barDoc, _ := json.Marshal(bar) - - s.ElasticsearchRepository.Insert(testIndexName, "10", string(fooDoc)) - s.ElasticsearchRepository.Insert(testIndexName, "20", string(barDoc)) - await.New().Await(func() bool { return s.ElasticsearchRepository.Exists(testIndexName, "10") }) - await.New().Await(func() bool { return s.ElasticsearchRepository.Exists(testIndexName, "20") }) - - query := es.NewQuery( - es.Bool().Must( - es.Term("foo", "foo")), - ) - bodyJSON, _ := json.Marshal(query) - - // When - result, err := s.ElasticsearchRepository.Search(testIndexName, string(bodyJSON)) - - // Then - assert.Nil(s.T(), err) - assert.Equal(s.T(), len(result), 1) - assert.Equal(s.T(), result[0].Foo, "foo") - - s.ElasticsearchRepository.Delete(testIndexName, "10") - s.ElasticsearchRepository.Delete(testIndexName, "20") -} - -func (s *testSuite) Test_it_should_return_documents_that_filtered_by_terms_query() { - // Given - doc1 := FooDocument{ - Foo: "foo", - } - doc2 := FooDocument{ - Foo: "mars", - } - doc3 := FooDocument{ - Foo: "earth", - } - - testDoc1, _ := json.Marshal(doc1) - testDoc2, _ := json.Marshal(doc2) - testDoc3, _ := json.Marshal(doc3) - - s.ElasticsearchRepository.Insert(testIndexName, "10", string(testDoc1)) - s.ElasticsearchRepository.Insert(testIndexName, "20", string(testDoc2)) - s.ElasticsearchRepository.Insert(testIndexName, "30", string(testDoc3)) - await.New().Await(func() bool { return s.ElasticsearchRepository.Exists(testIndexName, "10") }) - await.New().Await(func() bool { return s.ElasticsearchRepository.Exists(testIndexName, "20") }) - await.New().Await(func() bool { return s.ElasticsearchRepository.Exists(testIndexName, "30") }) - - query := es.NewQuery( - es.Bool().Must( - es.Terms("foo", "earth", "mars")), - ) - bodyJSON, _ := json.Marshal(query) - - // When - result, err := s.ElasticsearchRepository.Search(testIndexName, string(bodyJSON)) - - // Then - assert.Nil(s.T(), err) - assert.Equal(s.T(), len(result), 2) - assert.Contains(s.T(), result, doc2) - assert.Contains(s.T(), result, doc3) - - s.ElasticsearchRepository.Delete(testIndexName, "10") - s.ElasticsearchRepository.Delete(testIndexName, "20") - s.ElasticsearchRepository.Delete(testIndexName, "30") -} - -func (s *testSuite) Test_it_should_return_documents_that_filtered_by_query_string_with_wildcard_or_operator() { - // Given - foo := FooDocument{ - Foo: "foo", - } - bar := FooDocument{ - Foo: "bar", - } - george := FooDocument{ - Foo: "george orwell", - } - - fooDoc, _ := json.Marshal(foo) - barDoc, _ := json.Marshal(bar) - georgeDoc, _ := json.Marshal(george) - - s.ElasticsearchRepository.Insert(testIndexName, "10", string(fooDoc)) - s.ElasticsearchRepository.Insert(testIndexName, "20", string(barDoc)) - s.ElasticsearchRepository.Insert(testIndexName, "30", string(georgeDoc)) - await.New().Await(func() bool { return s.ElasticsearchRepository.Exists(testIndexName, "10") }) - await.New().Await(func() bool { return s.ElasticsearchRepository.Exists(testIndexName, "20") }) - await.New().Await(func() bool { return s.ElasticsearchRepository.Exists(testIndexName, "30") }) - //f* OR bar - query := es.NewQuery( - es.Bool().Must( - es.QueryString[string]("ge* OR bar").AnalyzeWildcard(true)), - ) - bodyJSON, _ := json.Marshal(query) - - // When - result, err := s.ElasticsearchRepository.Search(testIndexName, string(bodyJSON)) - - // Then - assert.Nil(s.T(), err) - assert.Equal(s.T(), len(result), 2) - assert.Equal(s.T(), result[0].Foo, "george orwell") - assert.Equal(s.T(), result[1].Foo, "bar") - - s.ElasticsearchRepository.Delete(testIndexName, "10") - s.ElasticsearchRepository.Delete(testIndexName, "20") - s.ElasticsearchRepository.Delete(testIndexName, "30") -} diff --git a/internal/testing/query_string_test.go b/internal/testing/query_string_test.go new file mode 100644 index 0000000..a74c30e --- /dev/null +++ b/internal/testing/query_string_test.go @@ -0,0 +1,45 @@ +package testing + +import ( + "encoding/json" + "github.com/Trendyol/es-query-builder/es" + "github.com/bayraktugrul/go-await" + "github.com/stretchr/testify/assert" +) + +func (s *testSuite) Test_it_should_return_documents_that_filtered_by_query_string_with_wildcard_or_operator() { + // Given + foo := FooDocument{ + Id: "10", + Foo: "foo", + } + bar := FooDocument{ + Id: "20", + Foo: "bar", + } + george := FooDocument{ + Id: "30", + Foo: "george orwell", + } + s.ElasticsearchRepository.BulkInsert([]FooDocument{foo, bar, george}) + await.New().Await(func() bool { return s.ElasticsearchRepository.Exists(foo.Id) }) + await.New().Await(func() bool { return s.ElasticsearchRepository.Exists(bar.Id) }) + await.New().Await(func() bool { return s.ElasticsearchRepository.Exists(george.Id) }) + + query := es.NewQuery( + es.Bool().Must( + es.QueryString[string]("ge* OR bar").AnalyzeWildcard(true)), + ) + bodyJSON, _ := json.Marshal(query) + + // When + result, err := s.ElasticsearchRepository.Search(string(bodyJSON)) + + // Then + assert.Nil(s.T(), err) + assert.Equal(s.T(), len(result), 2) + assert.Equal(s.T(), result[0].Foo, "george orwell") + assert.Equal(s.T(), result[1].Foo, "bar") + + s.ElasticsearchRepository.BulkDelete([]string{foo.Id, bar.Id, george.Id}) +} diff --git a/internal/testing/search_response.go b/internal/testing/search_response.go index 06ec0d3..0afe387 100644 --- a/internal/testing/search_response.go +++ b/internal/testing/search_response.go @@ -11,5 +11,6 @@ type Hit struct { } type FooDocument struct { + Id string `json:"id"` Foo string `json:"foo"` } diff --git a/internal/testing/suite_test.go b/internal/testing/suite_test.go index 664acc4..dc87b68 100644 --- a/internal/testing/suite_test.go +++ b/internal/testing/suite_test.go @@ -3,6 +3,7 @@ package testing import ( "context" "fmt" + "integration-tests/constants" "integration-tests/container" "os" "strings" @@ -14,10 +15,6 @@ import ( "github.com/stretchr/testify/suite" ) -const ( - testIndexName = "foo-index" -) - func TestSuite(t *testing.T) { suite.Run(t, new(testSuite)) } @@ -48,7 +45,7 @@ func (s *testSuite) SetupSuite() { s.ElasticsearchRepository = NewElasticsearchRepository(s.ESClient) indicesRequest := esapi.IndicesCreateRequest{ - Index: testIndexName, + Index: constants.TestIndex, Body: strings.NewReader(testIndexBody()), } diff --git a/internal/testing/term_query_test.go b/internal/testing/term_query_test.go new file mode 100644 index 0000000..92205d0 --- /dev/null +++ b/internal/testing/term_query_test.go @@ -0,0 +1,40 @@ +package testing + +import ( + "encoding/json" + "github.com/Trendyol/es-query-builder/es" + "github.com/bayraktugrul/go-await" + "github.com/stretchr/testify/assert" +) + +func (s *testSuite) Test_it_should_return_documents_that_filtered_by_term_query() { + // Given + foo := FooDocument{ + Id: "10", + Foo: "foo", + } + bar := FooDocument{ + Id: "20", + Foo: "bar", + } + + s.ElasticsearchRepository.BulkInsert([]FooDocument{foo, bar}) + await.New().Await(func() bool { return s.ElasticsearchRepository.Exists(foo.Id) }) + await.New().Await(func() bool { return s.ElasticsearchRepository.Exists(bar.Id) }) + + query := es.NewQuery( + es.Bool().Must( + es.Term("foo", "foo")), + ) + bodyJSON, _ := json.Marshal(query) + + // When + result, err := s.ElasticsearchRepository.Search(string(bodyJSON)) + + // Then + assert.Nil(s.T(), err) + assert.Equal(s.T(), len(result), 1) + assert.Equal(s.T(), result[0].Foo, "foo") + + s.ElasticsearchRepository.BulkDelete([]string{foo.Id, bar.Id}) +} diff --git a/internal/testing/terms_query_test.go b/internal/testing/terms_query_test.go new file mode 100644 index 0000000..c5d28c6 --- /dev/null +++ b/internal/testing/terms_query_test.go @@ -0,0 +1,46 @@ +package testing + +import ( + "encoding/json" + "github.com/Trendyol/es-query-builder/es" + "github.com/bayraktugrul/go-await" + "github.com/stretchr/testify/assert" +) + +func (s *testSuite) Test_it_should_return_documents_that_filtered_by_terms_query() { + // Given + doc1 := FooDocument{ + Id: "10", + Foo: "foo", + } + doc2 := FooDocument{ + Id: "20", + Foo: "mars", + } + doc3 := FooDocument{ + Id: "30", + Foo: "earth", + } + + s.ElasticsearchRepository.BulkInsert([]FooDocument{doc1, doc2, doc3}) + await.New().Await(func() bool { return s.ElasticsearchRepository.Exists(doc1.Id) }) + await.New().Await(func() bool { return s.ElasticsearchRepository.Exists(doc2.Id) }) + await.New().Await(func() bool { return s.ElasticsearchRepository.Exists(doc3.Id) }) + + query := es.NewQuery( + es.Bool().Must( + es.Terms("foo", "earth", "mars")), + ) + bodyJSON, _ := json.Marshal(query) + + // When + result, err := s.ElasticsearchRepository.Search(string(bodyJSON)) + + // Then + assert.Nil(s.T(), err) + assert.Equal(s.T(), len(result), 2) + assert.Contains(s.T(), result, doc2) + assert.Contains(s.T(), result, doc3) + + s.ElasticsearchRepository.BulkDelete([]string{doc1.Id, doc2.Id, doc3.Id}) +} From f822b4b53868b250fdf5186e26ed0b57cdf95dc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ksel=20K=C3=BC=C3=A7=C3=BCk=C5=9Fahin?= Date: Sat, 7 Sep 2024 23:22:51 +0300 Subject: [PATCH 2/3] test: sort goimports order. update error messages on elasticsearch_repository to request types. --- internal/testing/elasticsearch_repository.go | 14 ++++++++------ internal/testing/query_string_test.go | 1 + internal/testing/search_response.go | 15 ++++++++------- internal/testing/suite_test.go | 5 +++-- internal/testing/term_query_test.go | 1 + internal/testing/terms_query_test.go | 1 + 6 files changed, 22 insertions(+), 15 deletions(-) diff --git a/internal/testing/elasticsearch_repository.go b/internal/testing/elasticsearch_repository.go index 09f318f..cf5eb6c 100644 --- a/internal/testing/elasticsearch_repository.go +++ b/internal/testing/elasticsearch_repository.go @@ -4,11 +4,13 @@ import ( "context" "encoding/json" "fmt" + "net/http" + "strings" + "github.com/elastic/go-elasticsearch/v8" "github.com/elastic/go-elasticsearch/v8/esapi" + "integration-tests/constants" - "net/http" - "strings" ) type elasticsearchRepository struct { @@ -117,10 +119,10 @@ func (e *elasticsearchRepository) Delete(docId string) error { } res, err := request.Do(context.Background(), e.client) if err != nil { - return fmt.Errorf("failed to execute insert request: %w", err) + return fmt.Errorf("failed to execute delete request: %w", err) } if res.IsError() { - return fmt.Errorf("insert request returned error: %s", res.String()) + return fmt.Errorf("delete request returned error: %s", res.String()) } return err } @@ -155,10 +157,10 @@ func (e *elasticsearchRepository) DeleteByQuery(query string) error { } res, err := request.Do(context.Background(), e.client) if err != nil { - return fmt.Errorf("failed to execute insert request: %w", err) + return fmt.Errorf("failed to execute delete by query request: %w", err) } if res.IsError() { - return fmt.Errorf("insert request returned error: %s", res.String()) + return fmt.Errorf("delete by query request returned error: %s", res.String()) } return err } diff --git a/internal/testing/query_string_test.go b/internal/testing/query_string_test.go index a74c30e..69a8e29 100644 --- a/internal/testing/query_string_test.go +++ b/internal/testing/query_string_test.go @@ -2,6 +2,7 @@ package testing import ( "encoding/json" + "github.com/Trendyol/es-query-builder/es" "github.com/bayraktugrul/go-await" "github.com/stretchr/testify/assert" diff --git a/internal/testing/search_response.go b/internal/testing/search_response.go index 0afe387..f1cd530 100644 --- a/internal/testing/search_response.go +++ b/internal/testing/search_response.go @@ -1,16 +1,17 @@ package testing -type SearchResponse struct { - Hits struct { - Hits []Hit `json:"hits"` - } `json:"hits"` +type FooDocument struct { + Id string `json:"id"` + Foo string `json:"foo"` } type Hit struct { Source FooDocument `json:"_source"` } -type FooDocument struct { - Id string `json:"id"` - Foo string `json:"foo"` +type Hits struct { + Hits []Hit `json:"hits"` +} +type SearchResponse struct { + Hits Hits `json:"hits"` } diff --git a/internal/testing/suite_test.go b/internal/testing/suite_test.go index dc87b68..9fbc363 100644 --- a/internal/testing/suite_test.go +++ b/internal/testing/suite_test.go @@ -3,8 +3,6 @@ package testing import ( "context" "fmt" - "integration-tests/constants" - "integration-tests/container" "os" "strings" "testing" @@ -13,6 +11,9 @@ import ( "github.com/elastic/go-elasticsearch/v8" "github.com/elastic/go-elasticsearch/v8/esapi" "github.com/stretchr/testify/suite" + + "integration-tests/constants" + "integration-tests/container" ) func TestSuite(t *testing.T) { diff --git a/internal/testing/term_query_test.go b/internal/testing/term_query_test.go index 92205d0..e33dd5b 100644 --- a/internal/testing/term_query_test.go +++ b/internal/testing/term_query_test.go @@ -2,6 +2,7 @@ package testing import ( "encoding/json" + "github.com/Trendyol/es-query-builder/es" "github.com/bayraktugrul/go-await" "github.com/stretchr/testify/assert" diff --git a/internal/testing/terms_query_test.go b/internal/testing/terms_query_test.go index c5d28c6..c42c1db 100644 --- a/internal/testing/terms_query_test.go +++ b/internal/testing/terms_query_test.go @@ -2,6 +2,7 @@ package testing import ( "encoding/json" + "github.com/Trendyol/es-query-builder/es" "github.com/bayraktugrul/go-await" "github.com/stretchr/testify/assert" From de733d0ca7f89ec76ee92c95c494a23001977196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ksel=20K=C3=BC=C3=A7=C3=BCk=C5=9Fahin?= Date: Sat, 7 Sep 2024 23:22:51 +0300 Subject: [PATCH 3/3] test: sort goimports order. update error messages on elasticsearch_repository to request types. --- internal/testing/elasticsearch_repository.go | 14 ++++++++------ internal/testing/query_string_test.go | 1 + internal/testing/search_response.go | 16 +++++++++------- internal/testing/suite_test.go | 5 +++-- internal/testing/term_query_test.go | 1 + internal/testing/terms_query_test.go | 1 + 6 files changed, 23 insertions(+), 15 deletions(-) diff --git a/internal/testing/elasticsearch_repository.go b/internal/testing/elasticsearch_repository.go index 09f318f..cf5eb6c 100644 --- a/internal/testing/elasticsearch_repository.go +++ b/internal/testing/elasticsearch_repository.go @@ -4,11 +4,13 @@ import ( "context" "encoding/json" "fmt" + "net/http" + "strings" + "github.com/elastic/go-elasticsearch/v8" "github.com/elastic/go-elasticsearch/v8/esapi" + "integration-tests/constants" - "net/http" - "strings" ) type elasticsearchRepository struct { @@ -117,10 +119,10 @@ func (e *elasticsearchRepository) Delete(docId string) error { } res, err := request.Do(context.Background(), e.client) if err != nil { - return fmt.Errorf("failed to execute insert request: %w", err) + return fmt.Errorf("failed to execute delete request: %w", err) } if res.IsError() { - return fmt.Errorf("insert request returned error: %s", res.String()) + return fmt.Errorf("delete request returned error: %s", res.String()) } return err } @@ -155,10 +157,10 @@ func (e *elasticsearchRepository) DeleteByQuery(query string) error { } res, err := request.Do(context.Background(), e.client) if err != nil { - return fmt.Errorf("failed to execute insert request: %w", err) + return fmt.Errorf("failed to execute delete by query request: %w", err) } if res.IsError() { - return fmt.Errorf("insert request returned error: %s", res.String()) + return fmt.Errorf("delete by query request returned error: %s", res.String()) } return err } diff --git a/internal/testing/query_string_test.go b/internal/testing/query_string_test.go index a74c30e..69a8e29 100644 --- a/internal/testing/query_string_test.go +++ b/internal/testing/query_string_test.go @@ -2,6 +2,7 @@ package testing import ( "encoding/json" + "github.com/Trendyol/es-query-builder/es" "github.com/bayraktugrul/go-await" "github.com/stretchr/testify/assert" diff --git a/internal/testing/search_response.go b/internal/testing/search_response.go index 0afe387..98ee27e 100644 --- a/internal/testing/search_response.go +++ b/internal/testing/search_response.go @@ -1,16 +1,18 @@ package testing -type SearchResponse struct { - Hits struct { - Hits []Hit `json:"hits"` - } `json:"hits"` +type FooDocument struct { + Id string `json:"id"` + Foo string `json:"foo"` } type Hit struct { Source FooDocument `json:"_source"` } -type FooDocument struct { - Id string `json:"id"` - Foo string `json:"foo"` +type Hits struct { + Hits []Hit `json:"hits"` +} + +type SearchResponse struct { + Hits Hits `json:"hits"` } diff --git a/internal/testing/suite_test.go b/internal/testing/suite_test.go index dc87b68..9fbc363 100644 --- a/internal/testing/suite_test.go +++ b/internal/testing/suite_test.go @@ -3,8 +3,6 @@ package testing import ( "context" "fmt" - "integration-tests/constants" - "integration-tests/container" "os" "strings" "testing" @@ -13,6 +11,9 @@ import ( "github.com/elastic/go-elasticsearch/v8" "github.com/elastic/go-elasticsearch/v8/esapi" "github.com/stretchr/testify/suite" + + "integration-tests/constants" + "integration-tests/container" ) func TestSuite(t *testing.T) { diff --git a/internal/testing/term_query_test.go b/internal/testing/term_query_test.go index 92205d0..e33dd5b 100644 --- a/internal/testing/term_query_test.go +++ b/internal/testing/term_query_test.go @@ -2,6 +2,7 @@ package testing import ( "encoding/json" + "github.com/Trendyol/es-query-builder/es" "github.com/bayraktugrul/go-await" "github.com/stretchr/testify/assert" diff --git a/internal/testing/terms_query_test.go b/internal/testing/terms_query_test.go index c5d28c6..c42c1db 100644 --- a/internal/testing/terms_query_test.go +++ b/internal/testing/terms_query_test.go @@ -2,6 +2,7 @@ package testing import ( "encoding/json" + "github.com/Trendyol/es-query-builder/es" "github.com/bayraktugrul/go-await" "github.com/stretchr/testify/assert"