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

Function TestExistingFileMapperDefaultMissingCmds

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

Source from the content-addressed store, hash-verified

645}
646
647func TestExistingFileMapperDefaultMissingCmds(t *testing.T) {
648 type CLI struct {
649 CmdA struct {
650 FileA string `type:"existingfile" default:"testdata/aaa-missing.txt"`
651 FileB string `type:"existingfile" default:"testdata/bbb-missing.txt"`
652 } `cmd:""`
653 CmdC struct {
654 FileC string `type:"existingfile" default:"testdata/ccc-missing.txt"`
655 } `cmd:""`
656 }
657 var cli CLI
658 file := filepath.Join("testdata", "file.txt")
659 p := mustNew(t, &cli)
660 _, err := p.Parse([]string{"cmd-a", "--file-a", file, "--file-b", file})
661 assert.NoError(t, err)
662 assert.NotZero(t, cli.CmdA.FileA)
663 assert.Contains(t, cli.CmdA.FileA, file)
664 assert.NotZero(t, cli.CmdA.FileB)
665 assert.Contains(t, cli.CmdA.FileB, file)
666 p = mustNew(t, &cli)
667 _, err = p.Parse([]string{"cmd-a", "--file-a", file})
668 assert.Error(t, err)
669 assert.Contains(t, err.Error(), "bbb-missing.txt:")
670 assert.IsError(t, err, os.ErrNotExist)
671}
672
673//nolint:dupl
674func TestExistingDirMapper(t *testing.T) {

Callers

nothing calls this directly

Calls 3

mustNewFunction · 0.85
ParseMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected