git-module

fork of https://git.lin.moe/gogs/git-module

git clone git://git.lin.moe/fork/git-module.git

 1package git
 2
 3import (
 4	"context"
 5	"fmt"
 6	"testing"
 7
 8	"github.com/stretchr/testify/assert"
 9)
10
11func TestRepository_Blame(t *testing.T) {
12	ctx := context.Background()
13
14	t.Run("bad file", func(t *testing.T) {
15		_, err := testrepo.Blame(ctx, "", "404.txt")
16		assert.Error(t, err)
17	})
18
19	blame, err := testrepo.Blame(ctx, testrepoMarks[32].String(), "README.txt")
20	assert.Nil(t, err)
21
22	// Assert representative commits
23	// https://github.com/gogs/git-module-testrepo/blame/master/README.txt
24	tests := []struct {
25		line  int
26		expID string
27	}{
28		{line: 1, expID: testrepoMarks[1].String()},
29		{line: 3, expID: testrepoMarks[20].String()},
30		{line: 5, expID: testrepoMarks[1].String()},
31		{line: 13, expID: testrepoMarks[13].String()},
32	}
33	for _, test := range tests {
34		t.Run(fmt.Sprintf("Line %d", test.line), func(t *testing.T) {
35			line := blame.Line(test.line)
36			assert.Equal(t, test.expID, line.ID.String())
37		})
38	}
39}