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

Function NewTestAssets

internal/attachments/test.go:23–41  ·  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

21// directory to it for the rest of the test, so the names are relative paths
22// that resolve.
23func NewTestAssets(t *testing.T, names ...string) []UserAsset {
24 t.Helper()
25
26 t.Chdir(t.TempDir())
27
28 argv := make([]string, 0, len(names)*2)
29 for _, name := range names {
30 require.NoError(t, os.WriteFile(name, []byte("the bytes"), 0o600))
31 argv = append(argv, "--attach", "./"+name)
32 }
33
34 cmd := &cobra.Command{}
35 attachFlag := AddFlag(cmd)
36 require.NoError(t, cmd.Flags().Parse(argv))
37
38 assets, err := attachFlag.UserAssets()
39 require.NoError(t, err)
40 return assets
41}
42
43// AssertTestTelemetryEvents verifies the completed invocation event shape.
44func AssertTestTelemetryEvents(t *testing.T, events []ghtelemetry.Event, attachCount int, result UploadResult) {

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