summaryrefslogtreecommitdiffstats
path: root/modules/base/tool_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/base/tool_test.go')
-rw-r--r--modules/base/tool_test.go34
1 files changed, 30 insertions, 4 deletions
diff --git a/modules/base/tool_test.go b/modules/base/tool_test.go
index 44ea309f7c..ffa17fae00 100644
--- a/modules/base/tool_test.go
+++ b/modules/base/tool_test.go
@@ -1,11 +1,13 @@
package base
import (
+ "net/url"
"os"
"testing"
"time"
"code.gitea.io/gitea/modules/setting"
+
"github.com/Unknwon/i18n"
macaroni18n "github.com/go-macaron/i18n"
"github.com/stretchr/testify/assert"
@@ -126,16 +128,40 @@ func TestHashEmail(t *testing.T) {
)
}
-func TestAvatarLink(t *testing.T) {
+const gravatarSource = "https://secure.gravatar.com/avatar/"
+
+func disableGravatar() {
setting.EnableFederatedAvatar = false
setting.LibravatarService = nil
setting.DisableGravatar = true
+}
- assert.Equal(t, "/img/avatar_default.png", AvatarLink(""))
-
+func enableGravatar(t *testing.T) {
setting.DisableGravatar = false
+ var err error
+ setting.GravatarSourceURL, err = url.Parse(gravatarSource)
+ assert.NoError(t, err)
+}
+
+func TestSizedAvatarLink(t *testing.T) {
+ disableGravatar()
+ assert.Equal(t, "/img/avatar_default.png",
+ SizedAvatarLink("gitea@example.com", 100))
+
+ enableGravatar(t)
+ assert.Equal(t,
+ "https://secure.gravatar.com/avatar/353cbad9b58e69c96154ad99f92bedc7?d=identicon&s=100",
+ SizedAvatarLink("gitea@example.com", 100),
+ )
+}
+
+func TestAvatarLink(t *testing.T) {
+ disableGravatar()
+ assert.Equal(t, "/img/avatar_default.png", AvatarLink("gitea@example.com"))
+
+ enableGravatar(t)
assert.Equal(t,
- "353cbad9b58e69c96154ad99f92bedc7?d=identicon",
+ "https://secure.gravatar.com/avatar/353cbad9b58e69c96154ad99f92bedc7?d=identicon",
AvatarLink("gitea@example.com"),
)
}