shell_test.go 1.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
package cmd

import (
	"github.com/jenkins-zh/jenkins-cli/util"
	"io/ioutil"
	"os"

	"github.com/golang/mock/gomock"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("shell command", func() {
	var (
		ctrl *gomock.Controller
	)

	BeforeEach(func() {
		ctrl = gomock.NewController(GinkgoT())
		rootCmd.SetArgs([]string{})
		rootOptions.Jenkins = ""
LinuxSuRen's avatar
LinuxSuRen 已提交
22 23 24 25 26

		tempFile, err := ioutil.TempFile("", "example")
		Expect(err).To(BeNil())

		rootOptions.ConfigFile = tempFile.Name()
27 28 29 30 31 32 33 34 35 36
		shellOptions.ExecContext = util.FakeExecCommandSuccess
	})

	AfterEach(func() {
		rootCmd.SetArgs([]string{})
		os.Remove(rootOptions.ConfigFile)
		rootOptions.ConfigFile = ""
		ctrl.Finish()
	})

37 38
	//Context("basic test", func() {
	//	It("should success", func() {
LinuxSuRen's avatar
LinuxSuRen 已提交
39
	//		data, err := GenerateSampleConfig()
40 41 42 43 44 45 46 47 48 49 50 51 52 53
	//		Expect(err).To(BeNil())
	//		err = ioutil.WriteFile(rootOptions.ConfigFile, data, 0664)
	//		Expect(err).To(BeNil())
	//
	//		rootCmd.SetArgs([]string{"shell", "yourServer"})
	//
	//		buf := new(bytes.Buffer)
	//		rootCmd.SetOutput(buf)
	//		_, err = rootCmd.ExecuteC()
	//		Expect(err).To(BeNil())
	//
	//		Expect(buf.String()).To(ContainSubstring("testing: warning: no tests to run\nPASS\n"))
	//	})
	//})
54
})