2019-04-17 10:06:35 -06:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2019-04-17 10:06:35 -06:00
|
|
|
|
2021-11-24 15:56:24 +08:00
|
|
|
package files
|
2019-04-17 10:06:35 -06:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
2021-11-12 22:36:47 +08:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2019-06-29 16:51:10 -04:00
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
2024-02-27 15:12:22 +08:00
|
|
|
"code.gitea.io/gitea/services/contexttest"
|
2019-04-17 10:06:35 -06:00
|
|
|
|
2023-09-08 12:51:15 +08:00
|
|
|
_ "code.gitea.io/gitea/models/actions"
|
|
|
|
|
|
2019-04-17 10:06:35 -06:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
2023-09-28 09:38:53 +08:00
|
|
|
unittest.MainTest(m)
|
2019-04-17 10:06:35 -06:00
|
|
|
}
|
|
|
|
|
|
2019-06-29 16:51:10 -04:00
|
|
|
func TestGetContents(t *testing.T) {
|
2021-11-12 22:36:47 +08:00
|
|
|
unittest.PrepareTestEnv(t)
|
2023-09-01 19:26:07 +08:00
|
|
|
ctx, _ := contexttest.MockContext(t, "user2/repo1")
|
2024-12-24 21:47:45 +08:00
|
|
|
ctx.SetPathParam("id", "1")
|
2023-09-01 19:26:07 +08:00
|
|
|
contexttest.LoadRepo(t, ctx, 1)
|
|
|
|
|
contexttest.LoadRepoCommit(t, ctx)
|
|
|
|
|
contexttest.LoadUser(t, ctx, 2)
|
|
|
|
|
contexttest.LoadGitRepo(t, ctx)
|
2019-04-17 10:06:35 -06:00
|
|
|
|
2025-07-03 09:45:42 +08:00
|
|
|
// GetContentsOrList's behavior is fully tested in integration tests, so we don't need to test it here.
|
2019-04-17 10:06:35 -06:00
|
|
|
|
2025-06-25 10:34:21 +08:00
|
|
|
t.Run("GetBlobBySHA", func(t *testing.T) {
|
|
|
|
|
sha := "65f1bf27bc3bf70f64657658635e66094edbcb4d"
|
|
|
|
|
ctx.SetPathParam("id", "1")
|
|
|
|
|
ctx.SetPathParam("sha", sha)
|
|
|
|
|
gbr, err := GetBlobBySHA(ctx.Repo.Repository, ctx.Repo.GitRepo, ctx.PathParam("sha"))
|
|
|
|
|
expectedGBR := &api.GitBlobResponse{
|
2026-02-11 18:37:13 +01:00
|
|
|
Content: new("dHJlZSAyYTJmMWQ0NjcwNzI4YTJlMTAwNDllMzQ1YmQ3YTI3NjQ2OGJlYWI2CmF1dGhvciB1c2VyMSA8YWRkcmVzczFAZXhhbXBsZS5jb20+IDE0ODk5NTY0NzkgLTA0MDAKY29tbWl0dGVyIEV0aGFuIEtvZW5pZyA8ZXRoYW50a29lbmlnQGdtYWlsLmNvbT4gMTQ4OTk1NjQ3OSAtMDQwMAoKSW5pdGlhbCBjb21taXQK"),
|
|
|
|
|
Encoding: new("base64"),
|
2025-06-25 10:34:21 +08:00
|
|
|
URL: "https://try.gitea.io/api/v1/repos/user2/repo1/git/blobs/65f1bf27bc3bf70f64657658635e66094edbcb4d",
|
|
|
|
|
SHA: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
|
|
|
|
|
Size: 180,
|
|
|
|
|
}
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.Equal(t, expectedGBR, gbr)
|
2019-04-17 10:06:35 -06:00
|
|
|
})
|
2019-10-19 17:38:49 +02:00
|
|
|
}
|