Fix date-based release output and tests
This commit is contained in:
parent
0f42c7af4d
commit
4976bd75e1
4 changed files with 27 additions and 7 deletions
|
|
@ -99,7 +99,7 @@ func listRun(opts *ListOptions) error {
|
|||
if rel.PublishedAt.IsZero() {
|
||||
pubDate = rel.CreatedAt
|
||||
}
|
||||
publishedAt := pubDate.String()
|
||||
publishedAt := pubDate.Format(time.RFC3339)
|
||||
if table.IsTTY() {
|
||||
publishedAt = utils.FuzzyAgo(now.Sub(pubDate))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,6 +75,9 @@ func Test_NewCmdList(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_listRun(t *testing.T) {
|
||||
frozenTime, err := time.Parse(time.RFC3339, "2020-08-31T15:44:24+02:00")
|
||||
require.NoError(t, err)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
isTTY bool
|
||||
|
|
@ -97,6 +100,20 @@ func Test_listRun(t *testing.T) {
|
|||
`),
|
||||
wantStderr: ``,
|
||||
},
|
||||
{
|
||||
name: "machine-readable",
|
||||
isTTY: false,
|
||||
opts: ListOptions{
|
||||
LimitResults: 30,
|
||||
},
|
||||
wantStdout: heredoc.Doc(`
|
||||
v1.1.0 Draft v1.1.0 2020-08-31T15:44:24+02:00
|
||||
The big 1.0 Latest v1.0.0 2020-08-31T15:44:24+02:00
|
||||
1.0 release candidate Pre-release v1.0.0-pre.2 2020-08-31T15:44:24+02:00
|
||||
New features v0.9.2 2020-08-31T15:44:24+02:00
|
||||
`),
|
||||
wantStderr: ``,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
@ -105,7 +122,10 @@ func Test_listRun(t *testing.T) {
|
|||
io.SetStdinTTY(tt.isTTY)
|
||||
io.SetStderrTTY(tt.isTTY)
|
||||
|
||||
relativeTime := time.Now().Add(time.Duration(-24) * time.Hour)
|
||||
createdAt := frozenTime
|
||||
if tt.isTTY {
|
||||
createdAt = time.Now().Add(time.Duration(-24) * time.Hour)
|
||||
}
|
||||
|
||||
fakeHTTP := &httpmock.Registry{}
|
||||
fakeHTTP.Register(httpmock.GraphQL(`\bRepositoryReleaseList\(`), httpmock.StringResponse(fmt.Sprintf(`
|
||||
|
|
@ -144,7 +164,7 @@ func Test_listRun(t *testing.T) {
|
|||
"publishedAt": "%[1]s"
|
||||
}
|
||||
]
|
||||
} } } }`, relativeTime.Format(time.RFC3339))))
|
||||
} } } }`, createdAt.Format(time.RFC3339))))
|
||||
|
||||
tt.opts.IO = io
|
||||
tt.opts.HttpClient = func() (*http.Client, error) {
|
||||
|
|
|
|||
|
|
@ -136,9 +136,9 @@ func renderReleasePlain(w io.Writer, release *shared.Release) error {
|
|||
fmt.Fprintf(w, "draft:\t%v\n", release.IsDraft)
|
||||
fmt.Fprintf(w, "prerelease:\t%v\n", release.IsPrerelease)
|
||||
fmt.Fprintf(w, "author:\t%s\n", release.Author.Login)
|
||||
fmt.Fprintf(w, "created:\t%s\n", release.CreatedAt)
|
||||
fmt.Fprintf(w, "created:\t%s\n", release.CreatedAt.Format(time.RFC3339))
|
||||
if !release.IsDraft {
|
||||
fmt.Fprintf(w, "published:\t%s\n", release.PublishedAt)
|
||||
fmt.Fprintf(w, "published:\t%s\n", release.PublishedAt.Format(time.RFC3339))
|
||||
}
|
||||
fmt.Fprintf(w, "url:\t%s\n", release.HTMLURL)
|
||||
for _, a := range release.Assets {
|
||||
|
|
|
|||
|
|
@ -155,8 +155,8 @@ func Test_viewRun(t *testing.T) {
|
|||
draft: false
|
||||
prerelease: false
|
||||
author: MonaLisa
|
||||
created: 2020-08-31 15:44:24 +0200 CEST
|
||||
published: 2020-08-31 15:44:24 +0200 CEST
|
||||
created: 2020-08-31T15:44:24+02:00
|
||||
published: 2020-08-31T15:44:24+02:00
|
||||
url: https://github.com/OWNER/REPO/releases/tags/v1.2.3
|
||||
asset: windows.zip
|
||||
asset: linux.tgz
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue