gitlab.com/beacon-software/gadget@v0.0.0-20181217202115-54565ea1ed5e/net/http_test.go (about) 1 package net 2 3 import ( 4 "context" 5 "net/http" 6 "testing" 7 "time" 8 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func Test_client_DoWithContext(t *testing.T) { 13 assert := assert.New(t) 14 client := NewHTTPRedirectClient(time.Minute) 15 request, err := http.NewRequest("GET", "http://localhost", nil) 16 assert.NoError(err) 17 ctx := context.Background() 18 ctx, cancel := context.WithTimeout(ctx, time.Nanosecond) 19 cancel() 20 _, err = client.DoWithContext(ctx, request) 21 assert.EqualError(err, "request to http://localhost was cancelled by controlling context") 22 }