diff options
author | Ryooooooga <eial5q265e5@gmail.com> | 2022-12-31 22:47:21 +0900 |
---|---|---|
committer | Ryooooooga <eial5q265e5@gmail.com> | 2022-12-31 22:47:21 +0900 |
commit | 7c5f33980f541472aa29e4e072ace63358983308 (patch) | |
tree | 6a0b00717df2d30680bd408b7cbc258a4dab8d90 /pkg/commands/git_commands/tag_loader_test.go | |
parent | cceff63823540eb70c02ee89898e4dafd695aaa4 (diff) |
fix: improve backward compatibility
Diffstat (limited to 'pkg/commands/git_commands/tag_loader_test.go')
-rw-r--r-- | pkg/commands/git_commands/tag_loader_test.go | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/pkg/commands/git_commands/tag_loader_test.go b/pkg/commands/git_commands/tag_loader_test.go index f8696cafa..287d6e3c6 100644 --- a/pkg/commands/git_commands/tag_loader_test.go +++ b/pkg/commands/git_commands/tag_loader_test.go @@ -20,6 +20,7 @@ testtag func TestGetTags(t *testing.T) { type scenario struct { testName string + gitVersion *GitVersion runner *oscommands.FakeCmdObjRunner expectedTags []*models.Tag expectedError error @@ -27,14 +28,24 @@ func TestGetTags(t *testing.T) { scenarios := []scenario{ { - testName: "should return no tags if there are none", + testName: "should return no tags if there are none", + gitVersion: &GitVersion{2, 7, 0, ""}, runner: oscommands.NewFakeRunner(t). Expect(`git tag --list --sort=-creatordate`, "", nil), expectedTags: []*models.Tag{}, expectedError: nil, }, { - testName: "should return tags if present", + testName: "should return no tags if there are none (< 2.7.0)", + gitVersion: &GitVersion{2, 6, 7, ""}, + runner: oscommands.NewFakeRunner(t). + Expect(`git tag --list --sort=-v:refname`, "", nil), + expectedTags: []*models.Tag{}, + expectedError: nil, + }, + { + testName: "should return tags if present", + gitVersion: &GitVersion{2, 7, 0, ""}, runner: oscommands.NewFakeRunner(t). Expect(`git tag --list --sort=-creatordate`, tagsOutput, nil), expectedTags: []*models.Tag{ @@ -47,15 +58,31 @@ func TestGetTags(t *testing.T) { }, expectedError: nil, }, + { + testName: "should return tags if present (< 2.7.0)", + gitVersion: &GitVersion{2, 6, 7, ""}, + runner: oscommands.NewFakeRunner(t). + Expect(`git tag --list --sort=-v:refname`, 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), - } + loader := NewTagLoader( + utils.NewDummyCommon(), + scenario.gitVersion, + oscommands.NewDummyCmdObjBuilder(scenario.runner), + ) tags, err := loader.GetTags() |