-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
771e0c3
commit 1b22b47
Showing
3 changed files
with
86 additions
and
12 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
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,8 @@ | ||
package git | ||
|
||
import ( | ||
"io/ioutil" | ||
Check failure on line 4 in internal/git/blame_test.go GitHub Actions / Lint
|
||
"os" | ||
"testing" | ||
) | ||
|
||
|
@@ -19,14 +21,56 @@ func TestBlame(t *testing.T) { | |
t.Fatal("failed to blame file. Error:", err) | ||
} | ||
|
||
if len(blameRes[0].Lines) == 0 { | ||
t.Fatal("Should be larger than 0 lines, was", len(blameRes[0].Lines)) | ||
if len(blameRes.Files[0].Lines) == 0 { | ||
t.Fatal("Should be larger than 0 lines, was", len(blameRes.Files[0].Lines)) | ||
} | ||
|
||
if blameRes[0].Lines[0].Author.Name == "" { | ||
if blameRes.Files[0].Lines[0].Author.Name == "" { | ||
t.Fatal("Author should not be empty") | ||
} | ||
if blameRes[0].Lines[0].Author.Email == "" { | ||
if blameRes.Files[0].Lines[0].Author.Email == "" { | ||
t.Fatal("Email should not be empty") | ||
} | ||
} | ||
|
||
func TestToFile(t *testing.T) { | ||
|
||
tempFile, err := os.CreateTemp("", "test") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.Remove(tempFile.Name()) // clean up | ||
|
||
blamefiles := BlameFiles{ | ||
Files: []BlameFile{ | ||
{ | ||
Lines: []BlameLine{ | ||
{ | ||
Author: Author{ | ||
Email: "[email protected]", | ||
Name: "Example", | ||
}, | ||
LineNumber: 1, | ||
}, | ||
}, | ||
Path: "example.txt", | ||
}, | ||
}, | ||
} | ||
|
||
err = blamefiles.ToFile(tempFile.Name()) | ||
if err != nil { | ||
t.Fatal("failed to write to file. Error:", err) | ||
} | ||
|
||
content, err := ioutil.ReadFile(tempFile.Name()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
expected := "example.txt,1,Example,[email protected]\n" | ||
if string(content) != expected { | ||
t.Errorf("Expected %s, got %s", expected, content) | ||
} | ||
|
||
} |