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

Function TestFileMapperWithDefaultNonExistentFile

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

Source from the content-addressed store, hash-verified

845}
846
847func TestFileMapperWithDefaultNonExistentFile(t *testing.T) {
848 type CLI struct {
849 File *os.File `default:"testdata/missing-default.txt"`
850 }
851 var cli CLI
852 p := mustNew(t, &cli)
853
854 // Test 1: With CLI arg pointing to existing file - should succeed
855 _, err := p.Parse([]string{"--file", "testdata/file.txt"})
856 assert.NoError(t, err)
857 assert.NotZero(t, cli.File)
858 assert.Contains(t, cli.File.Name(), "file.txt")
859 _ = cli.File.Close()
860
861 // Test 2: Without CLI arg - should fail because default file doesn't exist
862 p = mustNew(t, &cli)
863 _, err = p.Parse([]string{})
864 assert.Error(t, err)
865 assert.Contains(t, err.Error(), "missing-default.txt")
866 assert.IsError(t, err, os.ErrNotExist)
867}

Callers

nothing calls this directly

Calls 3

mustNewFunction · 0.85
ParseMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected