response_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2012-present Oliver Eilhard. All rights reserved.
  2. // Use of this source code is governed by a MIT-license.
  3. // See http://olivere.mit-license.org/license.txt for details.
  4. package elastic
  5. import (
  6. "bytes"
  7. "fmt"
  8. "io/ioutil"
  9. "net/http"
  10. "testing"
  11. )
  12. func BenchmarkResponse(b *testing.B) {
  13. c := &Client{
  14. decoder: &DefaultDecoder{},
  15. }
  16. var resp *Response
  17. for n := 0; n < b.N; n++ {
  18. iteration := fmt.Sprint(n)
  19. body := fmt.Sprintf(`{"n":%d}`, n)
  20. res := &http.Response{
  21. Header: http.Header{
  22. "X-Iteration": []string{iteration},
  23. },
  24. Body: ioutil.NopCloser(bytes.NewBufferString(body)),
  25. StatusCode: http.StatusOK,
  26. }
  27. var err error
  28. resp, err = c.newResponse(res)
  29. if err != nil {
  30. b.Fatal(err)
  31. }
  32. /*
  33. if want, have := body, string(resp.Body); want != have {
  34. b.Fatalf("want %q, have %q", want, have)
  35. }
  36. //*/
  37. /*
  38. if want, have := iteration, resp.Header.Get("X-Iteration"); want != have {
  39. b.Fatalf("want %q, have %q", want, have)
  40. }
  41. //*/
  42. }
  43. _ = resp
  44. }