Don't use semver library for ordering by default

Use debian to parse versions and selections.
This covers ordering of versions like -0,-1 in sequence plus many others
not available with semver. It is backward compatible as we do support
the same featureset as before as tests are passing (adding more actually
to cover interesting cases)
This commit is contained in:
Ettore Di Giacinto
2021-09-20 19:21:00 +02:00
parent e3063985b2
commit ff46bc7641
5 changed files with 232 additions and 761 deletions

View File

@@ -17,6 +17,8 @@
package version_test
import (
"fmt"
. "github.com/mudler/luet/pkg/versioner"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@@ -71,6 +73,14 @@ var _ = Describe("Versioner", func() {
})
})
Context("Sorting with +", func() {
versioner := DefaultVersioner()
It("finds the correct ordering", func() {
sorted := versioner.Sort([]string{"1.0+1", "1.0+0", "0.1", "1.0+3", "1.0+2", "1.9"})
Expect(sorted).Should(Equal([]string{"0.1", "1.0+0", "1.0+1", "1.0+2", "1.0+3", "1.9"}))
})
})
// from: https://github.com/knqyf263/go-deb-version/blob/master/version_test.go#L8
Context("Debian Sorting", func() {
versioner := DefaultVersioner()
@@ -79,4 +89,75 @@ var _ = Describe("Versioner", func() {
Expect(sorted).Should(Equal([]string{"2:7.4.052-1ubuntu1", "2:7.4.052-1ubuntu2", "2:7.4.052-1ubuntu3", "2:7.4.052-1ubuntu3.1"}))
})
})
It("finds the correct ordering", func() {
versioner := DefaultVersioner()
sorted := versioner.Sort([]string{"0.0.1-beta-9", "0.0.1-alpha08-9", "0.0.1-alpha07-9", "0.0.1-alpha07-8"})
Expect(sorted).Should(Equal([]string{"0.0.1-alpha07-8", "0.0.1-alpha07-9", "0.0.1-alpha08-9", "0.0.1-beta-9"}))
})
It("finds the correct ordering", func() {
versioner := DefaultVersioner()
sorted := versioner.Sort([]string{"0.0.1-beta01", "0.0.1-alpha08", "0.0.1-alpha07"})
Expect(sorted).Should(Equal([]string{"0.0.1-alpha07", "0.0.1-alpha08", "0.0.1-beta01"}))
})
Context("Matching a selector", func() {
testCases := [][]string{
{">=1", "2"},
{"<=3", "2"},
{">0", ""},
{">0", "0.0.40-alpha"},
{">=0.1.0+0.4", "0.1.0+0.5"},
{">=0.0.20190406.4.9.172-r1", "1.0.111"},
{">=0", "1.0.29+pre2_p20191024"},
{">=0.1.0+4", "0.1.0+5"},
{">0.1.0-4", "0.1.0-5"},
{"<1.2.3-beta", "1.2.3-beta.1-1"},
{"<1.2.3", "1.2.3-beta.1"},
{">0.0.1-alpha07", "0.0.1-alpha07-8"},
{">0.0.1-alpha07-1", "0.0.1-alpha07-8"},
{">0.0.1-alpha07", "0.0.1-alpha08"},
}
versioner := DefaultVersioner()
for i, t := range testCases {
selector := testCases[i][0]
version := testCases[i][1]
It(fmt.Sprint(t), func() {
Expect(versioner.ValidateSelector(version, selector)).Should(BeTrue())
})
}
})
Context("Not matching a selector", func() {
testfalseCases := [][]string{
{">0.0.1-alpha07", "0.0.1-alpha06"},
{"<0.0.1-alpha07", "0.0.1-alpha08"},
{">0.1.0+0.4", "0.1.0+0.3"},
{">=0.0.20190406.4.9.172-r1", "0"},
{"<=1", "2"},
{">=3", "2"},
{"<0", "0.0.40-alpha"},
{"<0.1.0+0.4", "0.1.0+0.5"},
{"<=0.0.20190406.4.9.172-r1", "1.0.111"},
{"<0.1.0+4", "0.1.0+5"},
{"<=0.1.0-4", "0.1.0-5"},
}
versioner := DefaultVersioner()
for i, t := range testfalseCases {
selector := testfalseCases[i][0]
version := testfalseCases[i][1]
It(fmt.Sprint(t), func() {
Expect(versioner.ValidateSelector(version, selector)).Should(BeFalse())
})
}
})
})