summaryrefslogtreecommitdiffstats
path: root/pkg/commands/git_commands/tag_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/tag_loader_test.go
parentf67824b349fdbdcd1779e260f80bd26a446a4702 (diff)
Merge loaders package into git_commands package
Diffstat (limited to 'pkg/commands/git_commands/tag_loader_test.go')
-rw-r--r--pkg/commands/git_commands/tag_loader_test.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/pkg/commands/git_commands/tag_loader_test.go b/pkg/commands/git_commands/tag_loader_test.go
new file mode 100644
index 000000000..f8696cafa
--- /dev/null
+++ b/pkg/commands/git_commands/tag_loader_test.go
@@ -0,0 +1,68 @@
+package git_commands
+
+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"
+)
+
+const tagsOutput = `v0.34
+v0.33
+v0.32.2
+v0.32.1
+v0.32
+testtag
+`
+
+func TestGetTags(t *testing.T) {
+ type scenario struct {
+ testName string
+ runner *oscommands.FakeCmdObjRunner
+ expectedTags []*models.Tag
+ expectedError error
+ }
+
+ scenarios := []scenario{
+ {
+ testName: "should return no tags if there are none",
+ runner: oscommands.NewFakeRunner(t).
+ Expect(`git tag --list --sort=-creatordate`, "", nil),
+ expectedTags: []*models.Tag{},
+ expectedError: nil,
+ },
+ {
+ testName: "should return tags if present",
+ runner: oscommands.NewFakeRunner(t).
+ Expect(`git tag --list --sort=-creatordate`, tagsOutput, nil),
+ expectedTags: []*models.Tag{
+ {Name: "v0.34"},
+ {Name: "v0.33"},
+ {Name: "v0.32.2"},
+ {Name: "v0.32.1"},
+ {Name: "v0.32"},
+ {Name: "testtag"},
+ },
+ expectedError: nil,
+ },
+ }
+
+ for _, scenario := range scenarios {
+ scenario := scenario
+ t.Run(scenario.testName, func(t *testing.T) {
+ loader := &TagLoader{
+ Common: utils.NewDummyCommon(),
+ cmd: oscommands.NewDummyCmdObjBuilder(scenario.runner),
+ }
+
+ tags, err := loader.GetTags()
+
+ assert.Equal(t, scenario.expectedTags, tags)
+ assert.Equal(t, scenario.expectedError, err)
+
+ scenario.runner.CheckForMissingCalls()
+ })
+ }
+}