From d5efca1950be2016e52eb1d05589958aaf0a9321 Mon Sep 17 00:00:00 2001 From: lisenokdonbassenok Date: Tue, 13 Jan 2026 00:45:45 +0200 Subject: [PATCH] add test case --- internal/flags/flags_test.go | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/internal/flags/flags_test.go b/internal/flags/flags_test.go index 9832f67d09..599485e91a 100644 --- a/internal/flags/flags_test.go +++ b/internal/flags/flags_test.go @@ -17,8 +17,12 @@ package flags import ( + "flag" + "math/big" "runtime" "testing" + + "github.com/urfave/cli/v2" ) 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) + } +}