mirror of
https://github.com/fjogeleit/http-request-action.git
synced 2024-11-21 11:20:57 -05:00
Add tests with assertions (#154)
That way not only inputs are tested but also outputs
This commit is contained in:
parent
44816be1ea
commit
aeef78bb14
2 changed files with 315 additions and 103 deletions
103
.github/workflows/ci.yml
vendored
103
.github/workflows/ci.yml
vendored
|
@ -69,106 +69,3 @@ jobs:
|
||||||
- name: Repository Integrity Check
|
- name: Repository Integrity Check
|
||||||
run: |
|
run: |
|
||||||
git diff --quiet dist
|
git diff --quiet dist
|
||||||
test:
|
|
||||||
if: >
|
|
||||||
!failure() &&
|
|
||||||
!cancelled()
|
|
||||||
needs:
|
|
||||||
- integrity
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
ref: ${{ github.ref }}
|
|
||||||
|
|
||||||
- name: Request Postman Echo GET
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
url: 'https://postman-echo.com/get'
|
|
||||||
method: 'GET'
|
|
||||||
|
|
||||||
- name: Request Postman Echo POST
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
url: 'https://postman-echo.com/post'
|
|
||||||
method: 'POST'
|
|
||||||
data: '{ "key": "value" }'
|
|
||||||
|
|
||||||
- name: Request Postman Echo POST with Unescaped Newline
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
url: 'https://postman-echo.com/post'
|
|
||||||
method: 'POST'
|
|
||||||
escapeData: 'true'
|
|
||||||
data: >-
|
|
||||||
{
|
|
||||||
"key":"multi line\ntest
|
|
||||||
text"
|
|
||||||
}
|
|
||||||
|
|
||||||
- name: Request Postman Echo BasicAuth
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
url: 'https://postman-echo.com/basic-auth'
|
|
||||||
method: 'GET'
|
|
||||||
username: 'postman'
|
|
||||||
password: 'password'
|
|
||||||
|
|
||||||
- name: Request Postman Echo with 404 Response and ignore failure code
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
url: 'https://postman-echo.com/status/404'
|
|
||||||
method: 'GET'
|
|
||||||
ignoreStatusCodes: '404'
|
|
||||||
|
|
||||||
- name: Create Test File
|
|
||||||
run: |
|
|
||||||
echo "test" > testfile.txt
|
|
||||||
- name: Request Postman Echo POST Multipart
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
url: 'https://postman-echo.com/post'
|
|
||||||
method: 'POST'
|
|
||||||
data: '{ "key": "value" }'
|
|
||||||
files: '{ "file": "${{ github.workspace }}/testfile.txt" }'
|
|
||||||
|
|
||||||
- name: Request Postman Echo POST and persist response
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
url: 'https://postman-echo.com/post'
|
|
||||||
method: 'POST'
|
|
||||||
file: "${{ github.workspace }}/testfile.txt"
|
|
||||||
responseFile: "${{ github.workspace }}/response.json"
|
|
||||||
- name: Output responseFile
|
|
||||||
run: |
|
|
||||||
cat "${{ github.workspace }}/response.json"
|
|
||||||
|
|
||||||
- name: Request Postman Echo POST Multipart without data
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
url: 'https://postman-echo.com/post'
|
|
||||||
method: 'POST'
|
|
||||||
files: '{ "file": "${{ github.workspace }}/testfile.txt" }'
|
|
||||||
|
|
||||||
- name: Request Postman Echo POST single file
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
url: 'https://postman-echo.com/post'
|
|
||||||
method: 'POST'
|
|
||||||
file: "${{ github.workspace }}/testfile.txt"
|
|
||||||
|
|
||||||
- name: Request Postman Echo POST URLEncoded string data
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
url: 'https://postman-echo.com/post'
|
|
||||||
contentType : 'application/x-www-form-urlencoded'
|
|
||||||
method: 'POST'
|
|
||||||
data: 'key=value'
|
|
||||||
|
|
||||||
- name: Request Postman Echo POST URLEncoded json data
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
url: 'https://postman-echo.com/post'
|
|
||||||
contentType : 'application/x-www-form-urlencoded'
|
|
||||||
method: 'POST'
|
|
||||||
data: '{"key":"value"}'
|
|
||||||
|
|
315
.github/workflows/it-tests.yml
vendored
Normal file
315
.github/workflows/it-tests.yml
vendored
Normal file
|
@ -0,0 +1,315 @@
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
test-method-get-on-existing-url:
|
||||||
|
name: "IT Test - Request Postman Echo GET"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
||||||
|
- name: Given the gh-action is used with GET and a valid URL
|
||||||
|
id: execution
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
url: 'https://postman-echo.com/get'
|
||||||
|
method: 'GET'
|
||||||
|
|
||||||
|
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||||
|
name: Then outputs.status value must be 200
|
||||||
|
with:
|
||||||
|
expected: '200'
|
||||||
|
actual: ${{ steps.execution.outputs.status }}
|
||||||
|
comparison: exact
|
||||||
|
|
||||||
|
test-method-post-on-existing-url:
|
||||||
|
name: "IT Test - Request Postman Echo POST"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
||||||
|
- name: Given the gh-action is used with POST using valid data
|
||||||
|
id: execution
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
url: "https://postman-echo.com/post"
|
||||||
|
method: 'POST'
|
||||||
|
data: '{ "key": "value" }'
|
||||||
|
|
||||||
|
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||||
|
name: Then outputs.status value must be 200
|
||||||
|
with:
|
||||||
|
expected: '200'
|
||||||
|
actual: ${{ steps.execution.outputs.status }}
|
||||||
|
comparison: exact
|
||||||
|
|
||||||
|
test-method-post-on-existing-url-with-unescaped-newline:
|
||||||
|
name: "IT Test - Request Postman Echo POST with Unescaped Newline"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
||||||
|
- name: Given the gh-action is used with POST using unescaped new line within data
|
||||||
|
id: execution
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
url: "https://postman-echo.com/post"
|
||||||
|
method: 'POST'
|
||||||
|
escapeData: 'true'
|
||||||
|
data: >-
|
||||||
|
{
|
||||||
|
"key":"multi line\ntest
|
||||||
|
text"
|
||||||
|
}
|
||||||
|
|
||||||
|
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||||
|
name: Then outputs.status value must be 200
|
||||||
|
with:
|
||||||
|
expected: '200'
|
||||||
|
actual: ${{ steps.execution.outputs.status }}
|
||||||
|
comparison: exact
|
||||||
|
|
||||||
|
test-basic-auth:
|
||||||
|
name: "IT Test - Request Postman Echo BasicAuth"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
||||||
|
- name: Given the gh-action is used with valid BasicAuth parameters
|
||||||
|
id: execution
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
url: 'https://postman-echo.com/basic-auth'
|
||||||
|
method: 'GET'
|
||||||
|
username: 'postman'
|
||||||
|
password: 'password'
|
||||||
|
|
||||||
|
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||||
|
name: Then outputs.status value must be 200 as this URL exists
|
||||||
|
with:
|
||||||
|
expected: '200'
|
||||||
|
actual: ${{ steps.execution.outputs.status }}
|
||||||
|
comparison: exact
|
||||||
|
|
||||||
|
test-input-ignore-failure-code-404:
|
||||||
|
name: "IT Test - Request Postman Echo with 404 Response and ignore failure code"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
||||||
|
- name: Given the gh-action is used with unknown URL and ignoreStatusCode 404 for it
|
||||||
|
id: execution
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
url: 'https://postman-echo.com/status/404'
|
||||||
|
method: 'GET'
|
||||||
|
ignoreStatusCodes: '404'
|
||||||
|
|
||||||
|
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||||
|
name: Then outputs.status value must 404
|
||||||
|
with:
|
||||||
|
expected: '404'
|
||||||
|
actual: ${{ steps.execution.outputs.status }}
|
||||||
|
comparison: exact
|
||||||
|
|
||||||
|
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||||
|
name: Then the outcome value must be success as the error 404 is ignored
|
||||||
|
with:
|
||||||
|
expected: 'success'
|
||||||
|
actual: ${{ steps.execution.outcome }}
|
||||||
|
comparison: exact
|
||||||
|
|
||||||
|
test-input-ignore-failure-multiple-codes-401-404:
|
||||||
|
name: "IT Test - Request Postman Echo with 404 Response and ignore failure code"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
||||||
|
- name: Given the gh-action is used with unknown URL and ignore status codes 401,404
|
||||||
|
id: execution
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
url: 'https://postman-echo.com/status/404'
|
||||||
|
method: 'GET'
|
||||||
|
ignoreStatusCodes: '401,404'
|
||||||
|
|
||||||
|
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||||
|
name: Then outputs.status value must be 404
|
||||||
|
with:
|
||||||
|
expected: '404'
|
||||||
|
actual: ${{ steps.execution.outputs.status }}
|
||||||
|
comparison: exact
|
||||||
|
|
||||||
|
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||||
|
name: Then the outcome value must be success as the error 404 is ignored
|
||||||
|
with:
|
||||||
|
expected: 'success'
|
||||||
|
actual: ${{ steps.execution.outcome }}
|
||||||
|
comparison: exact
|
||||||
|
|
||||||
|
test-input-files:
|
||||||
|
name: "IT Test - Request Postman Echo POST Multipart"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
||||||
|
- name: Create Test File
|
||||||
|
run: |
|
||||||
|
echo "test" > testfile.txt
|
||||||
|
- name: Given the gh-action is used with file and data
|
||||||
|
id: execution
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
url: 'https://postman-echo.com/post'
|
||||||
|
method: 'POST'
|
||||||
|
data: '{ "key": "value" }'
|
||||||
|
files: '{ "file": "${{ github.workspace }}/testfile.txt" }'
|
||||||
|
|
||||||
|
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||||
|
name: Then outputs.status value must be 200
|
||||||
|
with:
|
||||||
|
expected: '200'
|
||||||
|
actual: ${{ steps.execution.outputs.status }}
|
||||||
|
comparison: exact
|
||||||
|
|
||||||
|
test-input-responseFile:
|
||||||
|
name: "IT Test - Request Postman Echo POST and persist response"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
||||||
|
- name: Create Test File
|
||||||
|
run: |
|
||||||
|
echo "test" > testfile2.txt
|
||||||
|
- name: Given the gh-action is used with file and responseFile
|
||||||
|
id: execution
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
url: 'https://postman-echo.com/post'
|
||||||
|
method: 'POST'
|
||||||
|
file: "${{ github.workspace }}/testfile2.txt"
|
||||||
|
responseFile: "${{ github.workspace }}/response.json"
|
||||||
|
|
||||||
|
- name: Output responseFile
|
||||||
|
id: execution-response-file
|
||||||
|
run: |
|
||||||
|
echo "response_content=$(cat ${{ github.workspace }}/response.json)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||||
|
name: Then outputs.response_content value must include
|
||||||
|
with:
|
||||||
|
expected: '{"args":{},"data":"test\n","files":{},"form":{},"headers":{"host":"postman-echo.com",'
|
||||||
|
actual: ${{ steps.execution-response-file.outputs.response_content }}
|
||||||
|
comparison: contains
|
||||||
|
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||||
|
name: Then outputs.response_content value must include
|
||||||
|
with:
|
||||||
|
expected: '"accept":"application/json, text/plain, */*","content-type":"application/json","user-agent"'
|
||||||
|
actual: ${{ steps.execution-response-file.outputs.response_content }}
|
||||||
|
comparison: contains
|
||||||
|
|
||||||
|
test-input-files-without-data:
|
||||||
|
name: "IT Test - Request Postman Echo POST Multipart without data"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
||||||
|
- name: Create Test File
|
||||||
|
run: |
|
||||||
|
echo "test" > testfile3.txt
|
||||||
|
- name: Given the gh-action is used with file
|
||||||
|
id: execution
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
url: 'https://postman-echo.com/post'
|
||||||
|
method: 'POST'
|
||||||
|
files: '{ "file": "${{ github.workspace }}/testfile3.txt" }'
|
||||||
|
|
||||||
|
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||||
|
name: Then outputs.status value must be 200
|
||||||
|
with:
|
||||||
|
expected: '200'
|
||||||
|
actual: ${{ steps.execution.outputs.status }}
|
||||||
|
comparison: exact
|
||||||
|
|
||||||
|
test-input-file-with-single-file:
|
||||||
|
name: "IT Test - Request Postman Echo POST single file"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
||||||
|
- name: Create Test File
|
||||||
|
run: |
|
||||||
|
echo "test" > testfile4.txt
|
||||||
|
- name: Given the gh-action is used with file
|
||||||
|
id: execution
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
url: 'https://postman-echo.com/post'
|
||||||
|
method: 'POST'
|
||||||
|
file: "${{ github.workspace }}/testfile4.txt"
|
||||||
|
|
||||||
|
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||||
|
name: Then outputs.status value must be 200
|
||||||
|
with:
|
||||||
|
expected: '200'
|
||||||
|
actual: ${{ steps.execution.outputs.status }}
|
||||||
|
comparison: exact
|
||||||
|
|
||||||
|
test-input-data-with-url-encoded-string:
|
||||||
|
name: "IT Test - Request Postman Echo POST URLEncoded string data"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
||||||
|
- name: Given the gh-action is used with data form url encoded
|
||||||
|
id: execution
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
url: 'https://postman-echo.com/post'
|
||||||
|
contentType : 'application/x-www-form-urlencoded'
|
||||||
|
method: 'POST'
|
||||||
|
data: 'key=value'
|
||||||
|
|
||||||
|
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||||
|
name: Then outputs.status value must be 200
|
||||||
|
with:
|
||||||
|
expected: '200'
|
||||||
|
actual: ${{ steps.execution.outputs.status }}
|
||||||
|
comparison: exact
|
||||||
|
|
||||||
|
test-input-data-with-url-encoded-json-data:
|
||||||
|
name: "IT Test - Request Postman Echo POST URLEncoded json data"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
||||||
|
- name: Given the gh-action is used with json data
|
||||||
|
id: execution
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
url: 'https://postman-echo.com/post'
|
||||||
|
contentType : 'application/x-www-form-urlencoded'
|
||||||
|
method: 'POST'
|
||||||
|
data: '{"key":"value"}'
|
||||||
|
|
||||||
|
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||||
|
name: Then outputs.status value must be 200
|
||||||
|
with:
|
||||||
|
expected: '200'
|
||||||
|
actual: ${{ steps.execution.outputs.status }}
|
||||||
|
comparison: exact
|
||||||
|
|
||||||
|
it-tests:
|
||||||
|
name: "All IT Tests have to pass"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: always()
|
||||||
|
needs:
|
||||||
|
# Add your tests here so that they prevent the merge of broken changes
|
||||||
|
- test-method-get-on-existing-url
|
||||||
|
- test-method-post-on-existing-url
|
||||||
|
- test-method-post-on-existing-url-with-unescaped-newline
|
||||||
|
- test-basic-auth
|
||||||
|
- test-input-ignore-failure-code-404
|
||||||
|
- test-input-ignore-failure-multiple-codes-401-404
|
||||||
|
- test-input-files
|
||||||
|
- test-input-responseFile
|
||||||
|
- test-input-files-without-data
|
||||||
|
- test-input-file-with-single-file
|
||||||
|
- test-input-data-with-url-encoded-string
|
||||||
|
- test-input-data-with-url-encoded-json-data
|
||||||
|
steps:
|
||||||
|
- uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # v1.2.2
|
||||||
|
with:
|
||||||
|
jobs: ${{ toJSON(needs) }}
|
Loading…
Reference in a new issue