noop: allow specifying debug file in config JSON
Chaining sends different config JSON to each plugin, but the same environment, and if we want to test multiple noop plugin runs in the same chain we need a way of telling each run to use a different debug file.
This commit is contained in:
@ -58,10 +58,11 @@ var _ = Describe("No-op plugin", func() {
|
||||
cmd.Env = []string{
|
||||
"CNI_COMMAND=ADD",
|
||||
"CNI_CONTAINERID=some-container-id",
|
||||
"CNI_ARGS=" + args,
|
||||
"CNI_NETNS=/some/netns/path",
|
||||
"CNI_IFNAME=some-eth0",
|
||||
"CNI_PATH=/some/bin/path",
|
||||
// Keep this last
|
||||
"CNI_ARGS=" + args,
|
||||
}
|
||||
cmd.Stdin = strings.NewReader(`{"some":"stdin-json", "cniVersion": "0.2.0"}`)
|
||||
expectedCmdArgs = skel.CmdArgs{
|
||||
@ -85,6 +86,36 @@ var _ = Describe("No-op plugin", func() {
|
||||
Expect(session.Out.Contents()).To(MatchJSON(reportResult))
|
||||
})
|
||||
|
||||
It("panics when no debug file is given", func() {
|
||||
// Remove the DEBUG option from CNI_ARGS and regular args
|
||||
cmd.Env[len(cmd.Env)-1] = "CNI_ARGS=FOO=BAR"
|
||||
expectedCmdArgs.Args = "FOO=BAR"
|
||||
|
||||
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Eventually(session).Should(gexec.Exit(2))
|
||||
})
|
||||
|
||||
It("allows passing debug file in config JSON", func() {
|
||||
// Remove the DEBUG option from CNI_ARGS and regular args
|
||||
newArgs := "FOO=BAR"
|
||||
cmd.Env[len(cmd.Env)-1] = "CNI_ARGS=" + newArgs
|
||||
newStdin := fmt.Sprintf(`{"some":"stdin-json", "cniVersion": "0.2.0", "debugFile": "%s"}`, debugFileName)
|
||||
cmd.Stdin = strings.NewReader(newStdin)
|
||||
expectedCmdArgs.Args = newArgs
|
||||
expectedCmdArgs.StdinData = []byte(newStdin)
|
||||
|
||||
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Eventually(session).Should(gexec.Exit(0))
|
||||
Expect(session.Out.Contents()).To(MatchJSON(reportResult))
|
||||
|
||||
debug, err := noop_debug.ReadDebug(debugFileName)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(debug.Command).To(Equal("ADD"))
|
||||
Expect(debug.CmdArgs).To(Equal(expectedCmdArgs))
|
||||
})
|
||||
|
||||
It("records all the args provided by skel.PluginMain", func() {
|
||||
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
Reference in New Issue
Block a user