Merge pull request #314 from rosenhouse/noop-helpful-message
plugins/noop: return a helpful message for test authors
This commit is contained in:
commit
652bae1deb
@ -22,6 +22,8 @@ import (
|
|||||||
"github.com/containernetworking/cni/pkg/skel"
|
"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
|
// Debug is used to control and record the behavior of the noop plugin
|
||||||
type Debug struct {
|
type Debug struct {
|
||||||
// Report* fields allow the test to control the behavior of the no-op plugin
|
// Report* fields allow the test to control the behavior of the no-op plugin
|
||||||
|
@ -29,7 +29,7 @@ import (
|
|||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/skel"
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
"github.com/containernetworking/cni/pkg/version"
|
"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
|
// parse extra args i.e. FOO=BAR;ABC=123
|
||||||
@ -60,7 +60,7 @@ func debugBehavior(args *skel.CmdArgs, command string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
debug, err := debug.ReadDebug(debugFilePath)
|
debug, err := noop_debug.ReadDebug(debugFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -68,6 +68,10 @@ func debugBehavior(args *skel.CmdArgs, command string) error {
|
|||||||
debug.CmdArgs = *args
|
debug.CmdArgs = *args
|
||||||
debug.Command = command
|
debug.Command = command
|
||||||
|
|
||||||
|
if debug.ReportResult == "" {
|
||||||
|
debug.ReportResult = fmt.Sprintf(` { "result": %q }`, noop_debug.EmptyReportResultMessage)
|
||||||
|
}
|
||||||
|
|
||||||
err = debug.WriteDebug(debugFilePath)
|
err = debug.WriteDebug(debugFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -101,7 +105,7 @@ func debugGetSupportedVersions() []string {
|
|||||||
panic("test setup error: missing DEBUG in CNI_ARGS")
|
panic("test setup error: missing DEBUG in CNI_ARGS")
|
||||||
}
|
}
|
||||||
|
|
||||||
debug, err := debug.ReadDebug(debugFilePath)
|
debug, err := noop_debug.ReadDebug(debugFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("test setup error: unable to read debug file: " + err.Error())
|
panic("test setup error: unable to read debug file: " + err.Error())
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,26 @@ var _ = Describe("No-op plugin", func() {
|
|||||||
Expect(debug.CmdArgs).To(Equal(expectedCmdArgs))
|
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() {
|
Context("when the ReportError debug field is set", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
debug.ReportError = "banana"
|
debug.ReportError = "banana"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user