diff --git a/plugins/test/noop/debug/debug.go b/plugins/test/noop/debug/debug.go index 5bc6e4f0..f400800f 100644 --- a/plugins/test/noop/debug/debug.go +++ b/plugins/test/noop/debug/debug.go @@ -22,6 +22,8 @@ import ( "github.com/containernetworking/cni/pkg/skel" ) +const EmptyReportResultMessage = "set debug.ReportResult and call debug.WriteDebug() before calling this plugin" + // Debug is used to control and record the behavior of the noop plugin type Debug struct { // Report* fields allow the test to control the behavior of the no-op plugin diff --git a/plugins/test/noop/main.go b/plugins/test/noop/main.go index fe67c377..2f4dc357 100644 --- a/plugins/test/noop/main.go +++ b/plugins/test/noop/main.go @@ -29,7 +29,7 @@ import ( "github.com/containernetworking/cni/pkg/skel" "github.com/containernetworking/cni/pkg/version" - "github.com/containernetworking/cni/plugins/test/noop/debug" + noop_debug "github.com/containernetworking/cni/plugins/test/noop/debug" ) // parse extra args i.e. FOO=BAR;ABC=123 @@ -60,7 +60,7 @@ func debugBehavior(args *skel.CmdArgs, command string) error { return nil } - debug, err := debug.ReadDebug(debugFilePath) + debug, err := noop_debug.ReadDebug(debugFilePath) if err != nil { return err } @@ -68,6 +68,10 @@ func debugBehavior(args *skel.CmdArgs, command string) error { debug.CmdArgs = *args debug.Command = command + if debug.ReportResult == "" { + debug.ReportResult = fmt.Sprintf(` { "result": %q }`, noop_debug.EmptyReportResultMessage) + } + err = debug.WriteDebug(debugFilePath) if err != nil { return err @@ -101,7 +105,7 @@ func debugGetSupportedVersions() []string { panic("test setup error: missing DEBUG in CNI_ARGS") } - debug, err := debug.ReadDebug(debugFilePath) + debug, err := noop_debug.ReadDebug(debugFilePath) if err != nil { panic("test setup error: unable to read debug file: " + err.Error()) } diff --git a/plugins/test/noop/noop_test.go b/plugins/test/noop/noop_test.go index 49e86161..c241e631 100644 --- a/plugins/test/noop/noop_test.go +++ b/plugins/test/noop/noop_test.go @@ -96,6 +96,26 @@ var _ = Describe("No-op plugin", func() { Expect(debug.CmdArgs).To(Equal(expectedCmdArgs)) }) + Context("when the ReportResult debug field is empty", func() { + BeforeEach(func() { + debug.ReportResult = "" + Expect(debug.WriteDebug(debugFileName)).To(Succeed()) + }) + + It("substitutes a helpful message for the test author", func() { + expectedResultString := fmt.Sprintf(` { "result": %q }`, noop_debug.EmptyReportResultMessage) + + session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter) + Expect(err).NotTo(HaveOccurred()) + Eventually(session).Should(gexec.Exit(0)) + Expect(session.Out.Contents()).To(MatchJSON(expectedResultString)) + + debug, err := noop_debug.ReadDebug(debugFileName) + Expect(err).NotTo(HaveOccurred()) + Expect(debug.ReportResult).To(MatchJSON(expectedResultString)) + }) + }) + Context("when the ReportError debug field is set", func() { BeforeEach(func() { debug.ReportError = "banana"