linter fixes

code cleanup
changing some test code to ensure uniformity
This commit is contained in:
Ajitem Sahasrabuddhe
2019-08-07 20:14:50 +05:30
parent 521735b760
commit fdba7e0f8c
13 changed files with 303 additions and 324 deletions

View File

@@ -72,7 +72,7 @@ func (f *GenericFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourc
}
if value != nil {
eachName(f.Name, func(name string) {
f.set.Set(f.Name, value.String())
_ = f.set.Set(f.Name, value.String())
})
}
}
@@ -135,7 +135,7 @@ func (f *BoolFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceCo
}
if value {
eachName(f.Name, func(name string) {
f.set.Set(f.Name, strconv.FormatBool(value))
_ = f.set.Set(f.Name, strconv.FormatBool(value))
})
}
}
@@ -153,7 +153,7 @@ func (f *BoolTFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceC
}
if !value {
eachName(f.Name, func(name string) {
f.set.Set(f.Name, strconv.FormatBool(value))
_ = f.set.Set(f.Name, strconv.FormatBool(value))
})
}
}
@@ -171,7 +171,7 @@ func (f *StringFlag) ApplyInputSourceValue(context *cli.Context, isc InputSource
}
if value != "" {
eachName(f.Name, func(name string) {
f.set.Set(f.Name, value)
_ = f.set.Set(f.Name, value)
})
}
}
@@ -189,7 +189,7 @@ func (f *IntFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceCon
}
if value > 0 {
eachName(f.Name, func(name string) {
f.set.Set(f.Name, strconv.FormatInt(int64(value), 10))
_ = f.set.Set(f.Name, strconv.FormatInt(int64(value), 10))
})
}
}
@@ -207,7 +207,7 @@ func (f *DurationFlag) ApplyInputSourceValue(context *cli.Context, isc InputSour
}
if value > 0 {
eachName(f.Name, func(name string) {
f.set.Set(f.Name, value.String())
_ = f.set.Set(f.Name, value.String())
})
}
}
@@ -226,7 +226,7 @@ func (f *Float64Flag) ApplyInputSourceValue(context *cli.Context, isc InputSourc
if value > 0 {
floatStr := float64ToString(value)
eachName(f.Name, func(name string) {
f.set.Set(f.Name, floatStr)
_ = f.set.Set(f.Name, floatStr)
})
}
}

View File

