gavv/httpexpect

Add bodyWrapper test for error handling with rewinds disabled

gavv opened this issue · 2 comments

gavv commented

bodyWrapper is an internal struct that wraps HTTP response body and allows to read it multiple times using Rewind and GetBody methods. See comments for details.

We need to add a test TestBodyWrapper_DisableRewindsErrors, with a few subtests that cover handling of read and close errors when rewinds are disabled at various points of time:

  • subtest 1: rewinds are disabled before first read

    flow:

    • create bodyWrapper
    • call bodyWrapper.DisableRewinds
    • configure mockBody to fail when reading
    • call bodyWrapper.Read

    expected behavior:

    • bodyWrapper.Read calls mockBody.Read and propagates error from it
    • if you call bodyWrapper.Read again, it calls mockBody.Read again
  • subtest 2: rewinds are disabled after read error

    flow:

    • create bodyWrapper
    • call bodyWrapper.Read
    • configure mockBody to fail when reading
    • call bodyWrapper.Read again (will fail and cache error)
    • call bodyWrapper.DisableRewinds
    • call bodyWrapper.Read again

    expected behavior:

    • the last bodyWrapper.Read won't try to read from mockBody, and will return cached error from last mockBody call
    • if you call bodyWrapper.Read again, it will do the same
  • subtest 3: rewinds are disabled after close error

    flow:

    • create bodyWrapper
    • configure mockBody to fail when closing
    • call bodyWrapper.Close (will fully read body into memory, get error from mockBody close, and cache error)
    • call bodyWrapper.DisableRewinds
    • call bodyWrapper.Read

    expected behavior:

    • the last bodyWrapper.Read won't try to read from mockBody, and will return cached error from last mockBody call
    • if you call bodyWrapper.Read again, it will do the same

Hi @gavv, I'm working on this one and can be assigned.

gavv commented

Awesome