invoke: better name and unit test coverage for GetVersionInfo
This commit is contained in:
parent
97192fc979
commit
bf31ed1591
@ -67,7 +67,7 @@ func (c *CNIConfig) GetVersionInfo(pluginType string) (version.PluginInfo, error
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return invoke.ExecPluginForVersion(pluginPath)
|
return invoke.GetVersionInfo(pluginPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// =====
|
// =====
|
||||||
|
@ -30,8 +30,8 @@ func ExecPluginWithoutResult(pluginPath string, netconf []byte, args CNIArgs) er
|
|||||||
return defaultPluginExec.WithoutResult(pluginPath, netconf, args)
|
return defaultPluginExec.WithoutResult(pluginPath, netconf, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExecPluginForVersion(pluginPath string) (version.PluginInfo, error) {
|
func GetVersionInfo(pluginPath string) (version.PluginInfo, error) {
|
||||||
return defaultPluginExec.GetVersion(pluginPath)
|
return defaultPluginExec.GetVersionInfo(pluginPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultPluginExec = &PluginExec{
|
var defaultPluginExec = &PluginExec{
|
||||||
@ -64,14 +64,14 @@ func (e *PluginExec) WithoutResult(pluginPath string, netconf []byte, args CNIAr
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *PluginExec) GetVersion(pluginPath string) (version.PluginInfo, error) {
|
func (e *PluginExec) GetVersionInfo(pluginPath string) (version.PluginInfo, error) {
|
||||||
args := &Args{
|
args := &Args{
|
||||||
Command: "VERSION",
|
Command: "VERSION",
|
||||||
|
|
||||||
// set fake values required by plugins built against an older version of skel
|
// set fake values required by plugins built against an older version of skel
|
||||||
NetNS: "/tmp/not/a/container",
|
NetNS: "dummy",
|
||||||
IfName: "not-an-interface",
|
IfName: "dummy",
|
||||||
Path: "/tmp/not/a/path",
|
Path: "dummy",
|
||||||
}
|
}
|
||||||
stdoutBytes, err := e.RawExec.ExecPlugin(pluginPath, nil, args.AsEnv())
|
stdoutBytes, err := e.RawExec.ExecPlugin(pluginPath, nil, args.AsEnv())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -47,7 +47,7 @@ var _ = Describe("GetVersion, integration tests", func() {
|
|||||||
DescribeTable("correctly reporting plugin versions",
|
DescribeTable("correctly reporting plugin versions",
|
||||||
func(gitRef string, pluginSource string, expectedVersions version.PluginInfo) {
|
func(gitRef string, pluginSource string, expectedVersions version.PluginInfo) {
|
||||||
Expect(testhelpers.BuildAt([]byte(pluginSource), gitRef, pluginPath)).To(Succeed())
|
Expect(testhelpers.BuildAt([]byte(pluginSource), gitRef, pluginPath)).To(Succeed())
|
||||||
versionInfo, err := invoke.ExecPluginForVersion(pluginPath)
|
versionInfo, err := invoke.GetVersionInfo(pluginPath)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
Expect(versionInfo.SupportedVersions()).To(ConsistOf(expectedVersions.SupportedVersions()))
|
Expect(versionInfo.SupportedVersions()).To(ConsistOf(expectedVersions.SupportedVersions()))
|
||||||
|
@ -103,14 +103,14 @@ var _ = Describe("Executing a plugin, unit tests", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("execs the plugin with the command VERSION", func() {
|
It("execs the plugin with the command VERSION", func() {
|
||||||
pluginExec.GetVersion(pluginPath)
|
pluginExec.GetVersionInfo(pluginPath)
|
||||||
Expect(rawExec.ExecPluginCall.Received.PluginPath).To(Equal(pluginPath))
|
Expect(rawExec.ExecPluginCall.Received.PluginPath).To(Equal(pluginPath))
|
||||||
Expect(rawExec.ExecPluginCall.Received.StdinData).To(BeNil())
|
Expect(rawExec.ExecPluginCall.Received.StdinData).To(BeNil())
|
||||||
Expect(rawExec.ExecPluginCall.Received.Environ).To(ContainElement("CNI_COMMAND=VERSION"))
|
Expect(rawExec.ExecPluginCall.Received.Environ).To(ContainElement("CNI_COMMAND=VERSION"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("decodes and returns the version info", func() {
|
It("decodes and returns the version info", func() {
|
||||||
versionInfo, err := pluginExec.GetVersion(pluginPath)
|
versionInfo, err := pluginExec.GetVersionInfo(pluginPath)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(versionInfo.SupportedVersions()).To(Equal([]string{"0.42.0"}))
|
Expect(versionInfo.SupportedVersions()).To(Equal([]string{"0.42.0"}))
|
||||||
Expect(versionDecoder.DecodeCall.Received.JSONBytes).To(MatchJSON(`{ "some": "version-info" }`))
|
Expect(versionDecoder.DecodeCall.Received.JSONBytes).To(MatchJSON(`{ "some": "version-info" }`))
|
||||||
@ -121,9 +121,31 @@ var _ = Describe("Executing a plugin, unit tests", func() {
|
|||||||
rawExec.ExecPluginCall.Returns.Error = errors.New("banana")
|
rawExec.ExecPluginCall.Returns.Error = errors.New("banana")
|
||||||
})
|
})
|
||||||
It("returns the error", func() {
|
It("returns the error", func() {
|
||||||
_, err := pluginExec.GetVersion(pluginPath)
|
_, err := pluginExec.GetVersionInfo(pluginPath)
|
||||||
Expect(err).To(MatchError("banana"))
|
Expect(err).To(MatchError("banana"))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Context("when the plugin is too old to recognize the VERSION command", func() {
|
||||||
|
BeforeEach(func() {
|
||||||
|
rawExec.ExecPluginCall.Returns.Error = errors.New("unknown CNI_COMMAND: VERSION")
|
||||||
|
})
|
||||||
|
|
||||||
|
It("interprets the error as a 0.1.0 version", func() {
|
||||||
|
versionInfo, err := pluginExec.GetVersionInfo(pluginPath)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(versionInfo.SupportedVersions()).To(ConsistOf("0.1.0"))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("sets dummy values for env vars required by very old plugins", func() {
|
||||||
|
pluginExec.GetVersionInfo(pluginPath)
|
||||||
|
|
||||||
|
env := rawExec.ExecPluginCall.Received.Environ
|
||||||
|
Expect(env).To(ContainElement("CNI_NETNS=dummy"))
|
||||||
|
Expect(env).To(ContainElement("CNI_IFNAME=dummy"))
|
||||||
|
Expect(env).To(ContainElement("CNI_PATH=dummy"))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user