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:
Dan Williams
2016-12-16 13:53:51 -06:00
parent 530dd71e19
commit 0a1b48f520
2 changed files with 106 additions and 14 deletions

View File

@ -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())