1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-14 11:23:09 +02:00
lazygit/pkg/commands/git_commands/stash_loader_test.go

60 lines
1.4 KiB
Go
Raw Normal View History

package git_commands
2021-12-30 08:48:47 +02:00
import (
"testing"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/stretchr/testify/assert"
)
2022-01-08 04:22:29 +02:00
func TestGetStashEntries(t *testing.T) {
2021-12-30 08:48:47 +02:00
type scenario struct {
testName string
filterPath string
runner oscommands.ICmdObjRunner
expectedStashEntries []*models.StashEntry
}
scenarios := []scenario{
{
"No stash entries found",
"",
oscommands.NewFakeRunner(t).
ExpectGitArgs([]string{"stash", "list", "-z", "--pretty=%gs"}, "", nil),
2021-12-30 08:48:47 +02:00
[]*models.StashEntry{},
},
{
"Several stash entries found",
"",
oscommands.NewFakeRunner(t).
ExpectGitArgs([]string{"stash", "list", "-z", "--pretty=%gs"},
2022-10-13 15:20:15 +02:00
"WIP on add-pkg-commands-test: 55c6af2 increase parallel build\x00WIP on master: bb86a3f update github template\x00",
2021-12-30 08:48:47 +02:00
nil,
),
[]*models.StashEntry{
{
Index: 0,
Name: "WIP on add-pkg-commands-test: 55c6af2 increase parallel build",
},
{
Index: 1,
Name: "WIP on master: bb86a3f update github template",
},
},
},
}
for _, s := range scenarios {
2022-01-08 06:46:35 +02:00
s := s
2021-12-30 08:48:47 +02:00
t.Run(s.testName, func(t *testing.T) {
cmd := oscommands.NewDummyCmdObjBuilder(s.runner)
loader := NewStashLoader(utils.NewDummyCommon(), cmd)
2022-01-03 05:33:53 +02:00
assert.EqualValues(t, s.expectedStashEntries, loader.GetStashEntries(s.filterPath))
2021-12-30 08:48:47 +02:00
})
}
}