check_test.go 783 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package http
  2. import (
  3. "bytes"
  4. "io/ioutil"
  5. "net/http"
  6. "testing"
  7. )
  8. func TestCheck_valid(t *testing.T) {
  9. var valid = &http.Response{
  10. StatusCode: 200,
  11. }
  12. err := CheckResponse(valid)
  13. if err != nil {
  14. t.Error("marked valid response as OK")
  15. }
  16. }
  17. func TestCheck_404(t *testing.T) {
  18. var buf = bytes.NewBufferString("test not found")
  19. var valid = &http.Response{
  20. StatusCode: 400,
  21. Body: ioutil.NopCloser(buf),
  22. }
  23. err := CheckResponse(valid)
  24. if err == nil {
  25. t.Error("marked invalid response as OK")
  26. }
  27. }
  28. func TestCheck_500(t *testing.T) {
  29. var buf = bytes.NewBufferString("test err")
  30. var valid = &http.Response{
  31. StatusCode: 500,
  32. Body: ioutil.NopCloser(buf),
  33. }
  34. err := CheckResponse(valid)
  35. if err == nil {
  36. t.Error("marked invalid response as OK")
  37. }
  38. }