(t *testing.T)
| 89 | } |
| 90 | |
| 91 | func TestFlagUserAssets(t *testing.T) { |
| 92 | tests := []struct { |
| 93 | name string |
| 94 | setup func(t *testing.T) |
| 95 | input string |
| 96 | wantPaths []string |
| 97 | wantAlts []string |
| 98 | wantErr string |
| 99 | // wantErrIs covers an error whose text the operating system words |
| 100 | // differently, so the assertion cannot be on the message. |
| 101 | wantErrIs error |
| 102 | }{ |
| 103 | { |
| 104 | name: "not passed", |
| 105 | input: "", |
| 106 | }, |
| 107 | { |
| 108 | name: "one file", |
| 109 | input: "--attach ./shot.png", |
| 110 | wantPaths: []string{"./shot.png"}, |
| 111 | }, |
| 112 | { |
| 113 | name: "a filename containing a hash stays whole", |
| 114 | input: "--attach './shot#dark.png'", |
| 115 | wantPaths: []string{"./shot#dark.png"}, |
| 116 | wantAlts: []string{"shot#dark"}, |
| 117 | }, |
| 118 | { |
| 119 | name: "alt text can contain a hash", |
| 120 | input: "--attach './caption.png#first#second'", |
| 121 | wantPaths: []string{"./caption.png"}, |
| 122 | wantAlts: []string{"first#second"}, |
| 123 | }, |
| 124 | { |
| 125 | name: "the longest existing path wins", |
| 126 | input: "--attach './shot#dark.png#first.png#second'", |
| 127 | wantPaths: []string{"./shot#dark.png#first.png"}, |
| 128 | wantAlts: []string{"second"}, |
| 129 | }, |
| 130 | { |
| 131 | name: "a missing path falls back at the last hash", |
| 132 | input: "--attach './gone.png#caption'", |
| 133 | wantErr: "./gone.png: ", |
| 134 | wantErrIs: fs.ErrNotExist, |
| 135 | }, |
| 136 | { |
| 137 | name: "several files, in the order written", |
| 138 | input: "--attach ./b.png --attach ./a.png", |
| 139 | wantPaths: []string{"./b.png", "./a.png"}, |
| 140 | }, |
| 141 | { |
| 142 | name: "too many attachments are rejected before filesystem validation", |
| 143 | input: strings.Repeat("--attach ./missing.txt ", maxAttachments+1), |
| 144 | wantErr: "`--attach` accepts at most 50 values per command", |
| 145 | }, |
| 146 | { |
| 147 | name: "a file that does not exist", |
| 148 | input: "--attach ./gone.png", |
nothing calls this directly
no test coverage detected