This repository has been archived by the owner on Jan 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from pinpt/code_by_commit
Add CodeByCommit method that returns code information grouped by commit.
- Loading branch information
Showing
8 changed files
with
152 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,52 @@ | ||
package e2etests | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/pinpt/ripsrc/ripsrc" | ||
) | ||
|
||
// Test results for a basic repo for both CodeSlice and Code2 calls | ||
func TestBasic(t *testing.T) { | ||
test := NewTest(t, "basic") | ||
got := test.Run(nil) | ||
var got []ripsrc.BlameResult | ||
|
||
type commit struct { | ||
SHA string | ||
Files []ripsrc.BlameResult | ||
} | ||
var byCommit []commit | ||
|
||
NewTest(t, "basic").Run(nil, func(rip *ripsrc.Ripsrc) { | ||
{ | ||
var err error | ||
got, err = rip.CodeSlice(context.Background()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
{ | ||
ch := make(chan ripsrc.CommitCode) | ||
done := make(chan bool) | ||
go func() { | ||
for c := range ch { | ||
c2 := commit{} | ||
c2.SHA = c.SHA | ||
for f := range c.Files { | ||
c2.Files = append(c2.Files, f) | ||
} | ||
byCommit = append(byCommit, c2) | ||
} | ||
done <- true | ||
}() | ||
defer func() { <-done }() | ||
err := rip.CodeByCommit(context.Background(), ch) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
}) | ||
|
||
u1n := "User1" | ||
u1e := "[email protected]" | ||
|
@@ -133,4 +171,19 @@ func TestBasic(t *testing.T) { | |
} | ||
|
||
assertResult(t, want, got) | ||
|
||
if len(byCommit) != 2 { | ||
t.Fatal("expecting 2 commits") | ||
} | ||
|
||
if byCommit[0].SHA != commit1.SHA { | ||
t.Fatal("invalid sha") | ||
} | ||
|
||
if len(byCommit[0].Files) != 1 { | ||
t.Fatal("invalid files len") | ||
} | ||
|
||
assertBlame(t, byCommit[0].Files[0], want[0]) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,23 @@ | ||
package e2etests | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/pinpt/ripsrc/ripsrc" | ||
) | ||
|
||
func TestDeletedFiles(t *testing.T) { | ||
test := NewTest(t, "deleted_files") | ||
got := test.Run(nil) | ||
|
||
var got []ripsrc.BlameResult | ||
test.Run(nil, func(rip *ripsrc.Ripsrc) { | ||
var err error | ||
got, err = rip.CodeSlice(context.Background()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
}) | ||
|
||
u1n := "User1" | ||
u1e := "[email protected]" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package e2etests | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/pinpt/ripsrc/ripsrc" | ||
|
@@ -10,7 +11,15 @@ import ( | |
// If the file in repo was a binary at some point and then switched to text and was modified, then git log with patches does not contain the full file content. There are 2 options to fix this, either we ignore all files that at some point in history were binary or retrieve the full file content for these cases separately without using log and patches. | ||
func TestEditingFormerBinFile(t *testing.T) { | ||
test := NewTest(t, "editing_former_bin_file") | ||
got := test.Run(nil) | ||
|
||
var got []ripsrc.BlameResult | ||
test.Run(nil, func(rip *ripsrc.Ripsrc) { | ||
var err error | ||
got, err = rip.CodeSlice(context.Background()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
}) | ||
|
||
u1n := "User1" | ||
u1e := "[email protected]" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,23 @@ | ||
package e2etests | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/pinpt/ripsrc/ripsrc" | ||
) | ||
|
||
func TestMergeBasic(t *testing.T) { | ||
test := NewTest(t, "merge_basic") | ||
got := test.Run(nil) | ||
|
||
var got []ripsrc.BlameResult | ||
test.Run(nil, func(rip *ripsrc.Ripsrc) { | ||
var err error | ||
got, err = rip.CodeSlice(context.Background()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
}) | ||
|
||
u1n := "User1" | ||
u1e := "[email protected]" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters