Skip to content

Commit

Permalink
Merge pull request #858 from squeed/version-from
Browse files Browse the repository at this point in the history
pkg/version: add VersionsFrom function
  • Loading branch information
dcbw authored Sep 7, 2021
2 parents 5608690 + c7f5f70 commit 1694fd7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
18 changes: 17 additions & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"fmt"

"github.com/containernetworking/cni/pkg/types"
"github.com/containernetworking/cni/pkg/types/100"
types100 "github.com/containernetworking/cni/pkg/types/100"
"github.com/containernetworking/cni/pkg/types/create"
)

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

// VersionsFrom returns a list of versions starting from min, inclusive
func VersionsStartingFrom(min string) PluginInfo {
out := []string{}
// cheat, just assume ordered
ok := false
for _, v := range All.SupportedVersions() {
if !ok && v == min {
ok = true
}
if ok {
out = append(out, v)
}
}
return PluginSupports(out...)
}

// Finds a Result object matching the requested version (if any) and asks
// that object to parse the plugin result, returning an error if parsing failed.
func NewResult(version string, resultBytes []byte) (types.Result, error) {
Expand Down
5 changes: 5 additions & 0 deletions pkg/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ import (
)

var _ = Describe("Version operations", func() {
It("computes a list of versions correctly", func() {
actual := version.VersionsStartingFrom("0.3.1")
Expect(actual.SupportedVersions()).To(Equal([]string{"0.3.1", "0.4.0", "1.0.0"}))
})

Context("when a prevResult is available", func() {
It("parses the prevResult", func() {
rawBytes := []byte(`{
Expand Down

0 comments on commit 1694fd7

Please sign in to comment.