plugin_open_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
package cmd

import (
	"fmt"
	"github.com/jenkins-zh/jenkins-cli/util"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"gopkg.in/yaml.v2"
	"io/ioutil"
	"os"
)

var _ = Describe("plugin open test", func() {
	var (
		err error
	)

	BeforeEach(func() {
		pluginOpenOption.ExecContext = util.FakeExecCommandSuccess
LinuxSuRen's avatar
LinuxSuRen 已提交
20
		data, err := GenerateSampleConfig()
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
		Expect(err).To(BeNil())
		rootOptions.ConfigFile = "test.yaml"
		err = ioutil.WriteFile(rootOptions.ConfigFile, data, 0664)
		Expect(err).To(BeNil())
	})

	JustBeforeEach(func() {
		rootCmd.SetArgs([]string{"plugin", "open"})
		_, err = rootCmd.ExecuteC()
	})

	AfterEach(func() {
		os.Remove(rootOptions.ConfigFile)
	})

	It("should success", func() {
		Expect(err).NotTo(HaveOccurred())
	})

	Context("without url", func() {
		BeforeEach(func() {
			pluginOpenOption.ExecContext = util.FakeExecCommandSuccess
			sampleConfig := getSampleConfig()
			sampleConfig.JenkinsServers[0].URL = ""
			data, err := yaml.Marshal(&sampleConfig)
			Expect(err).To(BeNil())
			err = ioutil.WriteFile(rootOptions.ConfigFile, data, 0664)
			Expect(err).To(BeNil())
		})

		It("should failure", func() {
			Expect(err).To(HaveOccurred())
			Expect(fmt.Sprint(err)).To(ContainSubstring("no URL fond from"))
		})
	})
})