File: model_test.go

package info (click to toggle)
golang-gopkg-alecthomas-kingpin.v3 3.0~git20180227.b8d601d-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 420 kB
  • sloc: makefile: 6
file content (44 lines) | stat: -rw-r--r-- 1,108 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package kingpin

import (
	"github.com/stretchr/testify/assert"

	"testing"
)

func TestFindModel(t *testing.T) {
	app := newTestApp()
	cmd := app.Command("cmd", "").Command("cmd2", "")
	model := app.Model()
	cmdModel := model.FindModelForCommand(cmd)
	assert.NotNil(t, cmdModel)
	assert.Equal(t, "cmd2", cmdModel.Name)
}

func TestFullCommand(t *testing.T) {
	app := newTestApp()
	cmd := app.Command("cmd", "").Command("cmd2", "")
	model := app.Model()
	cmdModel := model.FindModelForCommand(cmd)
	assert.Equal(t, "cmd cmd2", cmdModel.FullCommand())
}

func TestCmdSummary(t *testing.T) {
	app := newTestApp()
	cmd := app.Command("cmd", "")
	cmd.Flag("flag", "").Required().String()
	cmd = cmd.Command("cmd2", "")
	cmd.Arg("arg", "").Required().String()
	model := app.Model()
	cmdModel := model.FindModelForCommand(cmd)
	assert.Equal(t, "cmd --flag=FLAG cmd2 <arg>", cmdModel.CmdSummary())
}

func TestModelValue(t *testing.T) {
	app := newTestApp()
	value := app.Flag("test", "").Bool()
	*value = true
	model := app.Model()
	flag := model.FlagByName("test")
	assert.Equal(t, "true", flag.Value.String())
}