add test case

This commit is contained in:
lisenokdonbassenok 2026-01-13 00:45:45 +02:00 committed by GitHub
parent 07f5030e50
commit d5efca1950
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -17,8 +17,12 @@
package flags package flags
import ( import (
"flag"
"math/big"
"runtime" "runtime"
"testing" "testing"
"github.com/urfave/cli/v2"
) )
func TestPathExpansion(t *testing.T) { func TestPathExpansion(t *testing.T) {
@ -61,3 +65,39 @@ func TestPathExpansion(t *testing.T) {
}) })
} }
} }
func TestBigFlagEnvValuePreserved(t *testing.T) {
// Prepare a BigFlag with a non-zero default and an environment override.
const envVar = "GETH_TEST_BIGFLAG"
initialDefault := big.NewInt(123)
bf := &BigFlag{
Name: "test.bigflag",
Value: new(big.Int).Set(initialDefault),
EnvVars: []string{envVar},
}
t.Setenv(envVar, "0x10")
fs := flag.NewFlagSet("test", flag.ContinueOnError)
if err := bf.Apply(fs); err != nil {
t.Fatalf("Apply failed: %v", err)
}
app := cli.NewApp()
ctx := cli.NewContext(app, fs, nil)
got := GlobalBig(ctx, bf.Name)
if got == nil {
t.Fatalf("GlobalBig returned nil")
}
expected := big.NewInt(16)
if got.Cmp(expected) != 0 {
t.Fatalf("GlobalBig = %v, want %v", got, expected)
}
if !bf.HasBeenSet {
t.Fatalf("BigFlag.HasBeenSet = false, want true")
}
if bf.defaultValue == nil || bf.defaultValue.Cmp(initialDefault) != 0 {
t.Fatalf("defaultValue = %v, want %v", bf.defaultValue, initialDefault)
}
}