MCPcopy Create free account
hub / github.com/alecthomas/kong / TestFileMapperWithDefaultNonExistentFile

Function TestFileMapperWithDefaultNonExistentFile

mapper_test.go:879–899  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

877}
878
879func 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}

Callers

nothing calls this directly

Calls 3

mustNewFunction · 0.85
ParseMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected