(t *testing.T)
| 1458 | } |
| 1459 | |
| 1460 | func 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 | |
| 1488 | func TestCommand_ParseSliceFlagsWithMissingValue(t *testing.T) { |
| 1489 | var parsedIntSlice []int64 |
nothing calls this directly
no test coverage detected