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

Function TestPathMapperWithDefaultUsingStringPointer

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

Source from the content-addressed store, hash-verified

556}
557
558func TestPathMapperWithDefaultUsingStringPointer(t *testing.T) {
559 type CLI struct {
560 Path *string `type:"path" default:"foobar"`
561 }
562 var cli CLI
563
564 t.Run("With value", func(t *testing.T) {
565 pwd, err := os.Getwd()
566 assert.NoError(t, err)
567 p := mustNew(t, &cli)
568 _, err = p.Parse([]string{"--path", "."})
569 assert.NoError(t, err)
570 assert.NotZero(t, cli.Path)
571 assert.Equal(t, pwd, *cli.Path)
572 })
573
574 t.Run("Zero value", func(t *testing.T) {
575 p := mustNew(t, &cli)
576 _, err := p.Parse([]string{"--path", ""})
577 assert.NoError(t, err)
578 assert.Equal(t, nil, cli.Path)
579 })
580
581 t.Run("Without value", func(t *testing.T) {
582 pwd, err := os.Getwd()
583 assert.NoError(t, err)
584 pwd = filepath.Join(pwd, "foobar")
585 pwd, err = filepath.Abs(pwd)
586 assert.NoError(t, err)
587 p := mustNew(t, &cli)
588 _, err = p.Parse([]string{"--"})
589 assert.NoError(t, err)
590 assert.Equal(t, pwd, *cli.Path)
591 })
592}
593
594//nolint:dupl
595func 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