summaryrefslogtreecommitdiffstats
path: root/pkg/commands/git_commands/branch_loader_test.go
diff options
context:
space:
mode:
authorsudoburt <sudoburt@proton.me>2022-11-10 21:19:29 -0500
committerJesse Duffield <jessedduffield@gmail.com>2022-11-14 18:11:45 +1100
commit3e73dacce3365b540b278c3e1afb9bd8059d1ce7 (patch)
treed2706dc236491f7839ff5119e4eb60409e5bdbd8 /pkg/commands/git_commands/branch_loader_test.go
parentf67824b349fdbdcd1779e260f80bd26a446a4702 (diff)
Merge loaders package into git_commands package
Diffstat (limited to 'pkg/commands/git_commands/branch_loader_test.go')
-rw-r--r--pkg/commands/git_commands/branch_loader_test.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/pkg/commands/git_commands/branch_loader_test.go b/pkg/commands/git_commands/branch_loader_test.go
new file mode 100644
index 000000000..c147c1484
--- /dev/null
+++ b/pkg/commands/git_commands/branch_loader_test.go
@@ -0,0 +1,52 @@
+package git_commands
+
+// "*|feat/detect-purge|origin/feat/detect-purge|[ahead 1]"
+import (
+ "testing"
+
+ "github.com/jesseduffield/lazygit/pkg/commands/models"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestObtainBanch(t *testing.T) {
+ type scenario struct {
+ testName string
+ input []string
+ expectedBranch *models.Branch
+ }
+
+ scenarios := []scenario{
+ {
+ testName: "TrimHeads",
+ input: []string{"", "heads/a_branch", "", ""},
+ expectedBranch: &models.Branch{Name: "a_branch", Pushables: "?", Pullables: "?", Head: false},
+ },
+ {
+ testName: "NoUpstream",
+ input: []string{"", "a_branch", "", ""},
+ expectedBranch: &models.Branch{Name: "a_branch", Pushables: "?", Pullables: "?", Head: false},
+ },
+ {
+ testName: "IsHead",
+ input: []string{"*", "a_branch", "", ""},
+ expectedBranch: &models.Branch{Name: "a_branch", Pushables: "?", Pullables: "?", Head: true},
+ },
+ {
+ testName: "IsBehindAndAhead",
+ input: []string{"", "a_branch", "a_remote/a_branch", "[behind 2, ahead 3]"},
+ expectedBranch: &models.Branch{Name: "a_branch", Pushables: "3", Pullables: "2", Head: false},
+ },
+ {
+ testName: "RemoteBranchIsGone",
+ input: []string{"", "a_branch", "a_remote/a_branch", "[gone]"},
+ expectedBranch: &models.Branch{Name: "a_branch", UpstreamGone: true, Pushables: "?", Pullables: "?", Head: false},
+ },
+ }
+
+ for _, s := range scenarios {
+ t.Run(s.testName, func(t *testing.T) {
+ branch := obtainBranch(s.input)
+ assert.EqualValues(t, s.expectedBranch, branch)
+ })
+ }
+}