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

89 lines
2.0 KiB
Go
Raw Normal View History

package git_commands
2022-03-24 08:49:25 +02:00
// "*|feat/detect-purge|origin/feat/detect-purge|[ahead 1]"
import (
"testing"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/stretchr/testify/assert"
)
2022-11-07 07:35:36 +02:00
func TestObtainBranch(t *testing.T) {
2022-03-24 08:49:25 +02:00
type scenario struct {
testName string
input []string
expectedBranch *models.Branch
}
scenarios := []scenario{
{
2022-11-07 07:35:36 +02:00
testName: "TrimHeads",
input: []string{"", "heads/a_branch", "", "", "subject", "123"},
expectedBranch: &models.Branch{
Name: "a_branch",
Pushables: "?",
Pullables: "?",
Head: false,
Subject: "subject",
CommitHash: "123",
},
2022-03-24 08:49:25 +02:00
},
{
2022-11-07 07:35:36 +02:00
testName: "NoUpstream",
input: []string{"", "a_branch", "", "", "subject", "123"},
expectedBranch: &models.Branch{
Name: "a_branch",
Pushables: "?",
Pullables: "?",
Head: false,
Subject: "subject",
CommitHash: "123",
},
2022-03-24 08:49:25 +02:00
},
{
2022-11-07 07:35:36 +02:00
testName: "IsHead",
input: []string{"*", "a_branch", "", "", "subject", "123"},
expectedBranch: &models.Branch{
Name: "a_branch",
Pushables: "?",
Pullables: "?",
Head: true,
Subject: "subject",
CommitHash: "123",
},
2022-03-24 08:49:25 +02:00
},
{
2022-11-07 07:35:36 +02:00
testName: "IsBehindAndAhead",
input: []string{"", "a_branch", "a_remote/a_branch", "[behind 2, ahead 3]", "subject", "123"},
expectedBranch: &models.Branch{
Name: "a_branch",
Pushables: "3",
Pullables: "2",
Head: false,
Subject: "subject",
CommitHash: "123",
},
2022-03-24 08:49:25 +02:00
},
{
2022-11-07 07:35:36 +02:00
testName: "RemoteBranchIsGone",
input: []string{"", "a_branch", "a_remote/a_branch", "[gone]", "subject", "123"},
expectedBranch: &models.Branch{
Name: "a_branch",
UpstreamGone: true,
Pushables: "?",
Pullables: "?",
Head: false,
Subject: "subject",
CommitHash: "123",
},
2022-03-24 08:49:25 +02:00
},
}
for _, s := range scenarios {
t.Run(s.testName, func(t *testing.T) {
branch := obtainBranch(s.input)
assert.EqualValues(t, s.expectedBranch, branch)
})
}
}