|
|
@ -386,6 +386,20 @@ func TestStringSliceFlagApply_SetsAllNames(t *testing.T) {
|
|
|
|
expect(t, err, nil)
|
|
|
|
expect(t, err, nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestStringSliceFlagApply_UsesEnvValues(t *testing.T) {
|
|
|
|
|
|
|
|
defer resetEnv(os.Environ())
|
|
|
|
|
|
|
|
os.Clearenv()
|
|
|
|
|
|
|
|
_ = os.Setenv("MY_GOAT", "vincent van goat,scape goat")
|
|
|
|
|
|
|
|
var val StringSlice
|
|
|
|
|
|
|
|
fl := StringSliceFlag{Name: "goat", EnvVars: []string{"MY_GOAT"}, Value: &val}
|
|
|
|
|
|
|
|
set := flag.NewFlagSet("test", 0)
|
|
|
|
|
|
|
|
_ = fl.Apply(set)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err := set.Parse(nil)
|
|
|
|
|
|
|
|
expect(t, err, nil)
|
|
|
|
|
|
|
|
expect(t, val.Value(), NewStringSlice("vincent van goat", "scape goat").Value())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestStringSliceFlagApply_DefaultValueWithDestination(t *testing.T) {
|
|
|
|
func TestStringSliceFlagApply_DefaultValueWithDestination(t *testing.T) {
|
|
|
|
defValue := []string{"UA", "US"}
|
|
|
|
defValue := []string{"UA", "US"}
|
|
|
|
|
|
|
|
|
|
|
@ -1836,6 +1850,17 @@ func TestTimestampFlagApply(t *testing.T) {
|
|
|
|
expect(t, *fl.Value.timestamp, expectedResult)
|
|
|
|
expect(t, *fl.Value.timestamp, expectedResult)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestTimestampFlagApplyValue(t *testing.T) {
|
|
|
|
|
|
|
|
expectedResult, _ := time.Parse(time.RFC3339, "2006-01-02T15:04:05Z")
|
|
|
|
|
|
|
|
fl := TimestampFlag{Name: "time", Aliases: []string{"t"}, Layout: time.RFC3339, Value: NewTimestamp(expectedResult)}
|
|
|
|
|
|
|
|
set := flag.NewFlagSet("test", 0)
|
|
|
|
|
|
|
|
_ = fl.Apply(set)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err := set.Parse([]string{""})
|
|
|
|
|
|
|
|
expect(t, err, nil)
|
|
|
|
|
|
|
|
expect(t, *fl.Value.timestamp, expectedResult)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestTimestampFlagApply_Fail_Parse_Wrong_Layout(t *testing.T) {
|
|
|
|
func TestTimestampFlagApply_Fail_Parse_Wrong_Layout(t *testing.T) {
|
|
|
|
fl := TimestampFlag{Name: "time", Aliases: []string{"t"}, Layout: "randomlayout"}
|
|
|
|
fl := TimestampFlag{Name: "time", Aliases: []string{"t"}, Layout: "randomlayout"}
|
|
|
|
set := flag.NewFlagSet("test", 0)
|
|
|
|
set := flag.NewFlagSet("test", 0)
|
|
|
|