versioning: misc cleanups
highlights: - NetConf struct finally includes cniVersion field - improve test coverage of current version report behavior - godoc a few key functions - allow tests to control version list reported by no-op plugin
This commit is contained in:
@ -24,11 +24,17 @@ import (
|
||||
|
||||
// Debug is used to control and record the behavior of the noop plugin
|
||||
type Debug struct {
|
||||
ReportResult string
|
||||
ReportError string
|
||||
ReportStderr string
|
||||
Command string
|
||||
CmdArgs skel.CmdArgs
|
||||
// Report* fields allow the test to control the behavior of the no-op plugin
|
||||
ReportResult string
|
||||
ReportError string
|
||||
ReportStderr string
|
||||
ReportVersionSupport []string
|
||||
|
||||
// Command stores the CNI command that the plugin received
|
||||
Command string
|
||||
|
||||
// CmdArgs stores the CNI Args and Env Vars that the plugin recieved
|
||||
CmdArgs skel.CmdArgs
|
||||
}
|
||||
|
||||
// ReadDebug will return a debug file recorded by the noop plugin
|
||||
|
@ -63,6 +63,23 @@ func debugBehavior(args *skel.CmdArgs, command string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func debugGetSupportedVersions() []string {
|
||||
vers := []string{"0.-42.0", "0.1.0", "0.2.0", "0.3.0"}
|
||||
cniArgs := os.Getenv("CNI_ARGS")
|
||||
if cniArgs == "" {
|
||||
return vers
|
||||
}
|
||||
debugFilePath := strings.TrimPrefix(cniArgs, "DEBUG=")
|
||||
debug, err := debug.ReadDebug(debugFilePath)
|
||||
if err != nil {
|
||||
panic("test setup error: unable to read debug file: " + err.Error())
|
||||
}
|
||||
if debug.ReportVersionSupport == nil {
|
||||
return vers
|
||||
}
|
||||
return debug.ReportVersionSupport
|
||||
}
|
||||
|
||||
func cmdAdd(args *skel.CmdArgs) error {
|
||||
return debugBehavior(args, "ADD")
|
||||
}
|
||||
@ -72,6 +89,6 @@ func cmdDel(args *skel.CmdArgs) error {
|
||||
}
|
||||
|
||||
func main() {
|
||||
skel.PluginMain(cmdAdd, cmdDel,
|
||||
version.PluginSupports("0.-42.0", "0.1.0", "0.2.0", "0.3.0"))
|
||||
supportedVersions := debugGetSupportedVersions()
|
||||
skel.PluginMain(cmdAdd, cmdDel, version.PluginSupports(supportedVersions...))
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/containernetworking/cni/pkg/skel"
|
||||
"github.com/containernetworking/cni/pkg/version"
|
||||
noop_debug "github.com/containernetworking/cni/plugins/test/noop/debug"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
@ -38,7 +39,10 @@ var _ = Describe("No-op plugin", func() {
|
||||
const reportResult = `{ "ip4": { "ip": "10.1.2.3/24" }, "dns": {} }`
|
||||
|
||||
BeforeEach(func() {
|
||||
debug = &noop_debug.Debug{ReportResult: reportResult}
|
||||
debug = &noop_debug.Debug{
|
||||
ReportResult: reportResult,
|
||||
ReportVersionSupport: []string{"0.1.0", "0.2.0", "0.3.0"},
|
||||
}
|
||||
|
||||
debugFile, err := ioutil.TempFile("", "cni_debug")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
@ -122,6 +126,25 @@ var _ = Describe("No-op plugin", func() {
|
||||
Expect(debug.Command).To(Equal("DEL"))
|
||||
Expect(debug.CmdArgs).To(Equal(expectedCmdArgs))
|
||||
})
|
||||
})
|
||||
|
||||
Context("when the CNI_COMMAND is VERSION", func() {
|
||||
BeforeEach(func() {
|
||||
cmd.Env[0] = "CNI_COMMAND=VERSION"
|
||||
debug.ReportVersionSupport = []string{"0.123.0", "0.3.0"}
|
||||
|
||||
Expect(debug.WriteDebug(debugFileName)).To(Succeed())
|
||||
})
|
||||
|
||||
It("claims to support the specified versions", func() {
|
||||
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Eventually(session).Should(gexec.Exit(0))
|
||||
decoder := &version.PluginDecoder{}
|
||||
pluginInfo, err := decoder.Decode(session.Out.Contents())
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(pluginInfo.SupportedVersions()).To(ConsistOf(
|
||||
"0.123.0", "0.3.0"))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user