X Tutup
Skip to content

Commit 70c4cbf

Browse files
committed
Merge remote-tracking branch 'origin' into success-icon-consistency
2 parents f46bab2 + d0a4639 commit 70c4cbf

File tree

4 files changed

+125
-199
lines changed

4 files changed

+125
-199
lines changed

pkg/cmd/issue/view/view.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"github.com/MakeNowJust/heredoc"
1111
"github.com/cli/cli/api"
12-
"github.com/cli/cli/internal/config"
1312
"github.com/cli/cli/internal/ghrepo"
1413
"github.com/cli/cli/pkg/cmd/issue/shared"
1514
issueShared "github.com/cli/cli/pkg/cmd/issue/shared"
@@ -23,20 +22,21 @@ import (
2322

2423
type ViewOptions struct {
2524
HttpClient func() (*http.Client, error)
26-
Config func() (config.Config, error)
2725
IO *iostreams.IOStreams
2826
BaseRepo func() (ghrepo.Interface, error)
2927

3028
SelectorArg string
3129
WebMode bool
3230
Comments bool
31+
32+
Now func() time.Time
3333
}
3434

3535
func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Command {
3636
opts := &ViewOptions{
3737
IO: f.IOStreams,
3838
HttpClient: f.HttpClient,
39-
Config: f.Config,
39+
Now: time.Now,
4040
}
4141

4242
cmd := &cobra.Command{
@@ -141,7 +141,7 @@ func printRawIssuePreview(out io.Writer, issue *api.Issue) error {
141141

142142
func printHumanIssuePreview(opts *ViewOptions, issue *api.Issue) error {
143143
out := opts.IO.Out
144-
now := time.Now()
144+
now := opts.Now()
145145
ago := now.Sub(issue.CreatedAt)
146146
cs := opts.IO.ColorScheme()
147147

pkg/cmd/issue/view/view_test.go

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"os/exec"
99
"testing"
10+
"time"
1011

1112
"github.com/cli/cli/internal/config"
1213
"github.com/cli/cli/internal/ghrepo"
@@ -251,20 +252,38 @@ func TestIssueView_tty_Preview(t *testing.T) {
251252
}
252253
for name, tc := range tests {
253254
t.Run(name, func(t *testing.T) {
254-
http := &httpmock.Registry{}
255-
defer http.Verify(t)
256-
257-
http.Register(httpmock.GraphQL(`query IssueByNumber\b`), httpmock.FileResponse(tc.fixture))
258-
259-
output, err := runCommand(http, true, "123")
260-
if err != nil {
261-
t.Errorf("error running `issue view`: %v", err)
255+
io, _, stdout, stderr := iostreams.Test()
256+
io.SetStdoutTTY(true)
257+
io.SetStdinTTY(true)
258+
io.SetStderrTTY(true)
259+
260+
httpReg := &httpmock.Registry{}
261+
defer httpReg.Verify(t)
262+
263+
httpReg.Register(httpmock.GraphQL(`query IssueByNumber\b`), httpmock.FileResponse(tc.fixture))
264+
265+
opts := ViewOptions{
266+
IO: io,
267+
Now: func() time.Time {
268+
t, _ := time.Parse(time.RFC822, "03 Nov 20 15:04 UTC")
269+
return t
270+
},
271+
HttpClient: func() (*http.Client, error) {
272+
return &http.Client{Transport: httpReg}, nil
273+
},
274+
BaseRepo: func() (ghrepo.Interface, error) {
275+
return ghrepo.New("OWNER", "REPO"), nil
276+
},
277+
SelectorArg: "123",
262278
}
263279

264-
assert.Equal(t, "", output.Stderr())
280+
err := viewRun(&opts)
281+
assert.NoError(t, err)
282+
283+
assert.Equal(t, "", stderr.String())
265284

266285
//nolint:staticcheck // prefer exact matchers over ExpectLines
267-
test.ExpectLines(t, output.String(), tc.expectedOutputs...)
286+
test.ExpectLines(t, stdout.String(), tc.expectedOutputs...)
268287
})
269288
}
270289
}

0 commit comments

Comments
 (0)
X Tutup