提交 f5bebe6f 编写于 作者: LinuxSuRen's avatar LinuxSuRen

Decrease duplicate codes

上级 536d8f8e
...@@ -11,13 +11,17 @@ import ( ...@@ -11,13 +11,17 @@ import (
var _ = Describe("Root cmd test", func() { var _ = Describe("Root cmd test", func() {
var ( var (
ctrl *gomock.Controller ctrl *gomock.Controller
rootCmd *cobra.Command rootCmd *cobra.Command
successCmd string
errorCmd string
) )
BeforeEach(func() { BeforeEach(func() {
ctrl = gomock.NewController(GinkgoT()) ctrl = gomock.NewController(GinkgoT())
rootCmd = &cobra.Command{Use: "root"} rootCmd = &cobra.Command{Use: "root"}
successCmd = "echo 1"
errorCmd = "exit 1"
}) })
AfterEach(func() { AfterEach(func() {
...@@ -58,7 +62,7 @@ var _ = Describe("Root cmd test", func() { ...@@ -58,7 +62,7 @@ var _ = Describe("Root cmd test", func() {
Context("execute cmd test", func() { Context("execute cmd test", func() {
It("basic command", func() { It("basic command", func() {
var buf bytes.Buffer var buf bytes.Buffer
err := execute("echo 1", &buf) err := execute(successCmd, &buf)
Expect(buf.String()).To(Equal("1\n")) Expect(buf.String()).To(Equal("1\n"))
Expect(err).To(BeNil()) Expect(err).To(BeNil())
...@@ -66,7 +70,7 @@ var _ = Describe("Root cmd test", func() { ...@@ -66,7 +70,7 @@ var _ = Describe("Root cmd test", func() {
It("error command", func() { It("error command", func() {
var buf bytes.Buffer var buf bytes.Buffer
err := execute("exit 1", &buf) err := execute(errorCmd, &buf)
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
}) })
...@@ -82,7 +86,7 @@ var _ = Describe("Root cmd test", func() { ...@@ -82,7 +86,7 @@ var _ = Describe("Root cmd test", func() {
config = &Config{ config = &Config{
PreHooks: []PreHook{PreHook{ PreHooks: []PreHook{PreHook{
Path: "test", Path: "test",
Command: "echo 1", Command: successCmd,
}}, }},
} }
...@@ -102,13 +106,13 @@ var _ = Describe("Root cmd test", func() { ...@@ -102,13 +106,13 @@ var _ = Describe("Root cmd test", func() {
config = &Config{ config = &Config{
PreHooks: []PreHook{PreHook{ PreHooks: []PreHook{PreHook{
Path: "test", Path: "test",
Command: "echo 1", Command: successCmd,
}, PreHook{ }, PreHook{
Path: "test", Path: "test",
Command: "echo 2", Command: "echo 2",
}, PreHook{ }, PreHook{
Path: "fake", Path: "fake",
Command: "echo 1", Command: successCmd,
}}, }},
} }
...@@ -143,7 +147,7 @@ var _ = Describe("Root cmd test", func() { ...@@ -143,7 +147,7 @@ var _ = Describe("Root cmd test", func() {
config = &Config{ config = &Config{
PreHooks: []PreHook{PreHook{ PreHooks: []PreHook{PreHook{
Path: "test", Path: "test",
Command: "exit 1", Command: errorCmd,
}}, }},
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册