mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-03-25 12:23:03 -04:00
Some checks failed
/ release (push) Waiting to run
testing-integration / test-unit (push) Waiting to run
testing-integration / test-sqlite (push) Waiting to run
testing-integration / test-mariadb (v10.6) (push) Waiting to run
testing-integration / test-mariadb (v11.8) (push) Waiting to run
testing / backend-checks (push) Waiting to run
testing / frontend-checks (push) Waiting to run
testing / test-unit (push) Blocked by required conditions
testing / test-e2e (push) Blocked by required conditions
testing / test-remote-cacher (redis) (push) Blocked by required conditions
testing / test-remote-cacher (valkey) (push) Blocked by required conditions
testing / test-remote-cacher (garnet) (push) Blocked by required conditions
testing / test-remote-cacher (redict) (push) Blocked by required conditions
testing / test-mysql (push) Blocked by required conditions
testing / test-pgsql (push) Blocked by required conditions
testing / test-sqlite (push) Blocked by required conditions
testing / security-check (push) Blocked by required conditions
Integration tests for the release process / release-simulation (push) Has been cancelled
- Regression of forgejo/forgejo!9830 - `reqSignIn` means it requires sign-in, but it does not require sign-in (can be hit by visiting large repository) so `ignSignIn` is the better option. - Resulted in behavior of being redirected to `/user/login` when visiting a repository such as comaps or forgejo when not being logged in. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10815 Reviewed-by: Michael Kriese <michael.kriese@gmx.de> Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
100 lines
3.1 KiB
Go
100 lines
3.1 KiB
Go
// Copyright 2025 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package integration
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
repo_model "forgejo.org/models/repo"
|
|
"forgejo.org/models/unittest"
|
|
"forgejo.org/modules/git"
|
|
"forgejo.org/tests"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestRepoCommitHeader(t *testing.T) {
|
|
defer tests.PrepareTestEnv(t)()
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
t.Run("Verify commit info", func(t *testing.T) {
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
|
gitRepo, err := git.OpenRepository(git.DefaultContext, repo.RepoPath())
|
|
require.NoError(t, err)
|
|
defer gitRepo.Close()
|
|
|
|
commit, err := gitRepo.GetCommit("65f1bf27bc3bf70f64657658635e66094edbcb4d")
|
|
require.NoError(t, err)
|
|
|
|
req := NewRequest(t, "GET", "/user2/repo1/commit/65f1bf27bc3bf70f64657658635e66094edbcb4d")
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
|
|
|
summary := htmlDoc.Find(".commit-header h3")
|
|
assert.Equal(t, commit.Summary(), strings.TrimSpace(summary.Text()))
|
|
|
|
author := htmlDoc.Find(".commit-header-row .author strong").First()
|
|
assert.Equal(t, commit.Author.Name, author.Text())
|
|
|
|
committer := htmlDoc.Find(".commit-header-row .author strong").Last()
|
|
assert.Equal(t, commit.Committer.Name, committer.Text())
|
|
|
|
date, _ := htmlDoc.Find(".commit-header-row #authored-time relative-time").Attr("datetime")
|
|
assert.Equal(t, commit.Author.When.Format(time.RFC3339), date)
|
|
|
|
sha := htmlDoc.Find(".commit-header-row .sha.label")
|
|
assert.Equal(t, commit.ID.String()[:10], sha.Find(".shortsha").Text())
|
|
})
|
|
|
|
t.Run("Verify parent commit ID", func(t *testing.T) {
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
|
|
gitRepo, err := git.OpenRepository(git.DefaultContext, repo.RepoPath())
|
|
require.NoError(t, err)
|
|
defer gitRepo.Close()
|
|
|
|
commit, err := gitRepo.GetCommit("205ac761f3326a7ebe416e8673760016450b5cec")
|
|
require.NoError(t, err)
|
|
|
|
req := NewRequest(t, "GET", "/user2/repo2/commit/205ac761f3326a7ebe416e8673760016450b5cec")
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
|
|
|
shas := htmlDoc.Find(".commit-header-row .sha.label")
|
|
assert.Equal(t, 2, shas.Length())
|
|
|
|
parentSha := shas.First()
|
|
parentHref, _ := parentSha.Attr("href")
|
|
assert.Equal(t, "/user2/repo2/commit/2c54faec6c45d31c1abfaecdab471eac6633738a", parentHref)
|
|
|
|
parentID, err := commit.ParentID(0)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, parentID.String()[:10], parentSha.Find(".shortsha").Text())
|
|
|
|
sha := shas.Last()
|
|
assert.Equal(t, commit.ID.String()[:10], sha.Find(".shortsha").Text())
|
|
})
|
|
}
|
|
|
|
func TestLastCommit(t *testing.T) {
|
|
defer tests.PrepareTestEnv(t)()
|
|
|
|
t.Run("Anonymous", func(t *testing.T) {
|
|
req := NewRequest(t, "POST", "/user2/repo1/lastcommit/65f1bf27bc3bf70f64657658635e66094edbcb4d")
|
|
MakeRequest(t, req, http.StatusOK)
|
|
})
|
|
|
|
t.Run("Signed in", func(t *testing.T) {
|
|
session := loginUser(t, "user2")
|
|
|
|
req := NewRequest(t, "POST", "/user2/repo1/lastcommit/65f1bf27bc3bf70f64657658635e66094edbcb4d")
|
|
session.MakeRequest(t, req, http.StatusOK)
|
|
})
|
|
}
|