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.

git_blame_test.go 3.6KB

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