(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 | tests := []struct { |
| 45 | name string |
| 46 | tty bool |
| 47 | stdin string |
| 48 | cli string |
| 49 | config string |
| 50 | wantsErr bool |
| 51 | wantsErrMsg string |
| 52 | // wantErrIsNotExist covers an error whose text the operating system |
| 53 | // words differently, so the assertion cannot be on the message. |
| 54 | wantErrIsNotExist bool |
| 55 | wantsOpts CreateOptions |
| 56 | wantAssetPaths []string |
| 57 | }{ |
| 58 | { |
| 59 | name: "empty non-tty", |
| 60 | tty: false, |
| 61 | cli: "", |
| 62 | wantsErr: true, |
| 63 | }, |
| 64 | { |
| 65 | name: "only title non-tty", |
| 66 | tty: false, |
| 67 | cli: "-t mytitle", |
| 68 | wantsErr: true, |
| 69 | }, |
| 70 | { |
| 71 | name: "empty tty", |
| 72 | tty: true, |
| 73 | cli: "", |
| 74 | wantsErr: false, |
| 75 | wantsOpts: CreateOptions{ |
| 76 | Title: "", |
| 77 | Body: "", |
| 78 | RecoverFile: "", |
| 79 | WebMode: false, |
| 80 | Interactive: true, |
| 81 | }, |
| 82 | }, |
| 83 | { |
| 84 | name: "body from stdin", |
| 85 | tty: false, |
| 86 | stdin: "this is on standard input", |
| 87 | cli: "-t mytitle -F -", |
| 88 | wantsErr: false, |
| 89 | wantsOpts: CreateOptions{ |
| 90 | Title: "mytitle", |
| 91 | Body: "this is on standard input", |
| 92 | RecoverFile: "", |
| 93 | WebMode: false, |
nothing calls this directly
no test coverage detected