jtp_test.go 1.3 KB

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