示例#1
0
文件: noop_test.go 项目: achanda/cni
	})

	It("records all the args provided by skel.PluginMain", func() {
		session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
		Expect(err).NotTo(HaveOccurred())
		Eventually(session).Should(gexec.Exit(0))

		debug, err := noop_debug.ReadDebug(debugFileName)
		Expect(err).NotTo(HaveOccurred())
		Expect(debug.Command).To(Equal("ADD"))
		Expect(debug.CmdArgs).To(Equal(expectedCmdArgs))
	})

	Context("when the ReportError debug field is set", func() {
		BeforeEach(func() {
			debug.ReportError = "banana"
			Expect(debug.WriteDebug(debugFileName)).To(Succeed())
		})

		It("returns an error to skel.PluginMain, causing the process to exit code 1", func() {
			session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
			Expect(err).NotTo(HaveOccurred())
			Eventually(session).Should(gexec.Exit(1))
			Expect(session.Out.Contents()).To(MatchJSON(`{ "code": 100, "msg": "banana" }`))
		})
	})

	Context("when the CNI_COMMAND is DEL", func() {
		BeforeEach(func() {
			cmd.Env[0] = "CNI_COMMAND=DEL"
			debug.ReportResult = `{ "some": "delete-data" }`
示例#2
0
文件: api_test.go 项目: tomdee/cni
		})

		Context("when finding the plugin fails", func() {
			BeforeEach(func() {
				netConfig.Network.Type = "does-not-exist"
			})

			It("returns the error", func() {
				_, err := cniConfig.AddNetwork(netConfig, runtimeConfig)
				Expect(err).To(MatchError(ContainSubstring(`failed to find plugin "does-not-exist"`)))
			})
		})

		Context("when the plugin errors", func() {
			BeforeEach(func() {
				debug.ReportError = "plugin error: banana"
				Expect(debug.WriteDebug(debugFilePath)).To(Succeed())
			})
			It("unmarshals and returns the error", func() {
				result, err := cniConfig.AddNetwork(netConfig, runtimeConfig)
				Expect(result).To(BeNil())
				Expect(err).To(MatchError("plugin error: banana"))
			})
		})
	})

	Describe("DelNetwork", func() {
		It("executes the plugin with command DEL", func() {
			err := cniConfig.DelNetwork(netConfig, runtimeConfig)
			Expect(err).NotTo(HaveOccurred())