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

Function NewTestAssets

internal/attachments/test.go:22–40  ·  view source on GitHub ↗

NewTestAssets returns a UserAsset per name, resolved through --attach, which is the only way a command builds one. It writes each name into a temporary directory and changes the working directory to it for the rest of the test, so the names are relative paths that resolve.

(t *testing.T, names ...string)

Source from the content-addressed store, hash-verified

20// directory to it for the rest of the test, so the names are relative paths
21// that resolve.
22func NewTestAssets(t *testing.T, names ...string) []UserAsset {
23 t.Helper()
24
25 t.Chdir(t.TempDir())
26
27 argv := make([]string, 0, len(names)*2)
28 for _, name := range names {
29 require.NoError(t, os.WriteFile(name, []byte("the bytes"), 0o600))
30 argv = append(argv, "--attach", "./"+name)
31 }
32
33 cmd := &cobra.Command{}
34 attachFlag := AddFlag(cmd)
35 require.NoError(t, cmd.Flags().Parse(argv))
36
37 assets, err := attachFlag.UserAssets()
38 require.NoError(t, err)
39 return assets
40}
41
42// StubUpload registers one upload of name against repositoryID, answering with
43// status and body.

Callers 6

Test_createRunFunction · 0.92
Test_editRunFunction · 0.92
Test_createRunFunction · 0.92
Test_editRunFunction · 0.92
TestFlagUserAssetsFunction · 0.85

Calls 3

AddFlagFunction · 0.85
UserAssetsMethod · 0.80
HelperMethod · 0.65

Tested by 6

Test_createRunFunction · 0.74
Test_editRunFunction · 0.74
Test_createRunFunction · 0.74
Test_editRunFunction · 0.74
TestFlagUserAssetsFunction · 0.68