A golang webfinger server implementation
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
874 B

  1. package webfinger
  2. import (
  3. "context"
  4. "errors"
  5. "net/http"
  6. "testing"
  7. )
  8. func TestAddAndGetError(t *testing.T) {
  9. { // test with no error
  10. ctx := context.Background()
  11. r := &http.Request{}
  12. r = r.WithContext(ctx)
  13. err2 := ErrorFromContext(r.Context())
  14. if err2 != nil {
  15. t.Errorf("No error should result in no error")
  16. }
  17. }
  18. { // Test with addError(nil)
  19. ctx := context.Background()
  20. r := &http.Request{}
  21. r = r.WithContext(ctx)
  22. r = addError(r, nil)
  23. err2 := ErrorFromContext(r.Context())
  24. if err2 != nil {
  25. t.Errorf("Error was nil, is now not nil")
  26. }
  27. }
  28. { // Test with addError(errors.New("X"))
  29. ctx := context.Background()
  30. r := &http.Request{}
  31. r = r.WithContext(ctx)
  32. r = addError(r, errors.New("X"))
  33. err2 := ErrorFromContext(r.Context())
  34. if err2 == nil || err2.Error() != "X" {
  35. t.Errorf("Err is %v, expected 'X'", err2)
  36. }
  37. }
  38. }