Skip to content

Commit

Permalink
fix sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
choffmeister committed Nov 19, 2021
1 parent e05650a commit cc2ce02
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
14 changes: 7 additions & 7 deletions internal/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ func (l versionParsedList) Less(i, j int) bool {
if cmp < 0 {
return false
}
cmp2 := strings.Compare(a.Version, b.Version)
if cmp2 > 0 {
return true
}
if cmp2 < 0 {
return false
}
}
cmp2 := strings.Compare(a.Version, b.Version)
if cmp2 > 0 {
return true
}
if cmp2 < 0 {
return false
}
return false
}
Expand Down
8 changes: 6 additions & 2 deletions internal/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestPolicyFilterAndSort(t *testing.T) {
p1 := Policy{}
actual, err := p1.FilterAndSort("1", []string{"1", "2", "3"}, "", "")
if assert.NoError(t, err) {
assert.Equal(t, []string{"1", "2", "3"}, *actual)
assert.Equal(t, []string{"3", "2", "1"}, *actual)
}

p2 := Policy{
Expand Down Expand Up @@ -92,6 +92,10 @@ func TestPolicyFilterAndSort(t *testing.T) {
assert.Error(t, err)
_, err = p2.FilterAndSort("1.0-ubuntu", strings.Split("17.10 v18.04-ubuntu v18.10-ubuntu v19.04-ubuntu v19.10-ubuntu v20.04-ubuntu v20.10-ubuntu v21.04-ubuntu v21.10-ubuntu v22.04-ubuntu", " "), "v", "-ubuntu")
assert.Error(t, err)
actual, err = p2.FilterAndSort("1.0", strings.Split("1.2 1.10 2.1 2.10", " "), "", "")
if assert.NoError(t, err) {
assert.Equal(t, strings.Split("2.10 2.1 1.10 1.2", " "), *actual)
}

p3 := Policy{
Pattern: regexp.MustCompile(`^(?P<number>\d+)(?P<rest>.*)?$`),
Expand All @@ -112,7 +116,7 @@ func TestPolicyFindNext(t *testing.T) {
p1 := Policy{}
actual, err := p1.FindNext("1", []string{"1", "2", "3"}, "", "")
if assert.NoError(t, err) {
assert.Equal(t, "1", *actual)
assert.Equal(t, "3", *actual)
}

p2 := Policy{
Expand Down

0 comments on commit cc2ce02

Please sign in to comment.