Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sreya committed Feb 2, 2024
1 parent 898aff0 commit 95f410f
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions cli/cliflag/cliflag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestCliflag(t *testing.T) {
t.Run("UInt8Default", func(t *testing.T) {
var ptr uint8
flagset, name, shorthand, env, usage := randomFlag()
def, _ := cryptorand.Int63n(10)
def, _ := cryptorand.Intn(10)

cliflag.Uint8VarP(flagset, &ptr, name, shorthand, env, uint8(def), usage)
got, err := flagset.GetUint8(name)
Expand All @@ -124,9 +124,9 @@ func TestCliflag(t *testing.T) {
t.Run("UInt8EnvVar", func(t *testing.T) {
var ptr uint8
flagset, name, shorthand, env, usage := randomFlag()
envValue, _ := cryptorand.Int63n(10)
envValue, _ := cryptorand.Intn(10)
t.Setenv(env, strconv.FormatUint(uint64(envValue), 10))
def, _ := cryptorand.Int()
def, _ := cryptorand.Intn(10)

cliflag.Uint8VarP(flagset, &ptr, name, shorthand, env, uint8(def), usage)
got, err := flagset.GetUint8(name)
Expand All @@ -139,7 +139,7 @@ func TestCliflag(t *testing.T) {
flagset, name, shorthand, env, usage := randomFlag()
envValue, _ := cryptorand.String(10)
t.Setenv(env, envValue)
def, _ := cryptorand.Int63n(10)
def, _ := cryptorand.Intn(10)

cliflag.Uint8VarP(flagset, &ptr, name, shorthand, env, uint8(def), usage)
got, err := flagset.GetUint8(name)
Expand All @@ -150,7 +150,7 @@ func TestCliflag(t *testing.T) {
t.Run("IntDefault", func(t *testing.T) {
var ptr int
flagset, name, shorthand, env, usage := randomFlag()
def, _ := cryptorand.Int63n(10)
def, _ := cryptorand.Intn(10)

cliflag.IntVarP(flagset, &ptr, name, shorthand, env, int(def), usage)

Check failure on line 155 in cli/cliflag/cliflag_test.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary conversion (unconvert)
got, err := flagset.GetInt(name)
Expand All @@ -163,9 +163,9 @@ func TestCliflag(t *testing.T) {
t.Run("IntEnvVar", func(t *testing.T) {
var ptr int
flagset, name, shorthand, env, usage := randomFlag()
envValue, _ := cryptorand.Int63n(10)
envValue, _ := cryptorand.Intn(10)
t.Setenv(env, strconv.FormatUint(uint64(envValue), 10))
def, _ := cryptorand.Int()
def, _ := cryptorand.Intn(10)

cliflag.IntVarP(flagset, &ptr, name, shorthand, env, def, usage)
got, err := flagset.GetInt(name)
Expand All @@ -178,7 +178,7 @@ func TestCliflag(t *testing.T) {
flagset, name, shorthand, env, usage := randomFlag()
envValue, _ := cryptorand.String(10)
t.Setenv(env, envValue)
def, _ := cryptorand.Int63n(10)
def, _ := cryptorand.Intn(10)

cliflag.IntVarP(flagset, &ptr, name, shorthand, env, int(def), usage)

Check failure on line 183 in cli/cliflag/cliflag_test.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary conversion (unconvert)
got, err := flagset.GetInt(name)
Expand All @@ -189,22 +189,26 @@ func TestCliflag(t *testing.T) {
t.Run("BoolDefault", func(t *testing.T) {
var ptr bool
flagset, name, shorthand, env, usage := randomFlag()
def, _ := cryptorand.Bool()
def, _ := cryptorand.Intn(1)
boolDef := def == 1

cliflag.BoolVarP(flagset, &ptr, name, shorthand, env, def, usage)
cliflag.BoolVarP(flagset, &ptr, name, shorthand, env, boolDef, usage)
got, err := flagset.GetBool(name)
require.NoError(t, err)
require.Equal(t, def, got)
require.Equal(t, boolDef, got)
require.Contains(t, flagset.FlagUsages(), usage)
require.Contains(t, flagset.FlagUsages(), fmt.Sprintf("Consumes $%s", env))
})

t.Run("BoolEnvVar", func(t *testing.T) {
var ptr bool
flagset, name, shorthand, env, usage := randomFlag()
envValue, _ := cryptorand.Bool()
num, _ := cryptorand.Intn(1)
envValue := num == 1
t.Setenv(env, strconv.FormatBool(envValue))
def, _ := cryptorand.Bool()
defNum, _ := cryptorand.Intn(1)

def := defNum == 1

cliflag.BoolVarP(flagset, &ptr, name, shorthand, env, def, usage)
got, err := flagset.GetBool(name)
Expand All @@ -217,8 +221,8 @@ func TestCliflag(t *testing.T) {
flagset, name, shorthand, env, usage := randomFlag()
envValue, _ := cryptorand.String(10)
t.Setenv(env, envValue)
def, _ := cryptorand.Bool()

defNum, _ := cryptorand.Intn(1)
def := defNum == 1
cliflag.BoolVarP(flagset, &ptr, name, shorthand, env, def, usage)
got, err := flagset.GetBool(name)
require.NoError(t, err)
Expand All @@ -228,7 +232,7 @@ func TestCliflag(t *testing.T) {
t.Run("DurationDefault", func(t *testing.T) {
var ptr time.Duration
flagset, name, shorthand, env, usage := randomFlag()
def, _ := cryptorand.Duration()
def := time.Duration(10 * time.Second)

Check failure on line 235 in cli/cliflag/cliflag_test.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary conversion (unconvert)

cliflag.DurationVarP(flagset, &ptr, name, shorthand, env, def, usage)
got, err := flagset.GetDuration(name)
Expand All @@ -241,9 +245,9 @@ func TestCliflag(t *testing.T) {
t.Run("DurationEnvVar", func(t *testing.T) {
var ptr time.Duration
flagset, name, shorthand, env, usage := randomFlag()
envValue, _ := cryptorand.Duration()
envValue := time.Duration(10 * time.Second)

Check failure on line 248 in cli/cliflag/cliflag_test.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary conversion (unconvert)
t.Setenv(env, envValue.String())
def, _ := cryptorand.Duration()
def := time.Duration(10 * time.Minute)

Check failure on line 250 in cli/cliflag/cliflag_test.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary conversion (unconvert)

cliflag.DurationVarP(flagset, &ptr, name, shorthand, env, def, usage)
got, err := flagset.GetDuration(name)
Expand All @@ -256,7 +260,7 @@ func TestCliflag(t *testing.T) {
flagset, name, shorthand, env, usage := randomFlag()
envValue, _ := cryptorand.String(10)
t.Setenv(env, envValue)
def, _ := cryptorand.Duration()
def := time.Duration(10 * time.Minute)

Check failure on line 263 in cli/cliflag/cliflag_test.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary conversion (unconvert)

cliflag.DurationVarP(flagset, &ptr, name, shorthand, env, def, usage)
got, err := flagset.GetDuration(name)
Expand Down

0 comments on commit 95f410f

Please sign in to comment.