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.

52 lines
1.1 KiB

  1. package webfinger
  2. import (
  3. "testing"
  4. "reflect"
  5. "github.com/pkg/errors"
  6. )
  7. type acp struct {
  8. Input string
  9. Output account
  10. Error string
  11. }
  12. func (a *acp) Invoke() error {
  13. var ax account
  14. err := ax.ParseString(a.Input)
  15. failed := false
  16. failed = failed || err != nil && a.Error == ""
  17. failed = failed || err == nil && a.Error != ""
  18. failed = failed || err != nil && a.Error != err.Error()
  19. failed = failed || err != nil && a.Error != errors.Cause(err).Error()
  20. failed = failed || !reflect.DeepEqual(a.Output, ax)
  21. if failed {
  22. return errors.Errorf("ax.ParseString('%v') => '%v', '%v'; expected '%v', '%v'", a.Input, err, ax, a.Error, a.Output)
  23. }
  24. return nil
  25. }
  26. func TestAccountParse(t *testing.T) {
  27. var tests = []acp{
  28. {"", account{}, "URI is not an account"},
  29. {"http://hello.world", account{}, "URI is not an account"},
  30. {"acct:hello", account{"hello", ""}, "No domain on account"},
  31. {"acct:hello@domain", account{"hello", "domain"}, ""},
  32. {"acct:hello@domain/uri", account{"hello", "domain"}, ""},
  33. }
  34. for _, tx := range tests {
  35. if err := tx.Invoke(); err != nil {
  36. t.Error(err.Error())
  37. }
  38. }
  39. }