MCPcopy
hub / github.com/cli/cli / TestFindWorkflow

Function TestFindWorkflow

pkg/cmd/workflow/shared/shared_test.go:20–166  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func TestFindWorkflow(t *testing.T) {
21 badRequestURL, err := url.Parse("https://api.github.com/repos/OWNER/REPO/actions/workflows/nonexistentWorkflow.yml")
22 if err != nil {
23 t.Fatal(err)
24 }
25
26 tests := []struct {
27 name string
28 workflowSelector string
29 repo ghrepo.Interface
30 httpStubs func(*httpmock.Registry)
31 states []WorkflowState
32 expectedWorkflow Workflow
33 expectedHTTPError *api.HTTPError
34 expectedError error
35 }{
36 {
37 name: "When the workflow selector is empty, it returns an error",
38 workflowSelector: "",
39 repo: ghrepo.New("OWNER", "REPO"),
40 expectedError: errors.New("empty workflow selector"),
41 },
42 {
43 name: "When the workflow selector is a number, it returns the workflow with that ID",
44 workflowSelector: "1",
45 repo: ghrepo.New("OWNER", "REPO"),
46 httpStubs: func(reg *httpmock.Registry) {
47 reg.Register(
48 httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/1"),
49 httpmock.StatusJSONResponse(200, Workflow{
50 ID: 1,
51 }),
52 )
53 },
54 expectedWorkflow: Workflow{
55 ID: 1,
56 },
57 },
58 {
59 name: "When the workflow selector is a file, it returns the workflow with that path",
60 workflowSelector: "workflowFile.yml",
61 repo: ghrepo.New("OWNER", "REPO"),
62 httpStubs: func(reg *httpmock.Registry) {
63 reg.Register(
64 httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/workflowFile.yml"),
65 httpmock.StatusJSONResponse(200, Workflow{
66 ID: 1,
67 Name: "Some Workflow",
68 Path: ".github/workflows/workflowFile.yml",
69 }),
70 )
71 },
72 expectedWorkflow: Workflow{
73 ID: 1,
74 Name: "Some Workflow",
75 Path: ".github/workflows/workflowFile.yml",
76 },
77 },

Callers

nothing calls this directly

Calls 9

RegisterMethod · 0.95
NewFunction · 0.92
RESTFunction · 0.92
StatusJSONResponseFunction · 0.92
StatusStringResponseFunction · 0.92
FindWorkflowFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected