-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't currently work because `-c` doesn't seem to be honoured.
- Loading branch information
Showing
1 changed file
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package cmd_test | ||
|
||
import ( | ||
"bytes" | ||
"io/ioutil" | ||
"os" | ||
"os/exec" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"github.com/onsi/gomega/gbytes" | ||
"github.com/onsi/gomega/gexec" | ||
) | ||
|
||
var _ = Describe("Diagnostic", func() { | ||
var ( | ||
config *os.File | ||
command *exec.Cmd | ||
) | ||
|
||
BeforeEach(func() { | ||
var err error | ||
config, err = ioutil.TempFile("", "cmd_test") | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
command = exec.Command(pathCLI, "-c", config.Name(), "diagnostic") | ||
}) | ||
|
||
AfterEach(func() { | ||
Expect(os.Remove(config.Name())).To(Succeed()) | ||
}) | ||
|
||
Context("token and endpoint set in config file", func() { | ||
BeforeEach(func() { | ||
_, err := config.Write([]byte(` | ||
endpoint: https://example.com/graphql | ||
token: mytoken | ||
`)) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(config.Close()).To(Succeed()) | ||
}) | ||
|
||
It("print success", func() { | ||
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
Eventually(session.Err.Contents()).Should(BeEmpty()) | ||
Eventually(session.Out).Should(gbytes.Say("GraphQL API endpoint: https://example.com/graphql")) | ||
Eventually(session.Out).Should(gbytes.Say("OK, got a token.")) | ||
Eventually(session).Should(gexec.Exit(0)) | ||
}) | ||
}) | ||
|
||
Context("token not set in config file", func() { | ||
BeforeEach(func() { | ||
_, err := config.Write([]byte(` | ||
endpoint: https://example.com | ||
`)) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(config.Close()).To(Succeed()) | ||
|
||
var stdin bytes.Buffer | ||
stdin.Write([]byte(`mytoken`)) | ||
command.Stdin = &stdin | ||
}) | ||
|
||
It("prompt for token and print success", func() { | ||
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
Eventually(session.Err.Contents()).Should(BeEmpty()) | ||
Eventually(session.Out).Should(gbytes.Say("Please enter your CircleCI API token:")) | ||
Eventually(session.Out).Should(gbytes.Say("OK, got a token.")) | ||
Eventually(session).Should(gexec.Exit(0)) | ||
}) | ||
}) | ||
|
||
Context("token set to empty string in config file", func() { | ||
BeforeEach(func() { | ||
_, err := config.Write([]byte(` | ||
endpoint: https://example.com | ||
token: | ||
`)) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(config.Close()).To(Succeed()) | ||
}) | ||
|
||
It("print error", func() { | ||
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
Eventually(session.Err).Should(gbytes.Say("Please set a token!")) | ||
Eventually(session).Should(gexec.Exit(1)) | ||
}) | ||
}) | ||
}) |