MCPcopy
hub / github.com/urfave/cli / TestCommand_ParseSliceFlags

Function TestCommand_ParseSliceFlags

command_test.go:1460–1486  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1458}
1459
1460func TestCommand_ParseSliceFlags(t *testing.T) {
1461 var parsedIntSlice []int64
1462 var parsedStringSlice []string
1463
1464 cmd := &Command{
1465 Commands: []*Command{
1466 {
1467 Name: "cmd",
1468 Flags: []Flag{
1469 &Int64SliceFlag{Name: "p", Value: []int64{}, Usage: "set one or more ip addr"},
1470 &StringSliceFlag{Name: "ip", Value: []string{}, Usage: "set one or more ports to open"},
1471 },
1472 Action: func(_ context.Context, cmd *Command) error {
1473 parsedIntSlice = cmd.Int64Slice("p")
1474 parsedStringSlice = cmd.StringSlice("ip")
1475 return nil
1476 },
1477 },
1478 },
1479 }
1480
1481 r := require.New(t)
1482
1483 r.NoError(cmd.Run(buildTestContext(t), []string{"", "cmd", "-p", "22", "-p", "80", "-ip", "8.8.8.8", "-ip", "8.8.4.4"}))
1484 r.Equal([]int64{22, 80}, parsedIntSlice)
1485 r.Equal([]string{"8.8.8.8", "8.8.4.4"}, parsedStringSlice)
1486}
1487
1488func TestCommand_ParseSliceFlagsWithMissingValue(t *testing.T) {
1489 var parsedIntSlice []int64

Callers

nothing calls this directly

Calls 4

Int64SliceMethod · 0.95
StringSliceMethod · 0.95
RunMethod · 0.95
buildTestContextFunction · 0.85

Tested by

no test coverage detected