MCPcopy
hub / github.com/cli/cli / Test_apiRun_inputFile

Function Test_apiRun_inputFile

pkg/cmd/api/api_test.go:1266–1344  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1264}
1265
1266func Test_apiRun_inputFile(t *testing.T) {
1267 tests := []struct {
1268 name string
1269 inputFile string
1270 inputContents []byte
1271
1272 contentLength int64
1273 expectedContents []byte
1274 }{
1275 {
1276 name: "stdin",
1277 inputFile: "-",
1278 inputContents: []byte("I WORK OUT"),
1279 contentLength: 0,
1280 },
1281 {
1282 name: "from file",
1283 inputFile: "gh-test-file",
1284 inputContents: []byte("I WORK OUT"),
1285 contentLength: 10,
1286 },
1287 }
1288
1289 tempDir := t.TempDir()
1290
1291 for _, tt := range tests {
1292 t.Run(tt.name, func(t *testing.T) {
1293 ios, stdin, _, _ := iostreams.Test()
1294 resp := &http.Response{StatusCode: 204}
1295
1296 inputFile := tt.inputFile
1297 if tt.inputFile == "-" {
1298 _, _ = stdin.Write(tt.inputContents)
1299 } else {
1300 f, err := os.CreateTemp(tempDir, tt.inputFile)
1301 if err != nil {
1302 t.Fatal(err)
1303 }
1304 _, _ = f.Write(tt.inputContents)
1305 defer f.Close()
1306 inputFile = f.Name()
1307 }
1308
1309 var bodyBytes []byte
1310 options := ApiOptions{
1311 RequestPath: "hello",
1312 RequestInputFile: inputFile,
1313 RawFields: []string{"a=b", "c=d"},
1314
1315 IO: ios,
1316 HttpClient: func() (*http.Client, error) {
1317 var tr roundTripper = func(req *http.Request) (*http.Response, error) {
1318 var err error
1319 if bodyBytes, err = io.ReadAll(req.Body); err != nil {
1320 return nil, err
1321 }
1322 resp.Request = req
1323 return resp, nil

Callers

nothing calls this directly

Calls 10

TestFunction · 0.92
NewBlankConfigFunction · 0.92
apiRunFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
WriteMethod · 0.65
CloseMethod · 0.65
NameMethod · 0.65
ErrorfMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected