nolint:dupl
(t *testing.T)
| 593 | |
| 594 | //nolint:dupl |
| 595 | func TestExistingFileMapper(t *testing.T) { |
| 596 | type CLI struct { |
| 597 | File string `type:"existingfile"` |
| 598 | } |
| 599 | var cli CLI |
| 600 | p := mustNew(t, &cli) |
| 601 | _, err := p.Parse([]string{"--file", "testdata/file.txt"}) |
| 602 | assert.NoError(t, err) |
| 603 | assert.NotZero(t, cli.File) |
| 604 | p = mustNew(t, &cli) |
| 605 | _, err = p.Parse([]string{"--file", "testdata/missing.txt"}) |
| 606 | assert.Error(t, err) |
| 607 | assert.Contains(t, err.Error(), "missing.txt:") |
| 608 | assert.IsError(t, err, os.ErrNotExist) |
| 609 | p = mustNew(t, &cli) |
| 610 | _, err = p.Parse([]string{"--file", "testdata/"}) |
| 611 | assert.Error(t, err) |
| 612 | assert.Contains(t, err.Error(), "exists but is a directory") |
| 613 | } |
| 614 | |
| 615 | func TestExistingFileMapperSlice(t *testing.T) { |
| 616 | type CLI struct { |