diff options
author | Ethan Koenig <ethantkoenig@gmail.com> | 2017-12-03 03:55:13 -0800 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-12-03 19:55:13 +0800 |
commit | ab62da283aa20475109eba907324f55123d7e3c6 (patch) | |
tree | a08bb1753ff39d9ecc74afc42374ba614c67d8bb /modules/base/tool_test.go | |
parent | 7bab3d2fb1d75ac29ad6a9b11203ea358b1979d3 (diff) | |
download | gitea-ab62da283aa20475109eba907324f55123d7e3c6.tar.gz gitea-ab62da283aa20475109eba907324f55123d7e3c6.zip |
Fix avatar URLs (#3069)
* Fix avatar URLs
* import order
Diffstat (limited to 'modules/base/tool_test.go')
-rw-r--r-- | modules/base/tool_test.go | 34 |
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"), ) } |