From 49fd151ee37cd8c1928c7f5ceba87c26a47e5f9d Mon Sep 17 00:00:00 2001 From: Ryan SVIHLA Date: Tue, 4 May 2021 13:48:37 +0200 Subject: [PATCH] fixed login error (#17) * 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 --- cmd/login.go | 4 ++-- cmd/login_test.go | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/login.go b/cmd/login.go index 361f4b3..de9a721 100644 --- a/cmd/login.go +++ b/cmd/login.go @@ -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) } @@ -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 } diff --git a/cmd/login_test.go b/cmd/login_test.go index ce64fe0..5712bdf 100644 --- a/cmd/login_test.go +++ b/cmd/login_test.go @@ -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 {