Skip to content

Commit c0952ee

Browse files
author
vilmibm
committed
WIP execution tests
1 parent 6674bb6 commit c0952ee

File tree

2 files changed

+149
-2
lines changed

2 files changed

+149
-2
lines changed

pkg/cmd/workflow/list/list.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import (
1515
const (
1616
defaultLimit = 10
1717

18-
Active WorkflowState = "active"
18+
Active WorkflowState = "active"
19+
DisabledManually WorkflowState = "disabled_manually"
1920
)
2021

2122
type ListOptions struct {

pkg/cmd/workflow/list/list_test.go

Lines changed: 147 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ package list
22

33
import (
44
"bytes"
5+
"fmt"
56
"io/ioutil"
7+
"net/http"
68
"testing"
79

10+
"github.com/cli/cli/internal/ghrepo"
811
"github.com/cli/cli/pkg/cmdutil"
12+
"github.com/cli/cli/pkg/httpmock"
913
"github.com/cli/cli/pkg/iostreams"
1014
"github.com/google/shlex"
1115
"github.com/stretchr/testify/assert"
@@ -92,4 +96,146 @@ func Test_NewCmdList(t *testing.T) {
9296
}
9397
}
9498

95-
// TODO execution tests
99+
func TestListRun(t *testing.T) {
100+
workflows := []Workflow{
101+
{
102+
Name: "Go",
103+
State: Active,
104+
ID: 707,
105+
},
106+
{
107+
Name: "Linter",
108+
State: Active,
109+
ID: 666,
110+
},
111+
{
112+
Name: "Release",
113+
State: DisabledManually,
114+
ID: 451,
115+
},
116+
}
117+
payload := WorkflowsPayload{Workflows: workflows}
118+
119+
tests := []struct {
120+
name string
121+
opts *ListOptions
122+
wantOut string
123+
wantErrOut string
124+
stubs func(*httpmock.Registry)
125+
tty bool
126+
}{
127+
{
128+
name: "blank tty",
129+
tty: true,
130+
opts: &ListOptions{
131+
Limit: defaultLimit,
132+
},
133+
stubs: func(reg *httpmock.Registry) {
134+
reg.Register(
135+
httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows"),
136+
httpmock.JSONResponse(payload))
137+
},
138+
wantOut: "Go active 707\nLinter active 666\n",
139+
},
140+
{
141+
name: "blank nontty",
142+
opts: &ListOptions{
143+
Limit: defaultLimit,
144+
PlainOutput: true,
145+
},
146+
stubs: func(reg *httpmock.Registry) {
147+
reg.Register(
148+
httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows"),
149+
httpmock.JSONResponse(payload))
150+
},
151+
wantOut: "Go\tactive\t707\nLinter\tactive\t666\n",
152+
},
153+
{
154+
name: "pagination",
155+
opts: &ListOptions{
156+
Limit: 101,
157+
},
158+
stubs: func(reg *httpmock.Registry) {
159+
workflows := []Workflow{}
160+
for flowID := 0; flowID < 103; flowID++ {
161+
workflows = append(workflows, Workflow{
162+
ID: flowID,
163+
Name: fmt.Sprintf("flow %d", flowID),
164+
State: Active,
165+
})
166+
}
167+
reg.Register(
168+
httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows"),
169+
httpmock.JSONResponse(WorkflowsPayload{
170+
Workflows: workflows[0:100],
171+
}))
172+
reg.Register(
173+
httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows"),
174+
httpmock.JSONResponse(WorkflowsPayload{
175+
Workflows: workflows[100:],
176+
}))
177+
},
178+
wantOut: longOutput,
179+
},
180+
/*
181+
{
182+
name: "no results nontty",
183+
opts: &ListOptions{
184+
Limit: defaultLimit,
185+
PlainOutput: true,
186+
},
187+
stubs: func(reg *httpmock.Registry) {
188+
reg.Register(
189+
httpmock.REST("GET", "TODO"),
190+
httpmock.JSONResponse(shared.RunsPayload{}),
191+
)
192+
},
193+
nontty: true,
194+
wantOut: "",
195+
},
196+
{
197+
name: "no results tty",
198+
opts: &ListOptions{
199+
Limit: defaultLimit,
200+
},
201+
stubs: func(reg *httpmock.Registry) {
202+
reg.Register(
203+
httpmock.REST("GET", "TODO"),
204+
httpmock.JSONResponse(shared.RunsPayload{}),
205+
)
206+
},
207+
wantOut: "",
208+
wantErrOut: "No workflows found\n",
209+
},
210+
211+
// TODO showing all workflows
212+
*/
213+
}
214+
215+
for _, tt := range tests {
216+
t.Run(tt.name, func(t *testing.T) {
217+
reg := &httpmock.Registry{}
218+
tt.stubs(reg)
219+
220+
tt.opts.HttpClient = func() (*http.Client, error) {
221+
return &http.Client{Transport: reg}, nil
222+
}
223+
224+
io, _, stdout, stderr := iostreams.Test()
225+
io.SetStdoutTTY(tt.tty)
226+
tt.opts.IO = io
227+
tt.opts.BaseRepo = func() (ghrepo.Interface, error) {
228+
return ghrepo.FromFullName("OWNER/REPO")
229+
}
230+
231+
err := listRun(tt.opts)
232+
assert.NoError(t, err)
233+
234+
assert.Equal(t, tt.wantOut, stdout.String())
235+
assert.Equal(t, tt.wantErrOut, stderr.String())
236+
reg.Verify(t)
237+
})
238+
}
239+
}
240+
241+
const longOutput = "flow 0\tactive\t0\nflow 1\tactive\t1\nflow 2\tactive\t2\nflow 3\tactive\t3\nflow 4\tactive\t4\nflow 5\tactive\t5\nflow 6\tactive\t6\nflow 7\tactive\t7\nflow 8\tactive\t8\nflow 9\tactive\t9\nflow 10\tactive\t10\nflow 11\tactive\t11\nflow 12\tactive\t12\nflow 13\tactive\t13\nflow 14\tactive\t14\nflow 15\tactive\t15\nflow 16\tactive\t16\nflow 17\tactive\t17\nflow 18\tactive\t18\nflow 19\tactive\t19\nflow 20\tactive\t20\nflow 21\tactive\t21\nflow 22\tactive\t22\nflow 23\tactive\t23\nflow 24\tactive\t24\nflow 25\tactive\t25\nflow 26\tactive\t26\nflow 27\tactive\t27\nflow 28\tactive\t28\nflow 29\tactive\t29\nflow 30\tactive\t30\nflow 31\tactive\t31\nflow 32\tactive\t32\nflow 33\tactive\t33\nflow 34\tactive\t34\nflow 35\tactive\t35\nflow 36\tactive\t36\nflow 37\tactive\t37\nflow 38\tactive\t38\nflow 39\tactive\t39\nflow 40\tactive\t40\nflow 41\tactive\t41\nflow 42\tactive\t42\nflow 43\tactive\t43\nflow 44\tactive\t44\nflow 45\tactive\t45\nflow 46\tactive\t46\nflow 47\tactive\t47\nflow 48\tactive\t48\nflow 49\tactive\t49\nflow 50\tactive\t50\nflow 51\tactive\t51\nflow 52\tactive\t52\nflow 53\tactive\t53\nflow 54\tactive\t54\nflow 55\tactive\t55\nflow 56\tactive\t56\nflow 57\tactive\t57\nflow 58\tactive\t58\nflow 59\tactive\t59\nflow 60\tactive\t60\nflow 61\tactive\t61\nflow 62\tactive\t62\nflow 63\tactive\t63\nflow 64\tactive\t64\nflow 65\tactive\t65\nflow 66\tactive\t66\nflow 67\tactive\t67\nflow 68\tactive\t68\nflow 69\tactive\t69\nflow 70\tactive\t70\nflow 71\tactive\t71\nflow 72\tactive\t72\nflow 73\tactive\t73\nflow 74\tactive\t74\nflow 75\tactive\t75\nflow 76\tactive\t76\nflow 77\tactive\t77\nflow 78\tactive\t78\nflow 79\tactive\t79\nflow 80\tactive\t80\nflow 81\tactive\t81\nflow 82\tactive\t82\nflow 83\tactive\t83\nflow 84\tactive\t84\nflow 85\tactive\t85\nflow 86\tactive\t86\nflow 87\tactive\t87\nflow 88\tactive\t88\nflow 89\tactive\t89\nflow 90\tactive\t90\nflow 91\tactive\t91\nflow 92\tactive\t92\nflow 93\tactive\t93\nflow 94\tactive\t94\nflow 95\tactive\t95\nflow 96\tactive\t96\nflow 97\tactive\t97\nflow 98\tactive\t98\nflow 99\tactive\t99\nflow 100\tactive\t100\n"

0 commit comments

Comments
 (0)