MCPcopy Create free account
hub / github.com/cli/cli / TestRequiresUserCapabilityForScript

Function TestRequiresUserCapabilityForScript

acceptance/user_capability_test.go:180–243  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

178}
179
180func TestRequiresUserCapabilityForScript(t *testing.T) {
181 tests := []struct {
182 name string
183 content string
184 want bool
185 wantErr string
186 }{
187 {
188 name: "requires user capability",
189 content: "# requires-user-capability: true\n",
190 want: true,
191 },
192 {
193 name: "does not require user capability",
194 content: "# requires-user-capability: false\n",
195 },
196 {
197 name: "supports CRLF",
198 content: "# requires-user-capability: true\r\n",
199 want: true,
200 },
201 {
202 name: "missing",
203 content: "",
204 wantErr: "first line must be",
205 },
206 {
207 name: "not first",
208 content: "# explanation\n# requires-user-capability: true\n",
209 wantErr: "first line must be",
210 },
211 {
212 name: "invalid value",
213 content: "# requires-user-capability: unknown\n",
214 wantErr: "first line must be",
215 },
216 {
217 name: "multiple",
218 content: "# requires-user-capability: false\n# requires-user-capability: true\n",
219 wantErr: "script must contain exactly one requires-user-capability declaration",
220 },
221 {
222 name: "ignores archive contents",
223 content: "# requires-user-capability: false\n\n" +
224 "-- script.sh --\n" +
225 "# requires-user-capability: true\n",
226 },
227 }
228
229 for _, tt := range tests {
230 t.Run(tt.name, func(t *testing.T) {
231 file := filepath.Join(t.TempDir(), "script.txtar")
232 require.NoError(t, os.WriteFile(file, []byte(tt.content), 0o600))
233
234 got, err := requiresUserCapabilityForScript(file)
235 if tt.wantErr == "" {
236 require.NoError(t, err)
237 assert.Equal(t, tt.want, got)

Callers

nothing calls this directly

Calls 4

JoinMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected