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)
| 21 | // directory to it for the rest of the test, so the names are relative paths |
| 22 | // that resolve. |
| 23 | func 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. |
| 44 | func AssertTestTelemetryEvents(t *testing.T, events []ghtelemetry.Event, attachCount int, result UploadResult) { |