MCPcopy
hub / github.com/cli/cli / TestEditRun

Function TestEditRun

pkg/cmd/label/edit_test.go:91–170  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

89}
90
91func TestEditRun(t *testing.T) {
92 tests := []struct {
93 name string
94 tty bool
95 opts *editOptions
96 httpStubs func(*httpmock.Registry)
97 wantStdout string
98 wantErrMsg string
99 }{
100 {
101 name: "updates label",
102 tty: true,
103 opts: &editOptions{Name: "test", Description: "some description"},
104 httpStubs: func(reg *httpmock.Registry) {
105 reg.Register(
106 httpmock.REST("PATCH", "repos/OWNER/REPO/labels/test"),
107 httpmock.StatusStringResponse(201, "{}"),
108 )
109 },
110 wantStdout: "✓ Label \"test\" updated in OWNER/REPO\n",
111 },
112 {
113 name: "updates label notty",
114 tty: false,
115 opts: &editOptions{Name: "test", Description: "some description"},
116 httpStubs: func(reg *httpmock.Registry) {
117 reg.Register(
118 httpmock.REST("PATCH", "repos/OWNER/REPO/labels/test"),
119 httpmock.StatusStringResponse(201, "{}"),
120 )
121 },
122 wantStdout: "",
123 },
124 {
125 name: "updates missing label",
126 opts: &editOptions{Name: "invalid", Description: "some description"},
127 httpStubs: func(reg *httpmock.Registry) {
128 reg.Register(
129 httpmock.REST("PATCH", "repos/OWNER/REPO/labels/invalid"),
130 httpmock.WithHeader(
131 httpmock.StatusStringResponse(404, `{"message":"Not Found"}`),
132 "Content-Type",
133 "application/json",
134 ),
135 )
136 },
137 wantErrMsg: "HTTP 404: Not Found (https://api.github.com/repos/OWNER/REPO/labels/invalid)",
138 },
139 }
140
141 for _, tt := range tests {
142 t.Run(tt.name, func(t *testing.T) {
143 reg := &httpmock.Registry{}
144 if tt.httpStubs != nil {
145 tt.httpStubs(reg)
146 }
147 tt.opts.HttpClient = func() (*http.Client, error) {
148 return &http.Client{Transport: reg}, nil

Callers

nothing calls this directly

Calls 14

RegisterMethod · 0.95
VerifyMethod · 0.95
RESTFunction · 0.92
StatusStringResponseFunction · 0.92
WithHeaderFunction · 0.92
TestFunction · 0.92
NewFunction · 0.92
SetStdoutTTYMethod · 0.80
SetStdinTTYMethod · 0.80
SetStderrTTYMethod · 0.80
EqualMethod · 0.80
editRunFunction · 0.70

Tested by

no test coverage detected