@@ -89,11 +89,12 @@ func TestNewCmdList(t *testing.T) {
8989
9090func Test_listRun (t * testing.T ) {
9191 tests := []struct {
92- name string
93- opts * ListOptions
94- wantOut string
95- stubs func (* httpmock.Registry )
96- nontty bool
92+ name string
93+ opts * ListOptions
94+ wantOut string
95+ stubs func (* httpmock.Registry )
96+ nontty bool
97+ updatedAt * time.Time
9798 }{
9899 {
99100 name : "no gists" ,
@@ -126,20 +127,28 @@ func Test_listRun(t *testing.T) {
126127 wantOut : "1234567890 cool.txt 1 file public about 6 hours ago\n " ,
127128 },
128129 {
129- name : "nontty output" ,
130- opts : & ListOptions {},
131- wantOut : "1234567890\t cool.txt\t 1 file\t public\t 0001-01-01 00:00:00 +0000 UTC\n 4567890123\t \t 1 file\t public\t 0001-01-01 00:00:00 +0000 UTC\n 2345678901\t tea leaves thwart those who court catastrophe\t 2 files\t secret\t 0001-01-01 00:00:00 +0000 UTC\n 3456789012\t short desc\t 11 files\t secret\t 0001-01-01 00:00:00 +0000 UTC\n " ,
132- nontty : true ,
130+ name : "nontty output" ,
131+ opts : & ListOptions {},
132+ updatedAt : & time.Time {},
133+ wantOut : "1234567890\t cool.txt\t 1 file\t public\t 0001-01-01 00:00:00 +0000 UTC\n 4567890123\t \t 1 file\t public\t 0001-01-01 00:00:00 +0000 UTC\n 2345678901\t tea leaves thwart those who court catastrophe\t 2 files\t secret\t 0001-01-01 00:00:00 +0000 UTC\n 3456789012\t short desc\t 11 files\t secret\t 0001-01-01 00:00:00 +0000 UTC\n " ,
134+ nontty : true ,
133135 },
134136 }
135137
136138 for _ , tt := range tests {
139+ sixHoursAgo , _ := time .ParseDuration ("-6h" )
140+ updatedAt := time .Now ().Add (sixHoursAgo )
141+ if tt .updatedAt != nil {
142+ updatedAt = * tt .updatedAt
143+ }
144+
137145 reg := & httpmock.Registry {}
138146 if tt .stubs == nil {
139147 reg .Register (httpmock .REST ("GET" , "gists" ),
140148 httpmock .JSONResponse ([]shared.Gist {
141149 {
142150 ID : "1234567890" ,
151+ UpdatedAt : updatedAt ,
143152 Description : "" ,
144153 Files : map [string ]* shared.GistFile {
145154 "cool.txt" : {},
@@ -148,6 +157,7 @@ func Test_listRun(t *testing.T) {
148157 },
149158 {
150159 ID : "4567890123" ,
160+ UpdatedAt : updatedAt ,
151161 Description : "" ,
152162 Files : map [string ]* shared.GistFile {
153163 "gistfile0.txt" : {},
@@ -156,6 +166,7 @@ func Test_listRun(t *testing.T) {
156166 },
157167 {
158168 ID : "2345678901" ,
169+ UpdatedAt : updatedAt ,
159170 Description : "tea leaves thwart those who court catastrophe" ,
160171 Files : map [string ]* shared.GistFile {
161172 "gistfile0.txt" : {},
@@ -165,6 +176,7 @@ func Test_listRun(t *testing.T) {
165176 },
166177 {
167178 ID : "3456789012" ,
179+ UpdatedAt : updatedAt ,
168180 Description : "short desc" ,
169181 Files : map [string ]* shared.GistFile {
170182 "gistfile0.txt" : {},
@@ -190,11 +202,6 @@ func Test_listRun(t *testing.T) {
190202 return & http.Client {Transport : reg }, nil
191203 }
192204
193- tt .opts .Since = func (t time.Time ) time.Duration {
194- d , _ := time .ParseDuration ("6h" )
195- return d
196- }
197-
198205 io , _ , stdout , _ := iostreams .Test ()
199206 io .SetStdoutTTY (! tt .nontty )
200207 tt .opts .IO = io
0 commit comments