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.

avatar_test.go 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "net/url"
  7. "testing"
  8. "code.gitea.io/gitea/modules/setting"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. const gravatarSource = "https://secure.gravatar.com/avatar/"
  12. func disableGravatar() {
  13. setting.EnableFederatedAvatar = false
  14. setting.LibravatarService = nil
  15. setting.DisableGravatar = true
  16. }
  17. func enableGravatar(t *testing.T) {
  18. setting.DisableGravatar = false
  19. var err error
  20. setting.GravatarSourceURL, err = url.Parse(gravatarSource)
  21. assert.NoError(t, err)
  22. }
  23. func TestHashEmail(t *testing.T) {
  24. assert.Equal(t,
  25. "d41d8cd98f00b204e9800998ecf8427e",
  26. HashEmail(""),
  27. )
  28. assert.Equal(t,
  29. "353cbad9b58e69c96154ad99f92bedc7",
  30. HashEmail("gitea@example.com"),
  31. )
  32. }
  33. func TestSizedAvatarLink(t *testing.T) {
  34. disableGravatar()
  35. assert.Equal(t, "/suburl/img/avatar_default.png",
  36. SizedAvatarLink("gitea@example.com", 100))
  37. enableGravatar(t)
  38. assert.Equal(t,
  39. "https://secure.gravatar.com/avatar/353cbad9b58e69c96154ad99f92bedc7?d=identicon&s=100",
  40. SizedAvatarLink("gitea@example.com", 100),
  41. )
  42. }