From 69c02b9b8a44ebd8f9a28ee9a2063722c68b23c6 Mon Sep 17 00:00:00 2001 From: rajhawaldar Date: Tue, 6 Jun 2023 23:30:16 +0530 Subject: [PATCH 1/3] update gh auth status to write to stdout on success --- pkg/cmd/auth/status/status.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/pkg/cmd/auth/status/status.go b/pkg/cmd/auth/status/status.go index 8070fe9ae..51d7b2c7d 100644 --- a/pkg/cmd/auth/status/status.go +++ b/pkg/cmd/auth/status/status.go @@ -66,7 +66,7 @@ func statusRun(opts *StatusOptions) error { // TODO check tty stderr := opts.IO.ErrOut - + stdout := opts.IO.Out cs := opts.IO.ColorScheme() statusInfo := map[string][]string{} @@ -166,13 +166,22 @@ func statusRun(opts *StatusOptions) error { if !ok { continue } - if prevEntry { + if prevEntry && failed { fmt.Fprint(stderr, "\n") + } else if prevEntry && failed == false { + fmt.Fprint(stdout, "\n") } prevEntry = true - fmt.Fprintf(stderr, "%s\n", cs.Bold(hostname)) - for _, line := range lines { - fmt.Fprintf(stderr, " %s\n", line) + if failed { + fmt.Fprintf(stderr, "%s\n", cs.Bold(hostname)) + for _, line := range lines { + fmt.Fprintf(stderr, " %s\n", line) + } + } else { + fmt.Fprintf(stdout, "%s\n", cs.Bold(hostname)) + for _, line := range lines { + fmt.Fprintf(stdout, " %s\n", line) + } } } From 437b78a9552f61e8100bad2ec932ecf4ef012715 Mon Sep 17 00:00:00 2001 From: rajhawaldar Date: Wed, 7 Jun 2023 08:23:59 +0530 Subject: [PATCH 2/3] Resolve tests/lint errors --- pkg/cmd/auth/status/status.go | 2 +- pkg/cmd/auth/status/status_test.go | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/cmd/auth/status/status.go b/pkg/cmd/auth/status/status.go index 51d7b2c7d..77a5f125c 100644 --- a/pkg/cmd/auth/status/status.go +++ b/pkg/cmd/auth/status/status.go @@ -168,7 +168,7 @@ func statusRun(opts *StatusOptions) error { } if prevEntry && failed { fmt.Fprint(stderr, "\n") - } else if prevEntry && failed == false { + } else if prevEntry && !failed { fmt.Fprint(stdout, "\n") } prevEntry = true diff --git a/pkg/cmd/auth/status/status_test.go b/pkg/cmd/auth/status/status_test.go index e169d1b3f..16affe624 100644 --- a/pkg/cmd/auth/status/status_test.go +++ b/pkg/cmd/auth/status/status_test.go @@ -310,13 +310,12 @@ func Test_statusRun(t *testing.T) { tt.opts = &StatusOptions{} } - ios, _, _, stderr := iostreams.Test() + ios, _, stdout, stderr := iostreams.Test() ios.SetStdinTTY(true) ios.SetStderrTTY(true) ios.SetStdoutTTY(true) tt.opts.IO = ios - cfg := config.NewFromString("") if tt.cfgStubs != nil { tt.cfgStubs(cfg) @@ -340,9 +339,13 @@ func Test_statusRun(t *testing.T) { } else { assert.NoError(t, err) } - - output := strings.ReplaceAll(stderr.String(), config.ConfigDir()+string(filepath.Separator), "GH_CONFIG_DIR/") - assert.Equal(t, tt.wantOut, output) + output := strings.ReplaceAll(stdout.String(), config.ConfigDir()+string(filepath.Separator), "GH_CONFIG_DIR/") + errorOutput := strings.ReplaceAll(stderr.String(), config.ConfigDir()+string(filepath.Separator), "GH_CONFIG_DIR/") + if output != "" { + assert.Equal(t, tt.wantOut, output) + } else { + assert.Equal(t, tt.wantOut, errorOutput) + } mainBuf := bytes.Buffer{} hostsBuf := bytes.Buffer{} From b8302311fa3f49fefe036266b93710e20650bbd4 Mon Sep 17 00:00:00 2001 From: rajhawaldar Date: Thu, 15 Jun 2023 09:01:16 +0530 Subject: [PATCH 3/3] Added wantErrOut property --- pkg/cmd/auth/status/status_test.go | 31 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/pkg/cmd/auth/status/status_test.go b/pkg/cmd/auth/status/status_test.go index 16affe624..e18604202 100644 --- a/pkg/cmd/auth/status/status_test.go +++ b/pkg/cmd/auth/status/status_test.go @@ -76,12 +76,13 @@ func Test_statusRun(t *testing.T) { readConfigs := config.StubWriteConfig(t) tests := []struct { - name string - opts *StatusOptions - httpStubs func(*httpmock.Registry) - cfgStubs func(*config.ConfigMock) - wantErr string - wantOut string + name string + opts *StatusOptions + httpStubs func(*httpmock.Registry) + cfgStubs func(*config.ConfigMock) + wantErr string + wantOut string + wantErrOut string }{ { name: "hostname set", @@ -126,7 +127,7 @@ func Test_statusRun(t *testing.T) { httpmock.StringResponse(`{"data":{"viewer":{"login":"tess"}}}`)) }, wantErr: "SilentError", - wantOut: heredoc.Doc(` + wantErrOut: heredoc.Doc(` joel.miller X joel.miller: the token in GH_CONFIG_DIR/hosts.yml is missing required scope 'read:org' - To request missing scopes, run: gh auth refresh -h joel.miller @@ -156,7 +157,7 @@ func Test_statusRun(t *testing.T) { httpmock.StringResponse(`{"data":{"viewer":{"login":"tess"}}}`)) }, wantErr: "SilentError", - wantOut: heredoc.Doc(` + wantErrOut: heredoc.Doc(` joel.miller X joel.miller: authentication failed - The joel.miller token in GH_CONFIG_DIR/hosts.yml is no longer valid. @@ -298,9 +299,9 @@ func Test_statusRun(t *testing.T) { cfgStubs: func(c *config.ConfigMock) { c.Set("github.com", "oauth_token", "abc123") }, - httpStubs: func(reg *httpmock.Registry) {}, - wantErr: "SilentError", - wantOut: "Hostname \"github.example.com\" not found among authenticated GitHub hosts\n", + httpStubs: func(reg *httpmock.Registry) {}, + wantErr: "SilentError", + wantErrOut: "Hostname \"github.example.com\" not found among authenticated GitHub hosts\n", }, } @@ -341,11 +342,9 @@ func Test_statusRun(t *testing.T) { } output := strings.ReplaceAll(stdout.String(), config.ConfigDir()+string(filepath.Separator), "GH_CONFIG_DIR/") errorOutput := strings.ReplaceAll(stderr.String(), config.ConfigDir()+string(filepath.Separator), "GH_CONFIG_DIR/") - if output != "" { - assert.Equal(t, tt.wantOut, output) - } else { - assert.Equal(t, tt.wantOut, errorOutput) - } + + assert.Equal(t, tt.wantErrOut, errorOutput) + assert.Equal(t, tt.wantOut, output) mainBuf := bytes.Buffer{} hostsBuf := bytes.Buffer{}