This repository was archived by the owner on Nov 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Adding some integration tests #876
Merged
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
85d5a2f
Use special syntax for mentions
mieciu 895ada6
test
mieciu ba414ce
test two pipelines and empty target
mieciu a72890f
one more example
mieciu 3420247
one more example
mieciu 1ec716f
test
mieciu fac97c4
dual write test
mieciu b4132ed
dual query returns from CH
mieciu e72b4aa
COMPLETE SET
mieciu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| frontendConnectors: | ||
| - name: elastic-ingest | ||
| type: elasticsearch-fe-ingest | ||
| config: | ||
| listenPort: 8080 | ||
| - name: elastic-query | ||
| type: elasticsearch-fe-query | ||
| config: | ||
| listenPort: 8080 | ||
| backendConnectors: | ||
| - name: my-minimal-elasticsearch | ||
| type: elasticsearch | ||
| config: | ||
| url: "http://{{ .elasticsearch_host }}:{{ .elasticsearch_port }}" | ||
| user: elastic | ||
| password: quesmaquesma | ||
| - name: my-hydrolix-instance | ||
| type: clickhouse-os | ||
| config: | ||
| url: clickhouse://{{ .clickhouse_host }}:{{ .clickhouse_port }} | ||
| ingestStatistics: true | ||
| processors: | ||
| - name: my-query-processor | ||
| type: quesma-v1-processor-query | ||
| config: | ||
| indexes: | ||
| siem: | ||
| target: [my-hydrolix-instance] | ||
| logs: | ||
| target: [my-hydrolix-instance] | ||
| test_index: | ||
| target: [my-minimal-elasticsearch] | ||
| "*": | ||
| target: [ my-minimal-elasticsearch ] | ||
| - name: my-ingest-processor | ||
| type: quesma-v1-processor-ingest | ||
| config: | ||
| indexes: | ||
| test_index: | ||
| target: [ my-minimal-elasticsearch ] | ||
| logs_disabled: | ||
| target: [ ] | ||
| "*": | ||
| target: [ my-minimal-elasticsearch ] | ||
| pipelines: | ||
| - name: my-elasticsearch-proxy-read | ||
| frontendConnectors: [ elastic-query ] | ||
| processors: [ my-query-processor ] | ||
| backendConnectors: [ my-minimal-elasticsearch, my-hydrolix-instance ] | ||
| - name: my-elasticsearch-proxy-write | ||
| frontendConnectors: [ elastic-ingest ] | ||
| processors: [ my-ingest-processor ] | ||
| backendConnectors: [ my-minimal-elasticsearch, my-hydrolix-instance ] | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| package testcases | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "github.com/stretchr/testify/assert" | ||
| "io" | ||
| "net/http" | ||
| "testing" | ||
| ) | ||
|
|
||
| type QueryAndIngestPipelineTestcase struct { | ||
| IntegrationTestcaseBase | ||
| } | ||
|
|
||
| func NewQueryAndIngestPipelineTestcase() *QueryAndIngestPipelineTestcase { | ||
| return &QueryAndIngestPipelineTestcase{ | ||
| IntegrationTestcaseBase: IntegrationTestcaseBase{ | ||
| ConfigTemplate: "quesma-with-two-pipelines.yml.template", | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func (a *QueryAndIngestPipelineTestcase) SetupContainers(ctx context.Context) error { | ||
| containers, err := setupAllContainersWithCh(ctx, a.ConfigTemplate) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| a.Containers = containers | ||
| return nil | ||
| } | ||
|
|
||
| func (a *QueryAndIngestPipelineTestcase) RunTests(ctx context.Context, t *testing.T) error { | ||
| a.testBasicRequest(ctx, t) | ||
| a.testWildcardGoesToElastic(ctx, t) | ||
| a.testEmptyTargetDoc(ctx, t) | ||
| a.testEmptyTargetBulk(ctx, t) | ||
| return nil | ||
| } | ||
|
|
||
| func (a *QueryAndIngestPipelineTestcase) testBasicRequest(ctx context.Context, t *testing.T) { | ||
| resp, err := a.RequestToQuesma(ctx, "GET", "/", nil) | ||
| if err != nil { | ||
| t.Fatalf("Failed to make GET request: %s", err) | ||
| } | ||
| defer resp.Body.Close() | ||
| assert.Equal(t, 200, resp.StatusCode) | ||
| } | ||
|
|
||
| func (a *QueryAndIngestPipelineTestcase) testWildcardGoesToElastic(ctx context.Context, t *testing.T) { | ||
| // Given an index in Elasticsearch which falls under `*` in the configuration | ||
| var err error | ||
| if _, err = a.RequestToElasticsearch(ctx, "PUT", "/unmentioned_index", nil); err != nil { | ||
| t.Fatalf("Failed to create index: %s", err) | ||
| } | ||
| if _, err = a.RequestToElasticsearch(ctx, "POST", "/unmentioned_index/_doc/1", []byte(`{"name": "Alice"}`)); err != nil { | ||
| t.Fatalf("Failed to insert document: %s", err) | ||
| } | ||
| if _, err = a.RequestToElasticsearch(ctx, "POST", "/unmentioned_index/_refresh", nil); err != nil { | ||
| t.Fatalf("Failed to refresh index: %s", err) | ||
| } | ||
| // When Quesma searches for that document | ||
| resp, err := a.RequestToQuesma(ctx, "POST", "/unmentioned_index/_search", []byte(`{"query": {"match_all": {}}}`)) | ||
| if err != nil { | ||
| t.Fatalf("Failed to make GET request: %s", err) | ||
| } | ||
| defer resp.Body.Close() | ||
| bodyBytes, err := io.ReadAll(resp.Body) | ||
| if err != nil { | ||
| t.Fatalf("Failed to read response body: %s", err) | ||
| } | ||
| var jsonResponse map[string]interface{} | ||
| if err := json.Unmarshal(bodyBytes, &jsonResponse); err != nil { | ||
| t.Fatalf("Failed to unmarshal response body: %s", err) | ||
| } | ||
| hits, _ := jsonResponse["hits"].(map[string]interface{}) | ||
| // We should get proper search result from Elasticsearch | ||
| hit := hits["total"] | ||
| hitValue := hit.(map[string]interface{})["value"] | ||
| assert.Equal(t, float64(1), hitValue) | ||
| assert.Contains(t, string(bodyBytes), "Alice") | ||
| assert.Equal(t, 200, resp.StatusCode) | ||
| assert.Equal(t, "Elasticsearch", resp.Header.Get("X-Quesma-Source")) | ||
| assert.Equal(t, "Elasticsearch", resp.Header.Get("X-Elastic-Product")) | ||
| } | ||
|
|
||
| func (a *QueryAndIngestPipelineTestcase) testEmptyTargetDoc(ctx context.Context, t *testing.T) { | ||
| resp, err := a.RequestToQuesma(ctx, "POST", "/logs_disabled/_doc", []byte(`{"name": "Alice"}`)) | ||
| if err != nil { | ||
| t.Fatalf("Error sending POST request: %s", err) | ||
| } | ||
| defer resp.Body.Close() | ||
| bodyBytes, err := io.ReadAll(resp.Body) | ||
| if err != nil { | ||
| t.Fatalf("Failed to read response body: %s", err) | ||
| } | ||
|
|
||
| assert.Contains(t, string(bodyBytes), "index_closed_exception") | ||
| assert.Equal(t, http.StatusOK, resp.StatusCode) | ||
| assert.Equal(t, "Clickhouse", resp.Header.Get("X-Quesma-Source")) | ||
| assert.Equal(t, "Elasticsearch", resp.Header.Get("X-Elastic-Product")) | ||
| } | ||
|
|
||
| func (a *QueryAndIngestPipelineTestcase) testEmptyTargetBulk(ctx context.Context, t *testing.T) { | ||
| bulkPayload := []byte(` | ||
| { "index": { "_index": "logs_disabled", "_id": "1" } } | ||
| { "name": "Alice", "age": 30 } | ||
| { "index": { "_index": "logs_disabled", "_id": "2" } } | ||
| { "name": "Bob", "age": 25 } | ||
|
|
||
| `) | ||
| resp, err := a.RequestToQuesma(ctx, "POST", "/_bulk", bulkPayload) | ||
| if err != nil { | ||
| t.Fatalf("Error sending POST request: %s", err) | ||
| } | ||
| defer resp.Body.Close() | ||
| bodyBytes, err := io.ReadAll(resp.Body) | ||
| if err != nil { | ||
| t.Fatalf("Failed to read response body: %s", err) | ||
| } | ||
|
|
||
| assert.Contains(t, string(bodyBytes), "index_closed_exception") | ||
| assert.Equal(t, http.StatusOK, resp.StatusCode) | ||
| assert.Equal(t, "Clickhouse", resp.Header.Get("X-Quesma-Source")) | ||
| assert.Equal(t, "Elasticsearch", resp.Header.Get("X-Elastic-Product")) | ||
| } | ||
|
|
||
| // TODO: A POST to /logs_disabled/_doc/:id is going to be routed to Elasticsearch and will return result in writing to the index. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.