Skip to content

Commit c7f5f70

Browse files
committed
pkg/version: add VersionsFrom function
So plugins can easily declare support for "from version 0.3 and beyond". Signed-off-by: Casey Callendrello <[email protected]>
1 parent 5608690 commit c7f5f70

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Diff for: pkg/version/version.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"fmt"
2020

2121
"github.com/containernetworking/cni/pkg/types"
22-
"github.com/containernetworking/cni/pkg/types/100"
22+
types100 "github.com/containernetworking/cni/pkg/types/100"
2323
"github.com/containernetworking/cni/pkg/types/create"
2424
)
2525

@@ -38,6 +38,22 @@ func Current() string {
3838
var Legacy = PluginSupports("0.1.0", "0.2.0")
3939
var All = PluginSupports("0.1.0", "0.2.0", "0.3.0", "0.3.1", "0.4.0", "1.0.0")
4040

41+
// VersionsFrom returns a list of versions starting from min, inclusive
42+
func VersionsStartingFrom(min string) PluginInfo {
43+
out := []string{}
44+
// cheat, just assume ordered
45+
ok := false
46+
for _, v := range All.SupportedVersions() {
47+
if !ok && v == min {
48+
ok = true
49+
}
50+
if ok {
51+
out = append(out, v)
52+
}
53+
}
54+
return PluginSupports(out...)
55+
}
56+
4157
// Finds a Result object matching the requested version (if any) and asks
4258
// that object to parse the plugin result, returning an error if parsing failed.
4359
func NewResult(version string, resultBytes []byte) (types.Result, error) {

Diff for: pkg/version/version_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ import (
2828
)
2929

3030
var _ = Describe("Version operations", func() {
31+
It("computes a list of versions correctly", func() {
32+
actual := version.VersionsStartingFrom("0.3.1")
33+
Expect(actual.SupportedVersions()).To(Equal([]string{"0.3.1", "0.4.0", "1.0.0"}))
34+
})
35+
3136
Context("when a prevResult is available", func() {
3237
It("parses the prevResult", func() {
3338
rawBytes := []byte(`{

0 commit comments

Comments
 (0)