API testing example with the baloo Golang library

In this integration test, we hit the GET /user (https://developer.travis-ci.com/resource/user#User) endpoint in the Travis API. Here is the code testing this endpoint:

package mainimport (    "errors"    "net/http"    "os"    "testing"    "gopkg.in/h2non/baloo.v3")var test = baloo.New("https://api.travis-ci.com")func assertTravisUserEndpoint(res *http.Response, req *http.Request) error {  if res.StatusCode != http.StatusOK {    return errors.New("This endpoint should return a 200 response code")  }  if res.Body == nil {    return errors.New("The body should not be empty")  }  return nil}func TestBalooClient(t *testing.T) {    test.Get("/user").    SetHeader("Authorization", "token "+os.Getenv("TRAVIS_PERSONAL_TOKEN")). ...

Get Hands-On Continuous Integration and Delivery now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.