-
Couldn't load subscription status.
- Fork 127
[system testing] Add provision for system testing negative / false-positive scenarios in packages #1333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[system testing] Add provision for system testing negative / false-positive scenarios in packages #1333
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
10b905a
Recheck for more hits
bhapas 9bc8c61
Change the retry interval to 5 seconds
bhapas bf232cc
Add a test for false positives
bhapas 0a0094f
Move the false_positives to own execution
bhapas f92d3e7
Add test to buildkite
bhapas c91f182
Fix PR comments
bhapas 8bbf9cd
Add separate package run in CI
bhapas 6109a0f
Remove redundant check
bhapas 23a011a
Fix formatting
bhapas 530e9fe
Apply PR comment
bhapas 0fcce17
Upload logs to a safe location
bhapas 4d2190c
Fix script
bhapas 68fb07a
Modify false positive test execution target
bhapas 8deca24
Add integration-false_positives as step for GCS credentials
mrodm d486799
Update scripts/test-check-false-positives.sh
bhapas 51e33f4
Check for expected errors in false_positives script
mrodm 08933fe
Try with same number but different error
mrodm 30bf3b0
Set the right expected errors
mrodm c2d77cb
Add negative system tests to documentation
bhapas 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
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
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,91 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euxo pipefail | ||
|
|
||
| cleanup() { | ||
| r=$? | ||
|
|
||
| # Dump stack logs | ||
| elastic-package stack dump -v --output "build/elastic-stack-dump/check-${PACKAGE_UNDER_TEST:-${PACKAGE_TEST_TYPE:-*}}" | ||
|
|
||
| # Take down the stack | ||
| elastic-package stack down -v | ||
|
|
||
| # Clean used resources | ||
| for d in test/packages/${PACKAGE_TEST_TYPE:-false_positives}/${PACKAGE_UNDER_TEST:-*}/; do | ||
| ( | ||
| cd $d | ||
| elastic-package clean -v | ||
| ) | ||
| done | ||
|
|
||
| # This is a false positive scenario and tests that the test case failure is a success scenario | ||
| if [ "${PACKAGE_TEST_TYPE:-false_positives}" == "false_positives" ]; then | ||
| if [ $r == 1 ]; then | ||
| EXPECTED_ERRORS_FILE="test/packages/false_positives/${PACKAGE_UNDER_TEST}.expected_errors" | ||
| if [ ! -f ${EXPECTED_ERRORS_FILE} ]; then | ||
| echo "Error: Missing expected errors file: ${EXPECTED_ERRORS_FILE}" | ||
| fi | ||
| RESULTS_NO_SPACES="build/test-results-no-spaces.xml" | ||
| cat build/test-results/*.xml | tr -d '\n' > ${RESULTS_NO_SPACES} | ||
|
|
||
| # check number of expected errors | ||
| number_errors=$(cat build/test-results/*.xml | grep "<failure>" | wc -l) | ||
| expected_errors=$(cat ${EXPECTED_ERRORS_FILE} | wc -l) | ||
|
|
||
| if [ ${number_errors} -ne ${expected_errors} ]; then | ||
| echo "Error: There are unexpected errors in ${PACKAGE_UNDER_TEST}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # check whether or not the expected errors exist in the xml files | ||
| while read -r line; do | ||
| cat ${RESULTS_NO_SPACES} | grep -E "${line}" | ||
| done < ${EXPECTED_ERRORS_FILE} | ||
| rm -f build/test-results/*.xml | ||
| rm -f ${RESULTS_NO_SPACES} | ||
| exit 0 | ||
| elif [ $r == 0 ]; then | ||
| echo "Error: Expected to fail tests, but there was none failing" | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| exit $r | ||
| } | ||
|
|
||
| trap cleanup EXIT | ||
|
|
||
| export ELASTIC_PACKAGE_LINKS_FILE_PATH="$(pwd)/scripts/links_table.yml" | ||
|
|
||
| OLDPWD=$PWD | ||
| # Build/check packages | ||
| for d in test/packages/${PACKAGE_TEST_TYPE:-false_positives}/${PACKAGE_UNDER_TEST:-*}/; do | ||
| ( | ||
| cd $d | ||
| elastic-package check -v | ||
| ) | ||
| done | ||
| cd - | ||
|
|
||
| # Update the stack | ||
| elastic-package stack update -v | ||
|
|
||
| # Boot up the stack | ||
| elastic-package stack up -d -v | ||
|
|
||
| elastic-package stack status | ||
|
|
||
| # Run package tests | ||
| eval "$(elastic-package stack shellinit)" | ||
|
|
||
| for d in test/packages/${PACKAGE_TEST_TYPE:-false_positives}/${PACKAGE_UNDER_TEST:-*}/; do | ||
| ( | ||
| cd $d | ||
| elastic-package install -v | ||
|
|
||
| # defer-cleanup is set to a short period to verify that the option is available | ||
| elastic-package test -v --report-format xUnit --report-output file --defer-cleanup 1s --test-coverage | ||
| ) | ||
| cd - | ||
| done |
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 |
|---|---|---|
|
|
@@ -29,7 +29,7 @@ cleanup() { | |
| elastic-package clean -v | ||
| ) | ||
| done | ||
|
|
||
| exit $r | ||
| } | ||
|
|
||
|
|
||
1 change: 1 addition & 0 deletions
1
test/packages/false_positives/httpjson_false_positive_asserts.expected_errors
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 @@ | ||
| <testcase name=\"system test: pagination\" classname=\"httpjson_false_positive_asserts.generic\" time=\".*\"> * <failure>observed hit count 4 did not match expected hit count 2</failure> |
3 changes: 3 additions & 0 deletions
3
test/packages/false_positives/httpjson_false_positive_asserts/_dev/build/build.yml
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,3 @@ | ||
| dependencies: | ||
| ecs: | ||
| reference: git@v8.8.0 |
20 changes: 20 additions & 0 deletions
20
...kages/false_positives/httpjson_false_positive_asserts/_dev/build/docs/README.md
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,20 @@ | ||
| # Custom API input integration | ||
|
|
||
| The custom API input integration is used to ingest data from custom RESTful API's that do not currently have an existing integration. | ||
|
|
||
| The input itself supports sending both GET and POST requests, transform requests and responses during runtime, paginate and keep a running state on information from the last collected events. | ||
|
|
||
| ## Configuration | ||
|
|
||
| The extensive documentation for the input are currently available | ||
|
|
||
| The most commonly used configuration options are available on the main integration page, while more advanced and customizable options currently resides under the "Advanced options" part of the integration settings page. | ||
|
|
||
| Configuration is split into three main categories, Request, Response, and Cursor. | ||
|
|
||
| The request part of the configuration handles points like which URL endpoint to communicate with, the request body, specific transformations that have to happen before a request is sent out and some custom options like request proxy, timeout and similar options. | ||
|
|
||
| The response part of the configuration handles options like transformation, rate limiting, pagination, and splitting the response into different documents before it is sent to Elasticsearch. | ||
|
|
||
| The cursor part of the configuration is used when there is a need to keep state between each of the API requests, for example if a timestamp is returned in the response, that should be used as a filter in the next request after that, the cursor is a place where this is stored. | ||
|
|
14 changes: 14 additions & 0 deletions
14
...ges/false_positives/httpjson_false_positive_asserts/_dev/deploy/docker/docker-compose.yml
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,14 @@ | ||
| version: "2.3" | ||
| services: | ||
| httpjson: | ||
| image: docker.elastic.co/observability/stream:v0.7.0 | ||
| ports: | ||
| - 8080 | ||
| volumes: | ||
| - ./files:/files:ro | ||
| environment: | ||
| PORT: 8080 | ||
| command: | ||
| - http-server | ||
| - --addr=:8080 | ||
| - --config=/files/config.yml |
21 changes: 21 additions & 0 deletions
21
...kages/false_positives/httpjson_false_positive_asserts/_dev/deploy/docker/files/config.yml
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,21 @@ | ||
| rules: | ||
| - path: /testpagination/api | ||
| methods: ["GET"] | ||
| query_params: | ||
| page: 1 | ||
| request_headers: | ||
| Authorization: "Basic dGVzdDp0ZXN0" | ||
| responses: | ||
| - status_code: 200 | ||
| body: |- | ||
| {"message": "success", "page": 2} | ||
| - path: /testpagination/api | ||
| methods: ["GET"] | ||
| query_params: | ||
| page: 2 | ||
| request_headers: | ||
| Authorization: "Basic dGVzdDp0ZXN0" | ||
| responses: | ||
| - status_code: 200 | ||
| body: |- | ||
| {"message": "success"} |
5 changes: 5 additions & 0 deletions
5
test/packages/false_positives/httpjson_false_positive_asserts/changelog.yml
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,5 @@ | ||
| - version: "999.999.999" | ||
| changes: | ||
| - description: Test assert.hit_count | ||
| type: enhancement | ||
| link: https://github.com/elastic/integrations/pull/6326 |
18 changes: 18 additions & 0 deletions
18
...on_false_positive_asserts/data_stream/generic/_dev/test/system/test-pagination-config.yml
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,18 @@ | ||
| wait_for_data_timeout: 20s | ||
| input: httpjson | ||
| service: httpjson | ||
| data_stream: | ||
| vars: | ||
| data_stream.dataset: httpjson.generic | ||
| username: test | ||
| password: test | ||
| request_interval: 5s | ||
| request_url: http://{{Hostname}}:{{Port}}/testpagination/api?page=1 | ||
| response_pagination: |- | ||
| - set: | ||
| target: url.params.page | ||
| value: '[[.last_response.body.page]]' | ||
| fail_on_template_error: true | ||
| enable_request_tracer: true | ||
| assert: | ||
| hit_count: 2 |
Oops, something went wrong.
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.