Skip to content

Commit 009a06b

Browse files
authored
End to end tests (#23)
* Add end-to-end tests The tests run the actual GitHub Action and then verify that Hoverfly and Hoverctl have been successfully installed, or not. This provides great end-to-end black box testing[1] coverage :-) GitHub Actions cannot be run locally[2], so that means that these tests cannot be run locally either. Instead, they run automatically as a GitHub Action themselves[3], triggered on every push. There is no need for a separate language for the tests - as we are running the actual GitHub Action we are able use the GitHub Action workflow syntax[4], which gives us what we need (e.g. expressions)[5] to write clean tests. [1] http://softwaretestingfundamentals.com/black-box-testing [2] https://github.community/t/can-i-run-github-actions-on-my-laptop/17019/2 [3] https://github.com/agilepathway/hoverfly-github-action/actions?query=workflow%3ATest [4] https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions [5] https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#about-contexts-and-expressions * Allow yaml lines of any length Lines of more than 80 characters were being flagged as an error. Sometimes longer lines are necessary (e.g. long URLs), so bumped the limit up to 120 characters and downgraded the alerts from error to warning.
1 parent 9d48e60 commit 009a06b

File tree

4 files changed

+114
-0
lines changed

4 files changed

+114
-0
lines changed

.github/workflows/tests.yml

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
name: Test
3+
on: push # yamllint disable-line rule:truthy
4+
env:
5+
ASSERT_VERSION: "| grep -q $HOVERFLY_VERSION"
6+
ASSERT_HOVERFLY_NOT_INSTALLED: "! hoverfly -version"
7+
ASSERT_HOVERCTL_NOT_INSTALLED: "! hoverctl version"
8+
9+
jobs:
10+
11+
12+
install_latest_version_by_default:
13+
name: Install latest version by default
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Install Hoverfly
18+
uses: ./
19+
with:
20+
runner_github_workspace_path: ${{ github.workspace }}
21+
- name: Assert latest version installed
22+
env:
23+
HOVERFLY_VERSION: "v1.3.0"
24+
run: |
25+
hoverfly -version ${{ env.ASSERT_VERSION }}
26+
hoverctl version ${{ env.ASSERT_VERSION }}
27+
28+
29+
install_specific_version:
30+
name: Install specific version
31+
runs-on: ubuntu-latest
32+
env:
33+
HOVERFLY_VERSION: v1.2.0
34+
steps:
35+
- uses: actions/checkout@v2
36+
- name: Install Hoverfly
37+
uses: ./
38+
with:
39+
version: ${{ env.HOVERFLY_VERSION }}
40+
runner_github_workspace_path: ${{ github.workspace }}
41+
- name: Assert latest version installed
42+
run: |
43+
hoverfly -version ${{ env.ASSERT_VERSION }}
44+
hoverctl version ${{ env.ASSERT_VERSION }}
45+
46+
47+
install_fails_if_version_does_not_begin_with_v:
48+
name: Install fails if version does not begin with v
49+
runs-on: ubuntu-latest
50+
env:
51+
HOVERFLY_VERSION: "1.2.0"
52+
steps:
53+
- uses: actions/checkout@v2
54+
- name: Install Hoverfly
55+
uses: ./
56+
with:
57+
version: ${{ env.HOVERFLY_VERSION }}
58+
runner_github_workspace_path: ${{ github.workspace }}
59+
- name: Assert Hoverfly not installed
60+
run: |
61+
${{ env.ASSERT_HOVERFLY_NOT_INSTALLED }}
62+
${{ env.ASSERT_HOVERCTL_NOT_INSTALLED }}
63+
64+
65+
install_fails_if_no_runner_github_workspace_path:
66+
name: Install fails when no runner GitHub workspace path provided
67+
runs-on: ubuntu-latest
68+
steps:
69+
- uses: actions/checkout@v2
70+
- name: Install Hoverfly
71+
uses: ./
72+
- name: Assert Hoverfly not installed
73+
run: |
74+
${{ env.ASSERT_HOVERFLY_NOT_INSTALLED }}
75+
${{ env.ASSERT_HOVERCTL_NOT_INSTALLED }}
76+
77+
78+
install_fails_if_incorrect_runner_github_workspace_path:
79+
name: Install fails when incorrect runner GitHub workspace path provided
80+
runs-on: ubuntu-latest
81+
steps:
82+
- uses: actions/checkout@v2
83+
- name: Install Hoverfly
84+
uses: ./
85+
with: # Invalid runner_github_workspace_path (must be <dollarsign>{{ github.workspace}})
86+
runner_github_workspace_path: /tmp
87+
- name: Assert Hoverfly not installed
88+
run: |
89+
${{ env.ASSERT_HOVERFLY_NOT_INSTALLED }}
90+
${{ env.ASSERT_HOVERCTL_NOT_INSTALLED }}

.yamllint.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
extends: default
3+
4+
rules:
5+
# 120 chars should be enough, but don't fail if a line is longer
6+
line-length:
7+
max: 120
8+
level: warning

CONTRIBUTING.md

+11
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,14 @@ Firstly thanks for thinking of contributing - the project is [open source](https
1414
* Make your changes on your fork
1515
* Write a [good commit message(s)](https://chris.beams.io/posts/git-commit/) for your changes
1616
* [Create the pull request for your changes](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/proposing-changes-to-your-work-with-pull-requests)
17+
* [Update the tests or add new tests](#running-the-tests) to cover the new behaviour.
18+
19+
## Running the tests
20+
21+
The [tests](.github/workflows/tests.yml) are [end-to-end black box tests](http://softwaretestingfundamentals.com/black-box-testing), to verify that the GitHub Action installs [Hoverfly](https://docs.hoverfly.io) and [Hoverctl](https://docs.hoverfly.io/en/latest/pages/keyconcepts/hoverctl.html) successfully.
22+
23+
[GitHub Actions cannot be run locally](https://github.community/t/can-i-run-github-actions-on-my-laptop/17019/2), so that means that these tests cannot be run locally either. Instead, they run automatically as a [GitHub Action themselves](https://github.com/agilepathway/hoverfly-github-action/actions?query=workflow%3ATest), triggered on every push.
24+
25+
There is no need for a separate language for the tests - as we are running the actual GitHub Action we are able to use the [GitHub Action workflow syntax](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions), which gives us what we need (e.g. [expressions](https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#about-contexts-and-expressions)) to write clean tests.
26+
27+

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Hoverfly GitHub Action
22

3+
[![tests](https://github.com/agilepathway/hoverfly-github-action/workflows/Test/badge.svg?branch=main&event=push)](https://github.com/agilepathway/hoverfly-github-action/actions?query=workflow%3ATest+event%3Apush+branch%3Amain)
34
[![reviewdog](https://github.com/agilepathway/hoverfly-github-action/workflows/reviewdog/badge.svg?branch=main&event=push)](https://github.com/agilepathway/hoverfly-github-action/actions?query=workflow%3Areviewdog+event%3Apush+branch%3Amain)
45
[![License](https://img.shields.io/badge/license-MIT-blue.svg?maxAge=43200)](LICENSE)
56

@@ -99,6 +100,10 @@ The Hoverfly binaries are installed at `${{ github.workspace }}/bin`
99100

100101
(The [GitHub workspace directory is persistent throughout the GitHub Action workflow](https://docs.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners#filesystems-on-github-hosted-runners), which means that the binaries are available to any subsequent workflow steps.)
101102

103+
## Tests / examples
104+
105+
The [tests](.github/workflows/tests.yml) contain further configuration examples.
106+
102107

103108
## Suggestions / bug reports / contributions
104109

0 commit comments

Comments
 (0)