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.

blame_test.go 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package git
  5. import (
  6. "context"
  7. "io/ioutil"
  8. "testing"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. const exampleBlame = `
  12. 4b92a6c2df28054ad766bc262f308db9f6066596 1 1 1
  13. author Unknown
  14. author-mail <joe2010xtmf@163.com>
  15. author-time 1392833071
  16. author-tz -0500
  17. committer Unknown
  18. committer-mail <joe2010xtmf@163.com>
  19. committer-time 1392833071
  20. committer-tz -0500
  21. summary Add code of delete user
  22. previous be0ba9ea88aff8a658d0495d36accf944b74888d gogs.go
  23. filename gogs.go
  24. // Copyright 2014 The Gogs Authors. All rights reserved.
  25. ce21ed6c3490cdfad797319cbb1145e2330a8fef 2 2 1
  26. author Joubert RedRat
  27. author-mail <eu+github@redrat.com.br>
  28. author-time 1482322397
  29. author-tz -0200
  30. committer Lunny Xiao
  31. committer-mail <xiaolunwen@gmail.com>
  32. committer-time 1482322397
  33. committer-tz +0800
  34. summary Remove remaining Gogs reference on locales and cmd (#430)
  35. previous 618407c018cdf668ceedde7454c42fb22ba422d8 main.go
  36. filename main.go
  37. // Copyright 2016 The Gitea Authors. All rights reserved.
  38. 4b92a6c2df28054ad766bc262f308db9f6066596 2 3 2
  39. author Unknown
  40. author-mail <joe2010xtmf@163.com>
  41. author-time 1392833071
  42. author-tz -0500
  43. committer Unknown
  44. committer-mail <joe2010xtmf@163.com>
  45. committer-time 1392833071
  46. committer-tz -0500
  47. summary Add code of delete user
  48. previous be0ba9ea88aff8a658d0495d36accf944b74888d gogs.go
  49. filename gogs.go
  50. // Use of this source code is governed by a MIT-style
  51. 4b92a6c2df28054ad766bc262f308db9f6066596 3 4
  52. author Unknown
  53. author-mail <joe2010xtmf@163.com>
  54. author-time 1392833071
  55. author-tz -0500
  56. committer Unknown
  57. committer-mail <joe2010xtmf@163.com>
  58. committer-time 1392833071
  59. committer-tz -0500
  60. summary Add code of delete user
  61. previous be0ba9ea88aff8a658d0495d36accf944b74888d gogs.go
  62. filename gogs.go
  63. // license that can be found in the LICENSE file.
  64. e2aa991e10ffd924a828ec149951f2f20eecead2 6 6 2
  65. author Lunny Xiao
  66. author-mail <xiaolunwen@gmail.com>
  67. author-time 1478872595
  68. author-tz +0800
  69. committer Sandro Santilli
  70. committer-mail <strk@kbt.io>
  71. committer-time 1478872595
  72. committer-tz +0100
  73. summary ask for go get from code.gitea.io/gitea and change gogs to gitea on main file (#146)
  74. previous 5fc370e332171b8658caed771b48585576f11737 main.go
  75. filename main.go
  76. // Gitea (git with a cup of tea) is a painless self-hosted Git Service.
  77. e2aa991e10ffd924a828ec149951f2f20eecead2 7 7
  78. package main // import "code.gitea.io/gitea"
  79. `
  80. func TestReadingBlameOutput(t *testing.T) {
  81. tempFile, err := ioutil.TempFile("", ".txt")
  82. if err != nil {
  83. panic(err)
  84. }
  85. defer tempFile.Close()
  86. if _, err = tempFile.WriteString(exampleBlame); err != nil {
  87. panic(err)
  88. }
  89. ctx, cancel := context.WithCancel(context.Background())
  90. defer cancel()
  91. blameReader, err := createBlameReader(ctx, "", "cat", tempFile.Name())
  92. if err != nil {
  93. panic(err)
  94. }
  95. defer blameReader.Close()
  96. parts := []*BlamePart{
  97. {
  98. "4b92a6c2df28054ad766bc262f308db9f6066596",
  99. []string{
  100. "// Copyright 2014 The Gogs Authors. All rights reserved.",
  101. },
  102. },
  103. {
  104. "ce21ed6c3490cdfad797319cbb1145e2330a8fef",
  105. []string{
  106. "// Copyright 2016 The Gitea Authors. All rights reserved.",
  107. },
  108. },
  109. {
  110. "4b92a6c2df28054ad766bc262f308db9f6066596",
  111. []string{
  112. "// Use of this source code is governed by a MIT-style",
  113. "// license that can be found in the LICENSE file.",
  114. "",
  115. },
  116. },
  117. {
  118. "e2aa991e10ffd924a828ec149951f2f20eecead2",
  119. []string{
  120. "// Gitea (git with a cup of tea) is a painless self-hosted Git Service.",
  121. "package main // import \"code.gitea.io/gitea\"",
  122. },
  123. },
  124. nil,
  125. }
  126. for _, part := range parts {
  127. actualPart, err := blameReader.NextPart()
  128. if err != nil {
  129. panic(err)
  130. }
  131. assert.Equal(t, part, actualPart)
  132. }
  133. }