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

Function TestExistingFileMapper

mapper_test.go:595–613  ·  view source on GitHub ↗

nolint:dupl

(t *testing.T)

Source from the content-addressed store, hash-verified

593
594//nolint:dupl
595func 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
615func TestExistingFileMapperSlice(t *testing.T) {
616 type CLI struct {

Callers

nothing calls this directly

Calls 3

mustNewFunction · 0.85
ParseMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected