Skip to content

Commit 4976bd7

Browse files
committed
Fix date-based release output and tests
1 parent 0f42c7a commit 4976bd7

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

pkg/cmd/release/list/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func listRun(opts *ListOptions) error {
9999
if rel.PublishedAt.IsZero() {
100100
pubDate = rel.CreatedAt
101101
}
102-
publishedAt := pubDate.String()
102+
publishedAt := pubDate.Format(time.RFC3339)
103103
if table.IsTTY() {
104104
publishedAt = utils.FuzzyAgo(now.Sub(pubDate))
105105
}

pkg/cmd/release/list/list_test.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ func Test_NewCmdList(t *testing.T) {
7575
}
7676

7777
func Test_listRun(t *testing.T) {
78+
frozenTime, err := time.Parse(time.RFC3339, "2020-08-31T15:44:24+02:00")
79+
require.NoError(t, err)
80+
7881
tests := []struct {
7982
name string
8083
isTTY bool
@@ -97,6 +100,20 @@ func Test_listRun(t *testing.T) {
97100
`),
98101
wantStderr: ``,
99102
},
103+
{
104+
name: "machine-readable",
105+
isTTY: false,
106+
opts: ListOptions{
107+
LimitResults: 30,
108+
},
109+
wantStdout: heredoc.Doc(`
110+
v1.1.0 Draft v1.1.0 2020-08-31T15:44:24+02:00
111+
The big 1.0 Latest v1.0.0 2020-08-31T15:44:24+02:00
112+
1.0 release candidate Pre-release v1.0.0-pre.2 2020-08-31T15:44:24+02:00
113+
New features v0.9.2 2020-08-31T15:44:24+02:00
114+
`),
115+
wantStderr: ``,
116+
},
100117
}
101118
for _, tt := range tests {
102119
t.Run(tt.name, func(t *testing.T) {
@@ -105,7 +122,10 @@ func Test_listRun(t *testing.T) {
105122
io.SetStdinTTY(tt.isTTY)
106123
io.SetStderrTTY(tt.isTTY)
107124

108-
relativeTime := time.Now().Add(time.Duration(-24) * time.Hour)
125+
createdAt := frozenTime
126+
if tt.isTTY {
127+
createdAt = time.Now().Add(time.Duration(-24) * time.Hour)
128+
}
109129

110130
fakeHTTP := &httpmock.Registry{}
111131
fakeHTTP.Register(httpmock.GraphQL(`\bRepositoryReleaseList\(`), httpmock.StringResponse(fmt.Sprintf(`
@@ -144,7 +164,7 @@ func Test_listRun(t *testing.T) {
144164
"publishedAt": "%[1]s"
145165
}
146166
]
147-
} } } }`, relativeTime.Format(time.RFC3339))))
167+
} } } }`, createdAt.Format(time.RFC3339))))
148168

149169
tt.opts.IO = io
150170
tt.opts.HttpClient = func() (*http.Client, error) {

pkg/cmd/release/view/view.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ func renderReleasePlain(w io.Writer, release *shared.Release) error {
136136
fmt.Fprintf(w, "draft:\t%v\n", release.IsDraft)
137137
fmt.Fprintf(w, "prerelease:\t%v\n", release.IsPrerelease)
138138
fmt.Fprintf(w, "author:\t%s\n", release.Author.Login)
139-
fmt.Fprintf(w, "created:\t%s\n", release.CreatedAt)
139+
fmt.Fprintf(w, "created:\t%s\n", release.CreatedAt.Format(time.RFC3339))
140140
if !release.IsDraft {
141-
fmt.Fprintf(w, "published:\t%s\n", release.PublishedAt)
141+
fmt.Fprintf(w, "published:\t%s\n", release.PublishedAt.Format(time.RFC3339))
142142
}
143143
fmt.Fprintf(w, "url:\t%s\n", release.HTMLURL)
144144
for _, a := range release.Assets {

pkg/cmd/release/view/view_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ func Test_viewRun(t *testing.T) {
155155
draft: false
156156
prerelease: false
157157
author: MonaLisa
158-
created: 2020-08-31 15:44:24 +0200 CEST
159-
published: 2020-08-31 15:44:24 +0200 CEST
158+
created: 2020-08-31T15:44:24+02:00
159+
published: 2020-08-31T15:44:24+02:00
160160
url: https://github.com/OWNER/REPO/releases/tags/v1.2.3
161161
asset: windows.zip
162162
asset: linux.tgz

0 commit comments

Comments
 (0)