You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

blob_test.go 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Copyright 2019 The Gitea Authors. All rights reserved.
  3. // SPDX-License-Identifier: MIT
  4. package git
  5. import (
  6. "io"
  7. "path/filepath"
  8. "testing"
  9. "github.com/stretchr/testify/assert"
  10. "github.com/stretchr/testify/require"
  11. )
  12. func TestBlob_Data(t *testing.T) {
  13. output := "file2\n"
  14. bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
  15. repo, err := openRepositoryWithDefaultContext(bareRepo1Path)
  16. if !assert.NoError(t, err) {
  17. t.Fatal()
  18. }
  19. defer repo.Close()
  20. testBlob, err := repo.GetBlob("6c493ff740f9380390d5c9ddef4af18697ac9375")
  21. assert.NoError(t, err)
  22. r, err := testBlob.DataAsync()
  23. assert.NoError(t, err)
  24. require.NotNil(t, r)
  25. data, err := io.ReadAll(r)
  26. assert.NoError(t, r.Close())
  27. assert.NoError(t, err)
  28. assert.Equal(t, output, string(data))
  29. }
  30. func Benchmark_Blob_Data(b *testing.B) {
  31. bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
  32. repo, err := openRepositoryWithDefaultContext(bareRepo1Path)
  33. if err != nil {
  34. b.Fatal(err)
  35. }
  36. defer repo.Close()
  37. testBlob, err := repo.GetBlob("6c493ff740f9380390d5c9ddef4af18697ac9375")
  38. if err != nil {
  39. b.Fatal(err)
  40. }
  41. for i := 0; i < b.N; i++ {
  42. r, err := testBlob.DataAsync()
  43. if err != nil {
  44. b.Fatal(err)
  45. }
  46. io.ReadAll(r)
  47. _ = r.Close()
  48. }
  49. }