Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tests

geo

A simple CLI for fetching a place's geolocation data.

Building

Install dependencies:

Run:

make all

Usage

Set 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"

Testing

Unit tests

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 test

Integration tests

Integration 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 e2e

All tests

Run all the tests with:

make test-all

Notes:

Unit test that hits the API

There'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.

Stubbing with VCR

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

About

Geolocation Lookup CLI

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages