本站源代码
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.

72 satır
2.2KB

  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Copyright 2019 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package git
  6. import (
  7. "io/ioutil"
  8. "testing"
  9. "github.com/stretchr/testify/assert"
  10. "github.com/stretchr/testify/require"
  11. )
  12. func TestBlob_Data(t *testing.T) {
  13. output := `Copyright (c) 2016 The Gitea Authors
  14. Copyright (c) 2015 The Gogs Authors
  15. Permission is hereby granted, free of charge, to any person obtaining a copy
  16. of this software and associated documentation files (the "Software"), to deal
  17. in the Software without restriction, including without limitation the rights
  18. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  19. copies of the Software, and to permit persons to whom the Software is
  20. furnished to do so, subject to the following conditions:
  21. The above copyright notice and this permission notice shall be included in
  22. all copies or substantial portions of the Software.
  23. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  26. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  28. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  29. THE SOFTWARE.
  30. `
  31. repo, err := OpenRepository("../../.git")
  32. assert.NoError(t, err)
  33. testBlob, err := repo.GetBlob("a8d4b49dd073a4a38a7e58385eeff7cc52568697")
  34. assert.NoError(t, err)
  35. r, err := testBlob.DataAsync()
  36. assert.NoError(t, err)
  37. require.NotNil(t, r)
  38. defer r.Close()
  39. data, err := ioutil.ReadAll(r)
  40. assert.NoError(t, err)
  41. assert.Equal(t, output, string(data))
  42. }
  43. func Benchmark_Blob_Data(b *testing.B) {
  44. repo, err := OpenRepository("../../.git")
  45. if err != nil {
  46. b.Fatal(err)
  47. }
  48. testBlob, err := repo.GetBlob("a8d4b49dd073a4a38a7e58385eeff7cc52568697")
  49. if err != nil {
  50. b.Fatal(err)
  51. }
  52. for i := 0; i < b.N; i++ {
  53. r, err := testBlob.DataAsync()
  54. if err != nil {
  55. b.Fatal(err)
  56. }
  57. defer r.Close()
  58. ioutil.ReadAll(r)
  59. }
  60. }
上海开阖软件有限公司 沪ICP备12045867号-1