short_url_test.go 561 B

12345678910111213141516171819202122232425262728
  1. package domain
  2. import (
  3. "errors"
  4. "testing"
  5. )
  6. func TestNewShortURLHappy(t *testing.T) {
  7. tu := TargetURL{"https://example.com"}
  8. su, err := NewUnspecifiedShortURL(tu)
  9. if err != nil {
  10. t.Error(err)
  11. t.FailNow()
  12. }
  13. if su.URL.IsEmpty() || su.Target().IsEmpty() || !su.Target().MayRedirect() {
  14. t.FailNow()
  15. }
  16. }
  17. func TestNewShortURLSadFromEmpty(t *testing.T) {
  18. tu := TargetURL{""}
  19. _, err := NewUnspecifiedShortURL(tu)
  20. if err == nil {
  21. t.Error(errors.New("NewUnspecifiedShortURL should not have created ShortURL from empty target"))
  22. t.FailNow()
  23. }
  24. }