This is a simple exercise that is meant to help teach the principles of testing code.
It was deliberately not built in a TDD manner, this is not production code.
The code is not easy to test in its current form, you'll need to refactor a bit to get started.
This is a simple Go command, you will need a Pushover API token and User ID to test this.
$ export PUSHOVER_TOKEN=atxxxxxxxxxxxxxxxxxxxxxxxxxxxx
$ export NOTIFICATION_USER=ufxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
$ go run main.go
The testing.sh
script will simulate a GitHub hook notification with an
appropriate payload.
$ ./testing.sh
- Why is the code hard to test?
- Why is it harder to refactor?
- What should we do if Pushover is down?
- What if we wanted to notify more than one user?
- What if we wanted multiple notification methods, i.e. AWS SNS and Pushover?
- Apply the "Standard Go Project Layout"
- Adopt a command-line framework
- Consider testing with an HTTP mocking framework - is this easier than
net/http/httptest
?