2021-12-30 08:48:47 +02:00
|
|
|
package loaders
|
|
|
|
|
|
|
|
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).
|
2022-10-13 15:20:15 +02:00
|
|
|
Expect(`git stash list -z --pretty='%gs'`, "", nil),
|
2021-12-30 08:48:47 +02:00
|
|
|
[]*models.StashEntry{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Several stash entries found",
|
|
|
|
"",
|
|
|
|
oscommands.NewFakeRunner(t).
|
|
|
|
Expect(
|
2022-10-13 15:20:15 +02:00
|
|
|
`git stash list -z --pretty='%gs'`,
|
|
|
|
"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
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|