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