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

Function NewTestAssets

internal/attachments/test.go:24–43  ·  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. A name may include direct

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

Source from the content-addressed store, hash-verified

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

Callers 9

Test_createRunFunction · 0.92
TestNewUploaderFunction · 0.92
TestCreateRunFunction · 0.92
TestEditRunFunction · 0.92
Test_editRunFunction · 0.92
Test_createRunFunction · 0.92
Test_editRunFunction · 0.92
TestFlagUserAssetsFunction · 0.85

Calls 5

AddFlagFunction · 0.85
MkdirAllMethod · 0.80
WriteFileMethod · 0.80
UserAssetsMethod · 0.80
HelperMethod · 0.65

Tested by 9

Test_createRunFunction · 0.74
TestNewUploaderFunction · 0.74
TestCreateRunFunction · 0.74
TestEditRunFunction · 0.74
Test_editRunFunction · 0.74
Test_createRunFunction · 0.74
Test_editRunFunction · 0.74
TestFlagUserAssetsFunction · 0.68