code.gitea.io/gitea@v1.22.3/models/repo/avatar_test.go (about)

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