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)
| 20 | // directory to it for the rest of the test, so the names are relative paths |
| 21 | // that resolve. |
| 22 | func 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. |