Expect(versionInfo.SupportedVersions()).To(ConsistOf(expectedVersions.SupportedVersions()))
},
- Entry("old plugin, before VERSION was introduced", git_ref_v010, plugin_source_v010, version.PluginSupports("0.1.0")),
- Entry("when VERSION was introduced", git_ref_v020, plugin_source_v010, version.PluginSupports("0.1.0", "0.2.0")),
- Entry("when plugins report their own version support", git_ref_v030, plugin_source_v030, version.PluginSupports("0.3.0", "0.999.0")),
- Entry("HEAD", "HEAD", plugin_source_v030, version.PluginSupports("0.3.0", "0.999.0")),
+
+ Entry("historical: before VERSION was introduced",
+ git_ref_v010, plugin_source_no_custom_versions,
+ version.PluginSupports("0.1.0"),
+ ),
+
+ Entry("historical: when VERSION was introduced but plugins couldn't customize it",
+ git_ref_v020_no_custom_versions, plugin_source_no_custom_versions,
+ version.PluginSupports("0.1.0", "0.2.0"),
+ ),
+
+ Entry("historical: when plugins started reporting their own version list",
+ git_ref_v020_custom_versions, plugin_source_v020_custom_versions,
+ version.PluginSupports("0.2.0", "0.999.0"),
+ ),
+
+ // this entry tracks the current behavior. Before you change it, ensure
+ // that its previous behavior is captured in the most recent "historical" entry
+ Entry("current",
+ "HEAD", plugin_source_v020_custom_versions,
+ version.PluginSupports("0.2.0", "0.999.0"),
+ ),
)
})
-// a 0.3.0 plugin that can report its own versions
-const plugin_source_v030 = `package main
+// a 0.2.0 plugin that can report its own versions
+const plugin_source_v020_custom_versions = `package main
import (
"github.com/containernetworking/cni/pkg/skel"
func c(_ *skel.CmdArgs) error { fmt.Println("{}"); return nil }
-func main() { skel.PluginMain(c, c, version.PluginSupports("0.3.0", "0.999.0")) }
+func main() { skel.PluginMain(c, c, version.PluginSupports("0.2.0", "0.999.0")) }
`
-const git_ref_v030 = "bf31ed15"
+const git_ref_v020_custom_versions = "bf31ed15"
-// a minimal 0.1.0 / 0.2.0 plugin
-const plugin_source_v010 = `package main
+// a minimal 0.1.0 / 0.2.0 plugin that cannot report it's own version support
+const plugin_source_no_custom_versions = `package main
import "github.com/containernetworking/cni/pkg/skel"
import "fmt"
`
const git_ref_v010 = "2c482f4"
-const git_ref_v020 = "349d66d"
+const git_ref_v020_no_custom_versions = "349d66d"
Expect(err).NotTo(HaveOccurred())
Expect(stdout).To(MatchJSON(`{
- "cniVersion": "0.3.0",
+ "cniVersion": "0.2.0",
"supportedVersions": ["9.8.7"]
}`))
})
)
var _ = Describe("Decoding versions reported by a plugin", func() {
- var decoder *version.PluginDecoder
+ var (
+ decoder *version.PluginDecoder
+ versionStdout []byte
+ )
BeforeEach(func() {
decoder = &version.PluginDecoder{}
+ versionStdout = []byte(`{
+ "cniVersion": "some-library-version",
+ "supportedVersions": [ "some-version", "some-other-version" ]
+ }`)
})
It("returns a PluginInfo that represents the given json bytes", func() {
- pluginInfo, err := decoder.Decode([]byte(`{
- "cniVersion": "some-library-version",
- "supportedVersions": [ "some-version", "some-other-version" ]
- }`))
+ pluginInfo, err := decoder.Decode(versionStdout)
Expect(err).NotTo(HaveOccurred())
Expect(pluginInfo).NotTo(BeNil())
Expect(pluginInfo.SupportedVersions()).To(Equal([]string{
})
Context("when the bytes cannot be decoded as json", func() {
+ BeforeEach(func() {
+ versionStdout = []byte(`{{{`)
+ })
+
It("returns a meaningful error", func() {
- _, err := decoder.Decode([]byte(`{{{`))
+ _, err := decoder.Decode(versionStdout)
Expect(err).To(MatchError("decoding version info: invalid character '{' looking for beginning of object key string"))
})
})
Context("when the json bytes are missing the required CNIVersion field", func() {
+ BeforeEach(func() {
+ versionStdout = []byte(`{ "supportedVersions": [ "foo" ] }`)
+ })
+
It("returns a meaningful error", func() {
- _, err := decoder.Decode([]byte(`{ "supportedVersions": [ "foo" ] }`))
+ _, err := decoder.Decode(versionStdout)
Expect(err).To(MatchError("decoding version info: missing field cniVersion"))
})
})
Context("when there are no supported versions", func() {
- Context("when the cniVersion is 0.2.0", func() {
- It("infers the supported versions are 0.1.0 and 0.2.0", func() {
- pluginInfo, err := decoder.Decode([]byte(`{ "cniVersion": "0.2.0" }`))
- Expect(err).NotTo(HaveOccurred())
- Expect(pluginInfo).NotTo(BeNil())
- Expect(pluginInfo.SupportedVersions()).To(Equal([]string{
- "0.1.0",
- "0.2.0",
- }))
- })
+ BeforeEach(func() {
+ versionStdout = []byte(`{ "cniVersion": "0.2.0" }`)
})
- Context("when the cniVersion is >= 0.3.0", func() {
- It("returns a meaningful error", func() {
- _, err := decoder.Decode([]byte(`{ "cniVersion": "0.3.0" }`))
- Expect(err).To(MatchError("decoding version info: missing field supportedVersions"))
- })
+ It("assumes that the supported versions are 0.1.0 and 0.2.0", func() {
+ pluginInfo, err := decoder.Decode(versionStdout)
+ Expect(err).NotTo(HaveOccurred())
+ Expect(pluginInfo).NotTo(BeNil())
+ Expect(pluginInfo.SupportedVersions()).To(Equal([]string{
+ "0.1.0",
+ "0.2.0",
+ }))
})
})
// Current reports the version of the CNI spec implemented by this library
func Current() string {
- return "0.3.0"
+ return "0.2.0"
}
// Legacy PluginInfo describes a plugin that is backwards compatible with the
// library ought to work correctly with a plugin that reports support for
// Legacy versions.
//
-// Any future CNI spec versions which meet this definition will be added to
+// Any future CNI spec versions which meet this definition should be added to
// this list.
-var Legacy = PluginSupports("0.1.0", "0.2.0", "0.3.0")
+var Legacy = PluginSupports("0.1.0", "0.2.0")