@@ -2,9 +2,14 @@ package list
22
33import (
44 "bytes"
5+ "net/http"
56 "testing"
7+ "time"
68
9+ "github.com/cli/cli/pkg/cmd/gist/shared"
710 "github.com/cli/cli/pkg/cmdutil"
11+ "github.com/cli/cli/pkg/httpmock"
12+ "github.com/cli/cli/pkg/iostreams"
813 "github.com/google/shlex"
914 "github.com/stretchr/testify/assert"
1015)
@@ -84,3 +89,74 @@ func TestNewCmdList(t *testing.T) {
8489}
8590
8691// TODO execution tests
92+
93+ func Test_listRun (t * testing.T ) {
94+ tests := []struct {
95+ name string
96+ opts * ListOptions
97+ wantOut string
98+ stubs func (* httpmock.Registry )
99+ }{
100+ {
101+ name : "no gists" ,
102+ opts : & ListOptions {},
103+ stubs : func (reg * httpmock.Registry ) {
104+ reg .Register (httpmock .REST ("GET" , "gists" ),
105+ httpmock .JSONResponse ([]shared.Gist {}))
106+
107+ },
108+ wantOut : "" ,
109+ },
110+
111+ {
112+ name : "default behavior" ,
113+ opts : & ListOptions {},
114+ wantOut : "TODO" ,
115+ },
116+ // TODO public filter
117+ // TODO secret filter
118+ // TODO limit specified
119+ }
120+
121+ for _ , tt := range tests {
122+ reg := & httpmock.Registry {}
123+ if tt .stubs == nil {
124+ reg .Register (httpmock .REST ("GET" , "gists" ),
125+ httpmock .JSONResponse ([]shared.Gist {
126+ {
127+ ID : "1234567890" ,
128+ Description : "" ,
129+ Files : map [string ]* shared.GistFile {
130+ "cool.txt" : {
131+ Content : "lol" ,
132+ },
133+ },
134+ Public : true ,
135+ UpdatedAt : time.Time {},
136+ },
137+ }))
138+ } else {
139+ tt .stubs (reg )
140+ }
141+
142+ tt .opts .HttpClient = func () (* http.Client , error ) {
143+ return & http.Client {Transport : reg }, nil
144+ }
145+
146+ tt .opts .Since = func (t time.Time ) time.Duration {
147+ d , _ := time .ParseDuration ("6h" )
148+ return d
149+ }
150+
151+ io , _ , stdout , _ := iostreams .Test ()
152+ tt .opts .IO = io
153+
154+ t .Run (tt .name , func (t * testing.T ) {
155+ err := listRun (tt .opts )
156+ assert .NoError (t , err )
157+
158+ assert .Equal (t , tt .wantOut , stdout .String ())
159+ reg .Verify (t )
160+ })
161+ }
162+ }
0 commit comments