2019-04-17 18:06:35 +02:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package repofiles
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-09-19 13:49:59 +02:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2019-05-11 12:21:34 +02:00
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
2019-04-17 18:06:35 +02:00
|
|
|
"code.gitea.io/gitea/modules/test"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetBlobBySHA(t *testing.T) {
|
2021-09-19 13:49:59 +02:00
|
|
|
db.PrepareTestEnv(t)
|
2019-04-17 18:06:35 +02:00
|
|
|
ctx := test.MockContext(t, "user2/repo1")
|
|
|
|
test.LoadRepo(t, ctx, 1)
|
|
|
|
test.LoadRepoCommit(t, ctx)
|
|
|
|
test.LoadUser(t, ctx, 2)
|
|
|
|
test.LoadGitRepo(t, ctx)
|
2019-11-13 08:01:19 +01:00
|
|
|
defer ctx.Repo.GitRepo.Close()
|
|
|
|
|
2019-04-17 18:06:35 +02:00
|
|
|
sha := "65f1bf27bc3bf70f64657658635e66094edbcb4d"
|
|
|
|
ctx.SetParams(":id", "1")
|
|
|
|
ctx.SetParams(":sha", sha)
|
|
|
|
|
|
|
|
gbr, err := GetBlobBySHA(ctx.Repo.Repository, ctx.Params(":sha"))
|
|
|
|
expectedGBR := &api.GitBlobResponse{
|
2019-04-19 14:17:27 +02:00
|
|
|
Content: "dHJlZSAyYTJmMWQ0NjcwNzI4YTJlMTAwNDllMzQ1YmQ3YTI3NjQ2OGJlYWI2CmF1dGhvciB1c2VyMSA8YWRkcmVzczFAZXhhbXBsZS5jb20+IDE0ODk5NTY0NzkgLTA0MDAKY29tbWl0dGVyIEV0aGFuIEtvZW5pZyA8ZXRoYW50a29lbmlnQGdtYWlsLmNvbT4gMTQ4OTk1NjQ3OSAtMDQwMAoKSW5pdGlhbCBjb21taXQK",
|
2019-04-17 18:06:35 +02:00
|
|
|
Encoding: "base64",
|
|
|
|
URL: "https://try.gitea.io/api/v1/repos/user2/repo1/git/blobs/65f1bf27bc3bf70f64657658635e66094edbcb4d",
|
|
|
|
SHA: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
|
|
|
|
Size: 180,
|
|
|
|
}
|
2020-07-19 11:53:40 +02:00
|
|
|
assert.NoError(t, err)
|
2019-04-17 18:06:35 +02:00
|
|
|
assert.Equal(t, expectedGBR, gbr)
|
|
|
|
}
|