@@ -2,14 +2,12 @@ package function
22
33import (
44 "context"
5- "fmt"
6- "gopkg.in/src-d/go-mysql-server.v0/sql/expression"
7-
85 "github.com/src-d/gitbase"
96 "github.com/stretchr/testify/require"
107 fixtures "gopkg.in/src-d/go-git-fixtures.v3"
118 "gopkg.in/src-d/go-git.v4/plumbing/cache"
129 "gopkg.in/src-d/go-mysql-server.v0/sql"
10+ "gopkg.in/src-d/go-mysql-server.v0/sql/expression"
1311 "testing"
1412)
1513
@@ -21,44 +19,70 @@ func TestBlameEval(t *testing.T) {
2119 }()
2220
2321 path := fixtures .ByTag ("worktree" ).One ().Worktree ().Root ()
24-
2522 pool := gitbase .NewRepositoryPool (cache .DefaultMaxSize )
2623 require .NoError (t , pool .AddGitWithID ("worktree" , path ))
2724
2825 session := gitbase .NewSession (pool )
2926 ctx := sql .NewContext (context .TODO (), sql .WithSession (session ))
3027
3128 testCases := []struct {
32- name string
33- repo sql.Expression
34- commit sql.Expression
35- row sql.Row
36- expected BlameLine
29+ name string
30+ repo sql.Expression
31+ commit sql.Expression
32+ row sql.Row
33+ expected BlameLine
34+ testedLine int
35+ lineCount int
3736 }{
3837 {
39- name : "init commit" ,
40- repo : expression .NewGetField (0 , sql .Text , "repository_id" , false ),
41- commit : expression .NewGetField (1 , sql .Text , "commit_hash" , false ),
42- row : sql .NewRow ("worktree" , "b029517f6300c2da0f4b651b8642506cd6aaf45d" ),
38+ name : "init commit" ,
39+ repo : expression .NewGetField (0 , sql .Text , "repository_id" , false ),
40+ commit : expression .NewGetField (1 , sql .Text , "commit_hash" , false ),
41+ row : sql .NewRow ("worktree" , "b029517f6300c2da0f4b651b8642506cd6aaf45d" ),
42+ testedLine : 0 ,
43+ lineCount : 12 ,
4344 expected : BlameLine {
4445 "b029517f6300c2da0f4b651b8642506cd6aaf45d" ,
4546 ".gitignore" ,
4647 0 ,
4748 "mcuadros@gmail.com" ,
4849 "*.class" ,
4950 },
50- }}
51+ },
52+ {
53+ name : "changelog" ,
54+ repo : expression .NewGetField (0 , sql .Text , "repository_id" , false ),
55+ commit : expression .NewGetField (1 , sql .Text , "commit_hash" , false ),
56+ row : sql .NewRow ("worktree" , "b8e471f58bcbca63b07bda20e428190409c2db47" ),
57+ testedLine : 0 ,
58+ lineCount : 1 ,
59+ expected : BlameLine {
60+ "b8e471f58bcbca63b07bda20e428190409c2db47" ,
61+ "CHANGELOG" ,
62+ 0 ,
63+ "daniel@lordran.local" ,
64+ "Creating changelog" ,
65+ },
66+ },
67+ }
5168
5269 for _ , tc := range testCases {
5370 t .Run (tc .name , func (t * testing.T ) {
5471 blame := NewBlame (tc .repo , tc .commit )
5572 results , err := blame .Eval (ctx , tc .row )
5673 require .NoError (t , err )
57- for _ , r := range results .([]BlameLine ) {
58- fmt .Println (r )
74+ lineCount := 0
75+ for i , r := range results .([]BlameLine ) {
76+ if r .File != tc .expected .File {
77+ continue
78+ }
79+ lineCount ++
80+ if i != tc .testedLine {
81+ continue
82+ }
5983 require .EqualValues (t , tc .expected , r )
60- break
6184 }
85+ require .Equal (t , tc .lineCount , lineCount )
6286 })
6387 }
6488}
0 commit comments