MCPcopy
hub / github.com/cli/cli / TestCreateRun

Function TestCreateRun

pkg/cmd/label/create_test.go:86–169  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

84}
85
86func TestCreateRun(t *testing.T) {
87 tests := []struct {
88 name string
89 tty bool
90 opts *createOptions
91 httpStubs func(*httpmock.Registry)
92 wantStdout string
93 }{
94 {
95 name: "creates label",
96 tty: true,
97 opts: &createOptions{Name: "test", Description: "some description"},
98 httpStubs: func(reg *httpmock.Registry) {
99 reg.Register(
100 httpmock.REST("POST", "repos/OWNER/REPO/labels"),
101 httpmock.StatusStringResponse(201, "{}"),
102 )
103 },
104 wantStdout: "✓ Label \"test\" created in OWNER/REPO\n",
105 },
106 {
107 name: "creates label notty",
108 tty: false,
109 opts: &createOptions{Name: "test", Description: "some description"},
110 httpStubs: func(reg *httpmock.Registry) {
111 reg.Register(
112 httpmock.REST("POST", "repos/OWNER/REPO/labels"),
113 httpmock.StatusStringResponse(201, "{}"),
114 )
115 },
116 wantStdout: "",
117 },
118 {
119 name: "creates existing label",
120 opts: &createOptions{Name: "test", Description: "some description", Force: true},
121 httpStubs: func(reg *httpmock.Registry) {
122 reg.Register(
123 httpmock.REST("POST", "repos/OWNER/REPO/labels"),
124 httpmock.WithHeader(
125 httpmock.StatusStringResponse(422, `{"message":"Validation Failed","errors":[{"resource":"Label","code":"already_exists","field":"name"}]}`),
126 "Content-Type",
127 "application/json",
128 ),
129 )
130 reg.Register(
131 httpmock.REST("PATCH", "repos/OWNER/REPO/labels/test"),
132 httpmock.StatusStringResponse(201, "{}"),
133 )
134 },
135 },
136 }
137
138 for _, tt := range tests {
139 t.Run(tt.name, func(t *testing.T) {
140 reg := &httpmock.Registry{}
141 if tt.httpStubs != nil {
142 tt.httpStubs(reg)
143 }

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
createRunFunction · 0.70

Tested by

no test coverage detected