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