0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-12-08 17:55:50 +01:00

simple test

This commit is contained in:
a1012112796 2025-12-07 15:04:47 +08:00
parent 3b7e7d4868
commit 7442b26a3f
No known key found for this signature in database
GPG Key ID: E5FB19032C2C2A64

View File

@ -15,9 +15,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestActionUserSignIn(t *testing.T) { func testActionUserSignIn(t *testing.T) {
defer tests.PrepareTestEnv(t)()
req := NewRequest(t, "GET", "/api/v1/user"). req := NewRequest(t, "GET", "/api/v1/user").
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a") AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
@ -27,9 +25,7 @@ func TestActionUserSignIn(t *testing.T) {
assert.Equal(t, "gitea-actions", u.UserName) assert.Equal(t, "gitea-actions", u.UserName)
} }
func TestActionUserAccessPublicRepo(t *testing.T) { func testActionUserAccessPublicRepo(t *testing.T) {
defer tests.PrepareTestEnv(t)()
req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/raw/README.md"). req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/raw/README.md").
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a") AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
@ -43,10 +39,16 @@ func TestActionUserAccessPublicRepo(t *testing.T) {
assert.Equal(t, "file", resp.Header().Get("x-gitea-object-type")) assert.Equal(t, "file", resp.Header().Get("x-gitea-object-type"))
} }
func TestActionUserNoAccessOtherPrivateRepo(t *testing.T) { func testActionUserNoAccessOtherPrivateRepo(t *testing.T) {
defer tests.PrepareTestEnv(t)()
req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo2/raw/README.md"). req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo2/raw/README.md").
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a") AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
} }
func TestActionUserAccessPermission(t *testing.T) {
defer tests.PrepareTestEnv(t)()
t.Run("ActionUserSignIn", testActionUserSignIn)
t.Run("ActionUserAccessPublicRepo", testActionUserAccessPublicRepo)
t.Run("ActionUserNoAccessOtherPrivateRepo", testActionUserNoAccessOtherPrivateRepo)
}