Skip to content

Commit

Permalink
fixed login error (#17)
Browse files Browse the repository at this point in the history
* login command was always displaying help
* display where the login file was saved
* updated tests to look for client id, client name, token, and client secret flags being set instead of total argument
  • Loading branch information
foundev authored May 4, 2021
1 parent 69423c5 commit 49fd151
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var loginCmd = &cobra.Command{
}

func executeLogin(args []string, getHome func() (string, pkg.ConfFiles, error), usageFunc func() error) (int, error) {
if len(args) == 0 {
if clientJSON == "" && clientID == "" && clientName == "" && clientSecret == "" && authToken == "" {
if err := usageFunc(); err != nil {
return CriticalError, fmt.Errorf("cannot show usage %v", err)
}
Expand Down Expand Up @@ -163,6 +163,6 @@ func makeConf(confDir, confFile, content string) error {
if err != nil {
return fmt.Errorf("error finishing file")
}
fmt.Println("Login information saved")
fmt.Printf("Login information saved at %v\n", confFile)
return nil
}
7 changes: 5 additions & 2 deletions cmd/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,14 @@ func TestLoginArgsMissingSecret(t *testing.T) {
}

func TestLoginHomeError(t *testing.T) {
exitCode, err := executeLogin([]string{"--json", clientJSON}, func() (string, pkg.ConfFiles, error) {
clientJSON = "invalidjson"
defer func() { clientJSON = "" }()
exitCode, err := executeLogin([]string{}, func() (string, pkg.ConfFiles, error) {
return "", pkg.ConfFiles{}, fmt.Errorf("big error")
}, usageFunc)
if err == nil {
t.Error("expected error")
t.Logf("expected error there was none and exit code was %v", exitCode)
t.FailNow()
}
expected := "big error"
if err.Error() != expected {
Expand Down

0 comments on commit 49fd151

Please sign in to comment.