unmarshal_test.go 786 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package protocol_test
  2. import (
  3. "net/http"
  4. "strings"
  5. "testing"
  6. "github.com/aws/aws-sdk-go/aws/request"
  7. "github.com/aws/aws-sdk-go/private/protocol"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. type mockCloser struct {
  11. *strings.Reader
  12. Closed bool
  13. }
  14. func (m *mockCloser) Close() error {
  15. m.Closed = true
  16. return nil
  17. }
  18. func TestUnmarshalDrainBody(t *testing.T) {
  19. b := &mockCloser{Reader: strings.NewReader("example body")}
  20. r := &request.Request{HTTPResponse: &http.Response{
  21. Body: b,
  22. }}
  23. protocol.UnmarshalDiscardBody(r)
  24. assert.NoError(t, r.Error)
  25. assert.Equal(t, 0, b.Len())
  26. assert.True(t, b.Closed)
  27. }
  28. func TestUnmarshalDrainBodyNoBody(t *testing.T) {
  29. r := &request.Request{HTTPResponse: &http.Response{}}
  30. protocol.UnmarshalDiscardBody(r)
  31. assert.NoError(t, r.Error)
  32. }