Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gavv committed Oct 1, 2023
1 parent 4e3e1fa commit a7decf5
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions body_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -999,12 +999,15 @@ func TestBodyWrapper_DisableRewindsErrors(t *testing.T) {
body.readErr = bodyErr
b := make([]byte, len(bodyText)+1)

// disable rewinds before first read
wrp.DisableRewinds()

// Read calls body.Read, which fails
_, err := wrp.Read(b)
assert.EqualError(t, err, bodyErr.Error())
assert.Equal(t, 1, body.readCount)

// Read calls body.Read again, which fails again
_, err = wrp.Read(b)
assert.EqualError(t, err, bodyErr.Error())
assert.Equal(t, 2, body.readCount)
Expand All @@ -1017,12 +1020,15 @@ func TestBodyWrapper_DisableRewindsErrors(t *testing.T) {
body.readErr = bodyErr
b := make([]byte, len(bodyText)+1)

// Read calls body.Read, which fails
_, err := wrp.Read(b)
assert.EqualError(t, err, bodyErr.Error())
assert.Equal(t, 1, body.readCount)

// disable rewinds after failed read
wrp.DisableRewinds()

// Read returns cached error from previous call
_, err = wrp.Read(b)
assert.EqualError(t, err, bodyErr.Error())
assert.Equal(t, 1, body.readCount)
Expand All @@ -1035,17 +1041,21 @@ func TestBodyWrapper_DisableRewindsErrors(t *testing.T) {
body.closeErr = bodyErr
b := make([]byte, len(bodyText)+1)

// Close calls body.Read, then body.Close, which fails
err := wrp.Close()
assert.True(t, wrp.isFullyRead)
assert.EqualError(t, err, bodyErr.Error())
assert.Equal(t, 2, body.readCount)

// disable rewinds after failed close
wrp.DisableRewinds()

// Read returns cached error from Close call
_, err = wrp.Read(b)
assert.EqualError(t, err, bodyErr.Error())
assert.Equal(t, 2, body.readCount)

// Read returns cached error from Close call, again
_, err = wrp.Read(b)
assert.EqualError(t, err, bodyErr.Error())
assert.Equal(t, 2, body.readCount)
Expand Down

0 comments on commit a7decf5

Please sign in to comment.