test: add unit test for Request.Context() (#2554)

Signed-off-by: Guangwen Feng <fenggw-fnst@fujitsu.com>
This commit is contained in:
Guangwen Feng 2023-07-18 17:52:40 +08:00 committed by GitHub
parent 25ff199ca1
commit 94e4b7a5a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 0 deletions

View File

@ -64,6 +64,25 @@ func TestNewRequest(t *testing.T) {
assert.Equal(expectedDeadline, gotDeadline)
}
func TestRequest_Context(t *testing.T) {
assert := assert.New(t)
got, err := NewRequest("http://www.dragonfly.io")
assert.Nil(err)
assert.Equal(got.Context(), context.Background())
testHeaderMap := map[string]string{"testKey1": "testValue1", "testKey2": "testValue2"}
got, err = NewRequestWithHeader("http://www.dragonfly.io", testHeaderMap)
assert.Nil(err)
assert.Equal(got.Context(), context.Background())
testContext, cancelFunc := context.WithTimeout(context.Background(), 3*time.Second)
defer cancelFunc()
got, err = NewRequestWithContext(testContext, "http://www.dragonfly.io", testHeaderMap)
assert.Nil(err)
assert.Equal(got.Context(), testContext)
}
func TestRequest_Clone(t *testing.T) {
var testURL, err = url.Parse("http://www.dragonfly.io")
testCloneURL, err := url.Parse("http://www.dragonfly.io")