| 877 | } |
| 878 | |
| 879 | func TestFileMapperWithDefaultNonExistentFile(t *testing.T) { |
| 880 | type CLI struct { |
| 881 | File *os.File `default:"testdata/missing-default.txt"` |
| 882 | } |
| 883 | var cli CLI |
| 884 | p := mustNew(t, &cli) |
| 885 | |
| 886 | // Test 1: With CLI arg pointing to existing file - should succeed |
| 887 | _, err := p.Parse([]string{"--file", "testdata/file.txt"}) |
| 888 | assert.NoError(t, err) |
| 889 | assert.NotZero(t, cli.File) |
| 890 | assert.Contains(t, cli.File.Name(), "file.txt") |
| 891 | _ = cli.File.Close() |
| 892 | |
| 893 | // Test 2: Without CLI arg - should fail because default file doesn't exist |
| 894 | p = mustNew(t, &cli) |
| 895 | _, err = p.Parse([]string{}) |
| 896 | assert.Error(t, err) |
| 897 | assert.Contains(t, err.Error(), "missing-default.txt") |
| 898 | assert.IsError(t, err, os.ErrNotExist) |
| 899 | } |