示例#1
0
		command = exec.Command(outPath, sourceDir)
		command.Stdin = stdin
	})

	AfterEach(func() {
		err := os.RemoveAll(sourceDir)
		Ω(err).ShouldNot(HaveOccurred())
	})

	JustBeforeEach(func() {
		var err error
		session, err = gexec.Start(command, GinkgoWriter, GinkgoWriter)
		Ω(err).ShouldNot(HaveOccurred())

		<-session.Exited
		Expect(session.ExitCode()).To(Equal(expectedExitStatus))
	})

	Context("with a versioned_file and a regex", func() {
		var outRequest out.OutRequest

		BeforeEach(func() {
			outRequest = out.OutRequest{
				Source: s3resource.Source{
					AccessKeyID:     accessKeyID,
					SecretAccessKey: secretAccessKey,
					Bucket:          versionedBucketName,
					RegionName:      regionName,
					Regexp:          "some-regex",
					VersionedFile:   "some-file",
					Endpoint:        endpoint,
		session *gexec.Session

		tmpDir  string
		tmpFile string
	)

	itExitsWithZero := func() {
		It("exits with a zero exit code", func() {
			Eventually(session).Should(gexec.Exit(0))
		})
	}

	itExitsWithNonZero := func() {
		It("exits with a non-zero exit code", func() {
			Eventually(session).Should(gexec.Exit())
			Expect(session.ExitCode()).NotTo(BeZero())
		})
	}

	itCallsStopApp := func() {
		It("calls stop app", func() {
			Eventually(session).Should(gexec.Exit())

			contents, err := ioutil.ReadFile(tmpFile)
			Expect(err).NotTo(HaveOccurred())
			Expect(strings.Count(string(contents), "stop_app -n rabbit@host\n")).To(Equal(1))
			Eventually(session.Out).Should(gbytes.Say("It looks like you are trying to upgrade"))
			Eventually(session.Out).Should(gbytes.Say("The cluster needs to be taken offline as it cannot run in mixed mode"))
			Eventually(session.Out).Should(gbytes.Say("Stopping RabbitMQ on rabbit@host"))
		})
	}
		return m
	}

	It("outputs a single cpu_load metric", func() {
		m := decodeJson(session)
		Expect(m.Key).To(Equal("cpu_load"))
		Expect(m.Unit).To(Equal("load"))
	})

	Context("when --config flag is not provided", func() {
		BeforeEach(func() {
			configPath = ""
		})

		It("exits with a non-zero exit code", func() {
			Expect(session.ExitCode()).ToNot(Equal(0))
		})

		It("outputs a meaningful error message", func() {
			Expect(session.Err).To(gbytes.Say("Missing flag --config"))
		})
	})

	Context("when redis config file does not exist", func() {
		BeforeEach(func() {
			configPath = "/path/to/nowhere"
		})

		It("exits with a non-zero exit code", func() {
			Expect(session.ExitCode()).ToNot(Equal(0))
		})
		BeforeEach(func() {
			cmdInput = `
{
    "version": 1,
    "serial": 5,
    "modules": [
        {
            "path": [
                "root"
            ],
            "outputs": {
                "foo_dns_name": "foo.example.com",
                "foo_elastic_ip": "10.210.221.248",
                "foo_security_group_id": "sg-12345678"
            },
			"resources": {},
			"depends_on": []
		}
	]
}
			`
		})

		It("Exits non-zero and outputs nothing on STDOUT", func() {
			Eventually(session).Should(gexec.Exit())
			Expect(session.ExitCode()).NotTo(Equal(0))
			Expect(session.Out.Contents()).To(BeEmpty())
		})
	})
})