Skip to content

Commit

Permalink
Use proper version comparisions for querys
Browse files Browse the repository at this point in the history
  • Loading branch information
russelltg authored and randombenj committed Apr 27, 2022
1 parent 4c04e77 commit 954b222
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
10 changes: 5 additions & 5 deletions deb/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ func (q *FieldQuery) Matches(pkg PackageLike) bool {
case VersionDontCare:
return field != ""
case VersionEqual:
return field == q.Value
return CompareVersions(field, q.Value) == 0
case VersionGreater:
return field > q.Value
return CompareVersions(field, q.Value) > 0
case VersionGreaterOrEqual:
return field >= q.Value
return CompareVersions(field, q.Value) >= 0
case VersionLess:
return field < q.Value
return CompareVersions(field, q.Value) < 0
case VersionLessOrEqual:
return field <= q.Value
return CompareVersions(field, q.Value) <= 0
case VersionPatternMatch:
matched, err := filepath.Match(q.Value, field)
return err == nil && matched
Expand Down
23 changes: 23 additions & 0 deletions deb/query_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package deb

import (
. "gopkg.in/check.v1"
)

type QuerySuite struct {
}

var _ = Suite(&QuerySuite{})

func (s *QuerySuite) TestVersionCompare(c *C) {
q := FieldQuery{"Version", VersionLess, "5.0.0.2", nil}

p100 := Package{}
p100.Version = "5.0.0.100"

p1 := Package{}
p1.Version = "5.0.0.1"

c.Check(q.Matches(&p100), Equals, false)
c.Check(q.Matches(&p1), Equals, true)
}
2 changes: 2 additions & 0 deletions deb/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ func (s *VersionSuite) TestCompareVersions(c *C) {

c.Check(CompareVersions("1.0-133-avc", "1.1"), Equals, -1)
c.Check(CompareVersions("1.0-133-avc", "1.0"), Equals, 1)

c.Check(CompareVersions("5.2.0.3", "5.2.0.283"), Equals, -1)
}

func (s *VersionSuite) TestParseDependency(c *C) {
Expand Down

0 comments on commit 954b222

Please sign in to comment.