mirror of
https://gitcode.com/gitea/gitea.git
synced 2025-06-04 03:09:34 +08:00
.gitea
.github
assets
build
cmd
contrib
custom
docker
docs
integrations
models
modules
activitypub
analyze
appstate
auth
avatar
base
cache
charset
container
context
convert
csv
doctor
emoji
eventsource
generate
git
foreachref
pipeline
tests
url
README.md
batch_reader.go
blame.go
blame_test.go
blob.go
blob_gogit.go
blob_nogogit.go
blob_test.go
command.go
command_race_test.go
command_test.go
commit.go
commit_convert_gogit.go
commit_info.go
commit_info_gogit.go
commit_info_nogogit.go
commit_info_test.go
commit_reader.go
commit_test.go
diff.go
diff_test.go
error.go
git.go
git_test.go
hook.go
last_commit_cache.go
last_commit_cache_gogit.go
last_commit_cache_nogogit.go
log_name_status.go
notes.go
notes_gogit.go
notes_nogogit.go
notes_test.go
parse_gogit.go
parse_gogit_test.go
parse_nogogit.go
parse_nogogit_test.go
ref.go
remote.go
repo.go
repo_archive.go
repo_attribute.go
repo_attribute_test.go
repo_base.go
repo_base_gogit.go
repo_base_nogogit.go
repo_blame.go
repo_blob.go
repo_blob_gogit.go
repo_blob_nogogit.go
repo_blob_test.go
repo_branch.go
repo_branch_gogit.go
repo_branch_nogogit.go
repo_branch_test.go
repo_commit.go
repo_commit_gogit.go
repo_commit_nogogit.go
repo_commit_test.go
repo_commitgraph.go
repo_commitgraph_gogit.go
repo_compare.go
repo_compare_test.go
repo_gpg.go
repo_hook.go
repo_index.go
repo_language_stats.go
repo_language_stats_gogit.go
repo_language_stats_nogogit.go
repo_language_stats_test.go
repo_object.go
repo_ref.go
repo_ref_gogit.go
repo_ref_nogogit.go
repo_ref_test.go
repo_stats.go
repo_stats_test.go
repo_tag.go
repo_tag_gogit.go
repo_tag_nogogit.go
repo_tag_test.go
repo_test.go
repo_tree.go
repo_tree_gogit.go
repo_tree_nogogit.go
sha1.go
sha1_gogit.go
sha1_nogogit.go
signature.go
signature_gogit.go
signature_nogogit.go
submodule.go
submodule_test.go
tag.go
tag_test.go
tree.go
tree_blob.go
tree_blob_gogit.go
tree_blob_nogogit.go
tree_entry.go
tree_entry_gogit.go
tree_entry_mode.go
tree_entry_nogogit.go
tree_entry_test.go
tree_gogit.go
tree_nogogit.go
utils.go
utils_test.go
gitgraph
graceful
hcaptcha
highlight
hostmatcher
httpcache
httplib
indexer
json
lfs
log
markup
mcaptcha
metrics
migration
mirror
nosql
notification
options
packages
paginator
password
pprof
private
process
proxy
proxyprotocol
public
queue
recaptcha
references
regexplru
repository
secret
session
setting
sitemap
ssh
storage
structs
svg
sync
templates
test
timeutil
translation
typesniffer
updatechecker
upload
uri
user
util
validation
watcher
web
options
public
routers
services
snap
templates
tools
web_src
.air.toml
.changelog.yml
.drone.yml
.editorconfig
.eslintrc.yaml
.gitattributes
.gitignore
.golangci.yml
.ignore
.lgtm
.markdownlint.yaml
.npmrc
.spectral.yaml
.stylelintrc.yaml
BSDmakefile
CHANGELOG.md
CONTRIBUTING.md
DCO
Dockerfile
Dockerfile.rootless
LICENSE
MAINTAINERS
Makefile
README.md
README_ZH.md
SECURITY.md
build.go
go.mod
go.sum
jest.config.js
main.go
package-lock.json
package.json
webpack.config.js

* OpenRepositoryCtx -> OpenRepository * OpenRepository -> openRepositoryWithDefaultContext, only for internal usage
62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
// Copyright 2015 The Gogs Authors. All rights reserved.
|
|
// 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 git
|
|
|
|
import (
|
|
"io"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestBlob_Data(t *testing.T) {
|
|
output := "file2\n"
|
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
|
repo, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
|
if !assert.NoError(t, err) {
|
|
t.Fatal()
|
|
}
|
|
defer repo.Close()
|
|
|
|
testBlob, err := repo.GetBlob("6c493ff740f9380390d5c9ddef4af18697ac9375")
|
|
assert.NoError(t, err)
|
|
|
|
r, err := testBlob.DataAsync()
|
|
assert.NoError(t, err)
|
|
require.NotNil(t, r)
|
|
|
|
data, err := io.ReadAll(r)
|
|
assert.NoError(t, r.Close())
|
|
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, output, string(data))
|
|
}
|
|
|
|
func Benchmark_Blob_Data(b *testing.B) {
|
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
|
repo, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
defer repo.Close()
|
|
|
|
testBlob, err := repo.GetBlob("6c493ff740f9380390d5c9ddef4af18697ac9375")
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
r, err := testBlob.DataAsync()
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
io.ReadAll(r)
|
|
_ = r.Close()
|
|
}
|
|
}
|