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

Function testAsset

internal/attachments/client_test.go:23–42  ·  view source on GitHub ↗

testAsset stubs file opening so upload reads body without touching the filesystem.

(t *testing.T, name, contentType, body string)

Source from the content-addressed store, hash-verified

21// testAsset stubs file opening so upload reads body without touching the
22// filesystem.
23func testAsset(t *testing.T, name, contentType, body string) UserAsset {
24 t.Helper()
25
26 previousOpenFile := openFile
27 openFile = func(string) (io.ReadCloser, error) {
28 return io.NopCloser(strings.NewReader(body)), nil
29 }
30 t.Cleanup(func() { openFile = previousOpenFile })
31
32 info, err := fs.Stat(fstest.MapFS{
33 name: &fstest.MapFile{Data: []byte(body)},
34 }, name)
35 require.NoError(t, err)
36
37 base := asset{path: "./" + name, info: info, contentType: contentType}
38 if strings.HasPrefix(contentType, "video/") {
39 return &videoAsset{base}
40 }
41 return &imageAsset{base}
42}
43
44// newTestUploader builds an uploader whose requests land in reg.
45func newTestUploader(t *testing.T, reg *httpmock.Registry, host string, targetRepository int64) *Uploader {

Callers 5

TestUploadFunction · 0.85
TestUploadHostForTenantFunction · 0.85
TestUploadAuthenticationFunction · 0.85
TestUploadErrorsFunction · 0.85
TestUploadMissingFileFunction · 0.85

Calls 1

HelperMethod · 0.65

Tested by

no test coverage detected