github.com/xmidt-org/webpa-common@v1.11.9/xhttp/xcontext/setClient_test.go (about) 1 package xcontext 2 3 import ( 4 "context" 5 "net/http" 6 "net/http/httptest" 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 "github.com/xmidt-org/webpa-common/xhttp" 11 ) 12 13 func testSetClientDefault(t *testing.T) { 14 var ( 15 assert = assert.New(t) 16 ctx = SetClient(nil)(context.Background(), httptest.NewRequest("GET", "/", nil)) 17 ) 18 19 assert.Equal(http.DefaultClient, xhttp.GetClient(ctx)) 20 } 21 22 func testSetClientCustom(t *testing.T) { 23 var ( 24 assert = assert.New(t) 25 26 expected = new(http.Client) 27 ctx = SetClient(expected)(context.Background(), httptest.NewRequest("GET", "/", nil)) 28 ) 29 30 assert.Equal(expected, xhttp.GetClient(ctx)) 31 } 32 33 func TestSetClient(t *testing.T) { 34 t.Run("Default", testSetClientDefault) 35 t.Run("Custom", testSetClientCustom) 36 }