aboutsummaryrefslogtreecommitdiffstats
path: root/models/repo/avatar_test.go
blob: fc1f8baeca55202a822a6593dde47631bd630b65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package repo

import (
	"testing"

	"code.gitea.io/gitea/models/db"
	"code.gitea.io/gitea/modules/setting"
	"code.gitea.io/gitea/modules/test"

	"github.com/stretchr/testify/assert"
)

func TestRepoAvatarLink(t *testing.T) {
	defer test.MockVariableValue(&setting.AppURL, "https://localhost/")()
	defer test.MockVariableValue(&setting.AppSubURL, "")()

	repo := &Repository{ID: 1, Avatar: "avatar.png"}
	link := repo.AvatarLink(db.DefaultContext)
	assert.Equal(t, "https://localhost/repo-avatars/avatar.png", link)

	setting.AppURL = "https://localhost/sub-path/"
	setting.AppSubURL = "/sub-path"
	link = repo.AvatarLink(db.DefaultContext)
	assert.Equal(t, "https://localhost/sub-path/repo-avatars/avatar.png", link)
}