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)
| 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. |
| 24 | func 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. |
| 46 | func AssertTestTelemetryEvents(t *testing.T, events []ghtelemetry.Event, attachCount int, result UploadResult) { |