@@ -239,30 +239,30 @@ func TestDurationApplyInputSourceMethodSet(t *testing.T) {
c := runTest(t, testApplyInputSource{
Flag: NewDurationFlag(cli.DurationFlag{Name: "test"}),
FlagName: "test",
MapValue: time.Duration(30 * time.Second),
MapValue: 30 * time.Second,
})
expect(t, time.Duration(30*time.Second), c.Duration("test"))
expect(t, 30*time.Second, c.Duration("test"))
}
func TestDurationApplyInputSourceMethodContextSet(t *testing.T) {
c := runTest(t, testApplyInputSource{
Flag: NewDurationFlag(cli.DurationFlag{Name: "test"}),
FlagName: "test",
MapValue: time.Duration(30 * time.Second),
ContextValueString: time.Duration(15 * time.Second).String(),
MapValue: 30 * time.Second,
ContextValueString: (15 * time.Second).String(),
})
expect(t, time.Duration(15*time.Second), c.Duration("test"))
expect(t, 15*time.Second, c.Duration("test"))
}
func TestDurationApplyInputSourceMethodEnvVarSet(t *testing.T) {
c := runTest(t, testApplyInputSource{
Flag: NewDurationFlag(cli.DurationFlag{Name: "test", EnvVar: "TEST"}),
FlagName: "test",
MapValue: time.Duration(30 * time.Second),
MapValue: 30 * time.Second,
EnvVarName: "TEST",
EnvVarValue: time.Duration(15 * time.Second).String(),
EnvVarValue: (15 * time.Second).String(),
})
expect(t, time.Duration(15*time.Second), c.Duration("test"))
expect(t, 15*time.Second, c.Duration("test"))
}
func TestFloat64ApplyInputSourceMethodSet(t *testing.T) {
@@ -300,19 +300,19 @@ func runTest(t *testing.T, test testApplyInputSource) *cli.Context {
set := flag.NewFlagSet(test.FlagSetName, flag.ContinueOnError)
c := cli.NewContext(nil, set, nil)
if test.EnvVarName != "" && test.EnvVarValue != "" {
os.Setenv(test.EnvVarName, test.EnvVarValue)
_ = os.Setenv(test.EnvVarName, test.EnvVarValue)
defer os.Setenv(test.EnvVarName, "")
}
test.Flag.Apply(set)
if test.ContextValue != nil {
flag := set.Lookup(test.FlagName)
flag.Value = test.ContextValue
f := set.Lookup(test.FlagName)
f.Value = test.ContextValue
}
if test.ContextValueString != "" {
set.Set(test.FlagName, test.ContextValueString)
_ = set.Set(test.FlagName, test.ContextValueString)
}
test.Flag.ApplyInputSourceValue(c, inputSource)
_ = test.Flag.ApplyInputSourceValue(c, inputSource)
return c
}

View File

@@ -22,7 +22,7 @@ func TestCommandJSONFileTest(t *testing.T) {
app := cli.NewApp()
set := flag.NewFlagSet("test", 0)
test := []string{"test-cmd", "--load", fileName}
set.Parse(test)
_ = set.Parse(test)
c := cli.NewContext(app, set, nil)
@@ -52,11 +52,11 @@ func TestCommandJSONFileTestGlobalEnvVarWins(t *testing.T) {
app := cli.NewApp()
set := flag.NewFlagSet("test", 0)
os.Setenv("THE_TEST", "10")
_ = os.Setenv("THE_TEST", "10")
defer os.Setenv("THE_TEST", "")
test := []string{"test-cmd", "--load", fileName}
set.Parse(test)
_ = set.Parse(test)
c := cli.NewContext(app, set, nil)
@@ -87,11 +87,11 @@ func TestCommandJSONFileTestGlobalEnvVarWinsNested(t *testing.T) {
app := cli.NewApp()
set := flag.NewFlagSet("test", 0)
os.Setenv("THE_TEST", "10")
_ = os.Setenv("THE_TEST", "10")
defer os.Setenv("THE_TEST", "")
test := []string{"test-cmd", "--load", fileName}
set.Parse(test)
_ = set.Parse(test)
c := cli.NewContext(app, set, nil)
@@ -123,7 +123,7 @@ func TestCommandJSONFileTestSpecifiedFlagWins(t *testing.T) {
app := cli.NewApp()
set := flag.NewFlagSet("test", 0)
test := []string{"test-cmd", "--load", fileName, "--test", "7"}
set.Parse(test)
_ = set.Parse(test)
c := cli.NewContext(app, set, nil)
@@ -155,7 +155,7 @@ func TestCommandJSONFileTestSpecifiedFlagWinsNested(t *testing.T) {
app := cli.NewApp()
set := flag.NewFlagSet("test", 0)
test := []string{"test-cmd", "--load", fileName, "--top.test", "7"}
set.Parse(test)
_ = set.Parse(test)
c := cli.NewContext(app, set, nil)
@@ -187,7 +187,7 @@ func TestCommandJSONFileTestDefaultValueFileWins(t *testing.T) {
app := cli.NewApp()
set := flag.NewFlagSet("test", 0)
test := []string{"test-cmd", "--load", fileName}
set.Parse(test)
_ = set.Parse(test)
c := cli.NewContext(app, set, nil)
@@ -219,7 +219,7 @@ func TestCommandJSONFileTestDefaultValueFileWinsNested(t *testing.T) {
app := cli.NewApp()
set := flag.NewFlagSet("test", 0)
test := []string{"test-cmd", "--load", fileName}
set.Parse(test)
_ = set.Parse(test)
c := cli.NewContext(app, set, nil)
@@ -250,11 +250,11 @@ func TestCommandJSONFileFlagHasDefaultGlobalEnvJSONSetGlobalEnvWins(t *testing.T
app := cli.NewApp()
set := flag.NewFlagSet("test", 0)
os.Setenv("THE_TEST", "11")
_ = os.Setenv("THE_TEST", "11")
defer os.Setenv("THE_TEST", "")
test := []string{"test-cmd", "--load", fileName}
set.Parse(test)
_ = set.Parse(test)
c := cli.NewContext(app, set, nil)
@@ -284,11 +284,11 @@ func TestCommandJSONFileFlagHasDefaultGlobalEnvJSONSetGlobalEnvWinsNested(t *tes
app := cli.NewApp()
set := flag.NewFlagSet("test", 0)
os.Setenv("THE_TEST", "11")
_ = os.Setenv("THE_TEST", "11")
defer os.Setenv("THE_TEST", "")
test := []string{"test-cmd", "--load", fileName}
set.Parse(test)
_ = set.Parse(test)
c := cli.NewContext(app, set, nil)