Skip to content

Commit

Permalink
Retry check seeker test
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinku-Chen committed Mar 15, 2024
1 parent 107ef03 commit 443389c
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions colly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1710,7 +1710,7 @@ func TestCollectorPostRetry(t *testing.T) {

postValue := "hello"
c := NewCollector()

try := false
c.OnResponse(func(r *Response) {
if r.Ctx.Get("notFirst") == "" {
r.Ctx.Put("notFirst", "first")
Expand All @@ -1720,17 +1720,45 @@ func TestCollectorPostRetry(t *testing.T) {
if postValue != string(r.Body) {
t.Error("Failed to send data with POST")
}
try = true
})

c.Post(ts.URL+"/login", map[string]string{
"name": postValue,
})
if !try {
t.Error("OnResponse Retry was not called")
}
}
func TestCollectorGetRetry(t *testing.T) {
ts := newTestServer()
defer ts.Close()
try := false

c := NewCollector()

c.OnResponse(func(r *Response) {
if r.Ctx.Get("notFirst") == "" {
r.Ctx.Put("notFirst", "first")
_ = r.Request.Retry()
return
}
if !bytes.Equal(r.Body, serverIndexResponse) {
t.Error("Response body does not match with the original content")
}
try = true
})

c.Visit(ts.URL)
if !try {
t.Error("OnResponse Retry was not called")
}
}

func TestCollectorPostRetryUnSeekable(t *testing.T) {
ts := newTestServer()
defer ts.Close()

try := false
postValue := "hello"
c := NewCollector()

Expand All @@ -1747,8 +1775,10 @@ func TestCollectorPostRetryUnSeekable(t *testing.T) {
}
return
}

try = true
})

c.Request("POST", ts.URL+"/login", bytes.NewBuffer([]byte("name="+postValue)), nil, nil)
if try {
t.Error("OnResponse Retry was called but BodyUnSeekable")
}
}

0 comments on commit 443389c

Please sign in to comment.