A simple CLI for fetching a place's geolocation data.
Install dependencies:
Run:
make allSet the API Key
export OPEN_WEATHER_API_KEY=<api-key>Get help from 'geo' (ensure you built the binary):
build/geo -h
Run the example:
build/geo "Henrico, VA" 10001 "Seattle, WA"Unit tests are in any file named *_test.go that also does not have
the built tag: //go:build e2e at the top of the file.
Run the unit tests with:
make testIntegration tests are in the ./test/integration/ directory.
Ensure you have set the API Key:
export OPEN_WEATHER_API_KEY=<api-key>Run the integration tests with:
make e2eRun all the tests with:
make test-allThere's a "unit" test in ./internal/cmd/geo_test.go that hit's the OpenWeather API. I took a shortcut in these unit tests and did not mock the service, as I assume you really want to see the integration tests.
I have a trick (which I did not use) with unit tests in Go (and a few other languages like Ruby) where I use a vcr library to avoid building stubs. Further, 'vcr' libraries enable us to switch between fast local iteration and slow, complex e2e.
There are definitely caveats with this style of testing, and it doesn't fit every component, though it would work exceptionally well with this example.
This is something I would normally introduce, but it really only makes sense with developer driven acceptance testing, and I didn't want to push my agenda on that in this example :D