-
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.
Remove local command and move diagnostic and setup back
- Loading branch information
Zachary Scott
committed
Aug 2, 2018
1 parent
19f60ac
commit dc10296
Showing
8 changed files
with
304 additions
and
290 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,35 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func newDiagnosticCommand() *cobra.Command { | ||
diagnosticCommand := &cobra.Command{ | ||
Use: "diagnostic", | ||
Short: "Check the status of your CircleCI CLI.", | ||
RunE: diagnostic, | ||
} | ||
|
||
return diagnosticCommand | ||
} | ||
|
||
func diagnostic(cmd *cobra.Command, args []string) error { | ||
endpoint := viper.GetString("endpoint") | ||
token := viper.GetString("token") | ||
|
||
Logger.Infoln("\n---\nCircleCI CLI Diagnostics\n---\n") | ||
Logger.Infof("Config found: %v\n", viper.ConfigFileUsed()) | ||
|
||
Logger.Infof("GraphQL API endpoint: %s\n", endpoint) | ||
|
||
if token == "token" || token == "" { | ||
return errors.New("please set a token") | ||
} | ||
Logger.Infoln("OK, got a token.") | ||
Logger.Infof("Verbose mode: %v\n", viper.GetBool("verbose")) | ||
|
||
return nil | ||
} |
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,96 @@ | ||
package cmd_test | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"github.com/onsi/gomega/gbytes" | ||
"github.com/onsi/gomega/gexec" | ||
) | ||
|
||
var _ = Describe("Diagnostic", func() { | ||
var ( | ||
tempHome string | ||
command *exec.Cmd | ||
) | ||
|
||
BeforeEach(func() { | ||
var err error | ||
tempHome, err = ioutil.TempDir("", "circleci-cli-test-") | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
command = exec.Command(pathCLI, "diagnostic") | ||
command.Env = append(os.Environ(), | ||
fmt.Sprintf("HOME=%s", tempHome), | ||
) | ||
}) | ||
|
||
AfterEach(func() { | ||
Expect(os.RemoveAll(tempHome)).To(Succeed()) | ||
}) | ||
|
||
Describe("existing config file", func() { | ||
var config *os.File | ||
|
||
BeforeEach(func() { | ||
const ( | ||
configDir = ".circleci" | ||
configFile = "cli.yml" | ||
) | ||
|
||
Expect(os.Mkdir(filepath.Join(tempHome, configDir), 0700)).To(Succeed()) | ||
|
||
var err error | ||
config, err = os.OpenFile( | ||
filepath.Join(tempHome, configDir, configFile), | ||
os.O_RDWR|os.O_CREATE, | ||
0600, | ||
) | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
|
||
Describe("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 set to empty string in config file", func() { | ||
BeforeEach(func() { | ||
_, err := config.Write([]byte(` | ||
endpoint: https://example.com/graphql | ||
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("Error: please set a token")) | ||
Eventually(session.Out).Should(gbytes.Say("GraphQL API endpoint: https://example.com/graphql")) | ||
Eventually(session).Should(gexec.Exit(255)) | ||
}) | ||
}) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.