mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-06-22 10:02:15 +00:00
12726: Add migrations avatar test for GogsDownloader.
- Fix potential bug where forward-slash can be missing from URL to avatar.
This commit is contained in:
parent
6002d415c3
commit
c3a6779da6
3 changed files with 38 additions and 1 deletions
|
|
@ -142,7 +142,7 @@ func (g *GogsDownloader) GetRepoInfo() (*base.Repository, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
avatarURL := fmt.Sprintf("%srepo-avatars/%d", g.baseURL, gr.ID)
|
||||
avatarURL := fmt.Sprintf("%s/repo-avatars/%d", strings.TrimRight(g.baseURL, "/"), gr.ID)
|
||||
|
||||
// convert gogs repo to stand Repo
|
||||
return &base.Repository{
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"forgejo.org/models/unittest"
|
||||
base "forgejo.org/modules/migration"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -222,3 +223,29 @@ func TestGogsDownloaderFactory_New(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGogsDownloaderAvatarDownload(t *testing.T) {
|
||||
GithubLimitRateRemaining = 3 // Wait at 3 remaining since we could have 3 CI in //
|
||||
|
||||
token := os.Getenv("GOGS_READ_TOKEN_BIRDGOOSE")
|
||||
liveMode := token != ""
|
||||
|
||||
fixturePath := "./testdata/gogs/avatar"
|
||||
server := unittest.NewMockWebServer(t, "https://try.gogs.io", fixturePath, liveMode)
|
||||
defer server.Close()
|
||||
|
||||
downloader := NewGogsDownloader(t.Context(), server.URL, "", "", token, "example", "example-repo")
|
||||
|
||||
repo, err := downloader.GetRepoInfo()
|
||||
require.NoError(t, err)
|
||||
|
||||
assertRepositoryEqual(t, &base.Repository{
|
||||
Name: "example-repo",
|
||||
Owner: "example",
|
||||
Description: "An example repo for Forgejo migration testing.",
|
||||
CloneURL: server.URL + "/example/example-repo.git",
|
||||
OriginalURL: server.URL + "/example/example-repo",
|
||||
DefaultBranch: "main",
|
||||
AvatarURL: server.URL + "/repo-avatars/99330",
|
||||
}, repo)
|
||||
}
|
||||
|
|
|
|||
10
services/migrations/testdata/gogs/avatar/GET_%2Fapi%2Fv1%2Frepos%2Fexample%2Fexample-repo
vendored
Normal file
10
services/migrations/testdata/gogs/avatar/GET_%2Fapi%2Fv1%2Frepos%2Fexample%2Fexample-repo
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
Alt-Svc: h3=":443"; ma=86400
|
||||
Cf-Cache-Status: DYNAMIC
|
||||
Content-Type: application/json; charset=UTF-8
|
||||
Server-Timing: cfCacheStatus;desc="DYNAMIC"
|
||||
Server-Timing: cfEdge;dur=11,cfOrigin;dur=628
|
||||
Strict-Transport-Security: max-age=15552000; includeSubDomains
|
||||
X-Content-Type-Options: nosniff
|
||||
X-Frame-Options: deny
|
||||
|
||||
{"id":99330,"owner":{"id":126484,"username":"example","login":"example","full_name":"","email":"full.stick1536@foo.nz","avatar_url":"https://secure.gravatar.com/avatar/4468e916c63945b1907c28851dd7a678?d=identicon"},"name":"example-repo","full_name":"example/example-repo","description":"An example repo for Forgejo migration testing.","private":false,"fork":false,"parent":null,"empty":true,"mirror":false,"size":0,"html_url":"https://try.gogs.io/example/example-repo","ssh_url":"git@ssh.try.gogs.io:example/example-repo.git","clone_url":"https://try.gogs.io/example/example-repo.git","website":"","stars_count":0,"forks_count":0,"watchers_count":1,"open_issues_count":0,"default_branch":"main","created_at":"2026-06-02T10:43:34Z","updated_at":"2026-06-02T10:43:34Z","permissions":{"admin":true,"push":true,"pull":true}}
|
||||
Loading…
Add table
Add a link
Reference in a new issue