title: How do you test a service that makes call to another API endpoint in Go?
body: <p>I have a simple service created using infinite loop to call a certain HTTP API periodically, implemented in a package <code>aservice</code>. I created a <code>Service</code> struct there. Typically, to run that service, I expose a <code>StartService</code> method which is used to run that service synchronously. Users of the package can then run it using a goroutine. My question is, how do you write the tests for this kind of scenario?</p>
  
  <p>Do you run the whole system and "mock" the API? I have heard that code that uses 3rd party services don't need to be tested, but the whole <code>aservice</code> package may only contain <code>StartService</code> and <code>Shutdown</code> methods. The rest of them are unexported functions/methods which are then cannot be tested individually. If that is the case then I can't write any tests at all?</p>