Skip to content

GoLang Example of how to mock clients that would call external endpoints during production

Notifications You must be signed in to change notification settings

wyatt-howe/external_endpoint_mocking_example_golang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

external_endpoint_mocking_example_golang

GoLang Example of how to mock clients that would call external endpoints during production

Run (as you would in production)

go run .

This outputs the below to the console. The Phoned home! means the client called the real endpoint. This should only happen in production.

Phoned home! &{{0x14000112020 app123}}
{'finaloutput':{'externaldata':'27'}}

Test (as you would in development)

go test --v

This outputs the below to the console. Notice the Phoned home! message does not get printed because the mock client does not call the real endpoint, it only returns a response that simulates/mocks what it would return if it really did call the endpoint like the real client does. This should only happen in production.

=== RUN   Test_main
--- PASS: Test_main (0.00s)
PASS
ok      external_endpoint_mocking_example       0.196s

About

GoLang Example of how to mock clients that would call external endpoints during production

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages