mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 04:15:48 +02:00
Cleanup: don't mess with globals in tests without resetting them
Changing globals in the init() function of a test file is a bad idea, as it affects all other tests that run after it. Do it explicitly in each test function that needs it, and take care of restoring the previous value afterwards.
This commit is contained in:
parent
1cedfa463b
commit
c59e6b6451
5 changed files with 32 additions and 18 deletions
|
@ -15,11 +15,6 @@ import (
|
|||
"github.com/xo/terminfo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// on CI we've got no color capability so we're forcing it here
|
||||
color.ForceSetColorLevel(terminfo.ColorLevelMillions)
|
||||
}
|
||||
|
||||
func TestRenderCommitGraph(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
@ -218,6 +213,9 @@ func TestRenderCommitGraph(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
oldColorLevel := color.ForceSetColorLevel(terminfo.ColorLevelMillions)
|
||||
defer color.ForceSetColorLevel(oldColorLevel)
|
||||
|
||||
for _, test := range tests {
|
||||
test := test
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
|
@ -452,6 +450,9 @@ func TestRenderPipeSet(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
oldColorLevel := color.ForceSetColorLevel(terminfo.ColorLevelMillions)
|
||||
defer color.ForceSetColorLevel(oldColorLevel)
|
||||
|
||||
for _, test := range tests {
|
||||
test := test
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
|
@ -523,6 +524,9 @@ func TestGetNextPipes(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
oldColorLevel := color.ForceSetColorLevel(terminfo.ColorLevelMillions)
|
||||
defer color.ForceSetColorLevel(oldColorLevel)
|
||||
|
||||
for _, test := range tests {
|
||||
getStyle := func(c *models.Commit) style.TextStyle { return style.FgDefault }
|
||||
pipes := getNextPipes(test.prevPipes, test.commit, getStyle)
|
||||
|
@ -538,6 +542,9 @@ func TestGetNextPipes(t *testing.T) {
|
|||
}
|
||||
|
||||
func BenchmarkRenderCommitGraph(b *testing.B) {
|
||||
oldColorLevel := color.ForceSetColorLevel(terminfo.ColorLevelMillions)
|
||||
defer color.ForceSetColorLevel(oldColorLevel)
|
||||
|
||||
commits := generateCommits(50)
|
||||
getStyle := func(commit *models.Commit) style.TextStyle {
|
||||
return authors.AuthorStyle(commit.AuthorName)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue