1
// Copyright 2019 The Gitea Authors. All rights reserved.
2
// SPDX-License-Identifier: MIT
10
"github.com/stretchr/testify/assert"
13
func TestReadingBlameOutput(t *testing.T) {
14
ctx, cancel := context.WithCancel(context.Background())
17
t.Run("Without .git-blame-ignore-revs", func(t *testing.T) {
18
repo, err := OpenRepository(ctx, "./tests/repos/repo5_pulls")
19
assert.NoError(t, err)
22
commit, err := repo.GetCommit("f32b0a9dfd09a60f616f29158f772cedd89942d2")
23
assert.NoError(t, err)
25
parts := []*BlamePart{
27
Sha: "72866af952e98d02a73003501836074b286a78f6",
30
"Test repository for testing migration from github to gitea",
34
Sha: "f32b0a9dfd09a60f616f29158f772cedd89942d2",
35
Lines: []string{"", "Do not make any changes to this repo it is used for unit testing"},
36
PreviousSha: "72866af952e98d02a73003501836074b286a78f6",
37
PreviousPath: "README.md",
41
for _, bypass := range []bool{false, true} {
42
blameReader, err := CreateBlameReader(ctx, Sha1ObjectFormat, "./tests/repos/repo5_pulls", commit, "README.md", bypass)
43
assert.NoError(t, err)
44
assert.NotNil(t, blameReader)
45
defer blameReader.Close()
47
assert.False(t, blameReader.UsesIgnoreRevs())
49
for _, part := range parts {
50
actualPart, err := blameReader.NextPart()
51
assert.NoError(t, err)
52
assert.Equal(t, part, actualPart)
55
// make sure all parts have been read
56
actualPart, err := blameReader.NextPart()
57
assert.Nil(t, actualPart)
58
assert.NoError(t, err)
62
t.Run("With .git-blame-ignore-revs", func(t *testing.T) {
63
repo, err := OpenRepository(ctx, "./tests/repos/repo6_blame")
64
assert.NoError(t, err)
69
Sha: "af7486bd54cfc39eea97207ca666aa69c9d6df93",
70
Lines: []string{"line", "line"},
73
Sha: "45fb6cbc12f970b04eacd5cd4165edd11c8d7376",
74
Lines: []string{"changed line"},
75
PreviousSha: "af7486bd54cfc39eea97207ca666aa69c9d6df93",
76
PreviousPath: "blame.txt",
79
Sha: "af7486bd54cfc39eea97207ca666aa69c9d6df93",
80
Lines: []string{"line", "line", ""},
91
CommitID: "544d8f7a3b15927cddf2299b4b562d6ebd71b6a7",
96
Sha: "af7486bd54cfc39eea97207ca666aa69c9d6df93",
97
Lines: []string{"line", "line", "changed line", "line", "line", ""},
102
CommitID: "544d8f7a3b15927cddf2299b4b562d6ebd71b6a7",
103
UsesIgnoreRevs: false,
108
CommitID: "45fb6cbc12f970b04eacd5cd4165edd11c8d7376",
109
UsesIgnoreRevs: false,
114
CommitID: "45fb6cbc12f970b04eacd5cd4165edd11c8d7376",
115
UsesIgnoreRevs: false,
121
objectFormat, err := repo.GetObjectFormat()
122
assert.NoError(t, err)
123
for _, c := range cases {
124
commit, err := repo.GetCommit(c.CommitID)
125
assert.NoError(t, err)
127
blameReader, err := CreateBlameReader(ctx, objectFormat, "./tests/repos/repo6_blame", commit, "blame.txt", c.Bypass)
128
assert.NoError(t, err)
129
assert.NotNil(t, blameReader)
130
defer blameReader.Close()
132
assert.Equal(t, c.UsesIgnoreRevs, blameReader.UsesIgnoreRevs())
134
for _, part := range c.Parts {
135
actualPart, err := blameReader.NextPart()
136
assert.NoError(t, err)
137
assert.Equal(t, part, actualPart)
140
// make sure all parts have been read
141
actualPart, err := blameReader.NextPart()
142
assert.Nil(t, actualPart)
143
assert.NoError(t, err)