jtp_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // +build !offline
  2. package jtp
  3. import (
  4. "net/url"
  5. "testing"
  6. )
  7. func TestStatusLineNoInfo(t *testing.T) {
  8. test := "HTTP/1.1 200\r\n"
  9. status, err := parseStatusLine(test)
  10. if err != nil {
  11. t.Fatal(err)
  12. }
  13. if status != "200" {
  14. t.Fatalf("expected status 200 but received %s", status)
  15. }
  16. }
  17. func TestRedirect(t *testing.T) {
  18. accept := "application/activity+json"
  19. tolerated := []string{"application/json"}
  20. link, err := url.Parse("https://httpbin.org/redirect/5")
  21. if err != nil {
  22. t.Fatalf("invalid url literal: %s", err)
  23. }
  24. _, actualLink, err := Get(link, accept, tolerated, 5)
  25. if err != nil {
  26. t.Fatalf("failed to preform request: %s", err)
  27. }
  28. if link.String() == actualLink.String() {
  29. t.Fatalf("failed to return the underlying url redirected to by %s", link.String())
  30. }
  31. }
  32. func TestBasic(t *testing.T) {
  33. accept := "application/activity+json"
  34. tolerated := []string{"application/json"}
  35. link, err := url.Parse("https://httpbin.org/get")
  36. if err != nil {
  37. t.Fatalf("invalid url literal: %s", err)
  38. }
  39. _, actualLink, err := Get(link, accept, tolerated, 20)
  40. if err != nil {
  41. t.Fatalf("failed to preform request: %s", err)
  42. }
  43. if link.String() != actualLink.String() {
  44. t.Fatalf("underlying url %s should match request url %s", actualLink.String(), link.String())
  45. }
  46. }