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

Function TestPathMapperWithDefaultUsingStringPointer

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

Source from the content-addressed store, hash-verified

588}
589
590func TestPathMapperWithDefaultUsingStringPointer(t *testing.T) {
591 type CLI struct {
592 Path *string `type:"path" default:"foobar"`
593 }
594 var cli CLI
595
596 t.Run("With value", func(t *testing.T) {
597 pwd, err := os.Getwd()
598 assert.NoError(t, err)
599 p := mustNew(t, &cli)
600 _, err = p.Parse([]string{"--path", "."})
601 assert.NoError(t, err)
602 assert.NotZero(t, cli.Path)
603 assert.Equal(t, pwd, *cli.Path)
604 })
605
606 t.Run("Zero value", func(t *testing.T) {
607 p := mustNew(t, &cli)
608 _, err := p.Parse([]string{"--path", ""})
609 assert.NoError(t, err)
610 assert.Equal(t, nil, cli.Path)
611 })
612
613 t.Run("Without value", func(t *testing.T) {
614 pwd, err := os.Getwd()
615 assert.NoError(t, err)
616 pwd = filepath.Join(pwd, "foobar")
617 pwd, err = filepath.Abs(pwd)
618 assert.NoError(t, err)
619 p := mustNew(t, &cli)
620 _, err = p.Parse([]string{"--"})
621 assert.NoError(t, err)
622 assert.Equal(t, pwd, *cli.Path)
623 })
624}
625
626//nolint:dupl
627func TestExistingFileMapper(t *testing.T) {

Callers

nothing calls this directly

Calls 3

mustNewFunction · 0.85
RunMethod · 0.45
ParseMethod · 0.45

Tested by

no test coverage detected