(t *testing.T)
| 34 | ) |
| 35 | |
| 36 | func TestNewCmdCreate(t *testing.T) { |
| 37 | tmpFile := filepath.Join(t.TempDir(), "my-body.md") |
| 38 | err := os.WriteFile(tmpFile, []byte("a body from file"), 0600) |
| 39 | require.NoError(t, err) |
| 40 | |
| 41 | tmpImage := filepath.Join(t.TempDir(), "shot.png") |
| 42 | require.NoError(t, os.WriteFile(tmpImage, []byte("the bytes"), 0600)) |
| 43 | |
| 44 | attachmentEvent := []ghtelemetry.Event{{ |
| 45 | Type: "attachment_invocation", |
| 46 | Dimensions: ghtelemetry.Dimensions{"command": "create"}, |
| 47 | Measures: ghtelemetry.Measures{ |
| 48 | "attach_count": 1, "append_ops_count": 0, "replace_ops_count": 0, |
| 49 | }, |
| 50 | }} |
| 51 | |
| 52 | tests := []struct { |
| 53 | name string |
| 54 | tty bool |
| 55 | stdin string |
| 56 | cli string |
| 57 | config string |
| 58 | wantsErr bool |
| 59 | wantsErrMsg string |
| 60 | // wantErrIsNotExist covers an error whose text the operating system |
| 61 | // words differently, so the assertion cannot be on the message. |
| 62 | wantErrIsNotExist bool |
| 63 | wantsOpts CreateOptions |
| 64 | wantAssetPaths []string |
| 65 | wantEvents []ghtelemetry.Event |
| 66 | wantSampleRate int |
| 67 | }{ |
| 68 | { |
| 69 | name: "empty non-tty", |
| 70 | tty: false, |
| 71 | cli: "", |
| 72 | wantsErr: true, |
| 73 | }, |
| 74 | { |
| 75 | name: "only title non-tty", |
| 76 | tty: false, |
| 77 | cli: "-t mytitle", |
| 78 | wantsErr: true, |
| 79 | }, |
| 80 | { |
| 81 | name: "empty tty", |
| 82 | tty: true, |
| 83 | cli: "", |
| 84 | wantsErr: false, |
| 85 | wantsOpts: CreateOptions{ |
| 86 | Title: "", |
| 87 | Body: "", |
| 88 | RecoverFile: "", |
| 89 | WebMode: false, |
| 90 | Interactive: true, |
| 91 | }, |
| 92 | }, |
| 93 | { |
nothing calls this directly
no test coverage detected