gitea源码

avatar_test.go 765B

12345678910111213141516171819202122232425262728
  1. // Copyright 2024 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package repo
  4. import (
  5. "testing"
  6. "code.gitea.io/gitea/modules/setting"
  7. "code.gitea.io/gitea/modules/test"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestRepoAvatarLink(t *testing.T) {
  11. defer test.MockVariableValue(&setting.AppURL, "https://localhost/")()
  12. defer test.MockVariableValue(&setting.AppSubURL, "")()
  13. repo := &Repository{ID: 1, Avatar: "avatar.png"}
  14. link := repo.AvatarLink(t.Context())
  15. assert.Equal(t, "https://localhost/repo-avatars/avatar.png", link)
  16. setting.AppURL = "https://localhost/sub-path/"
  17. setting.AppSubURL = "/sub-path"
  18. link = repo.AvatarLink(t.Context())
  19. assert.Equal(t, "https://localhost/sub-path/repo-avatars/avatar.png", link)
  20. }