From bd87fe5f0a5e7f143562066e239f1e561ab60d00 Mon Sep 17 00:00:00 2001 From: Naveen Gogineni Date: Sun, 11 Aug 2024 08:21:31 -0400 Subject: [PATCH 1/2] Fix:(issue_1962) Fix tests failing on 32 bit architectures --- altsrc/yaml_file_loader_test.go | 21 ++++++++++----------- flag_test.go | 10 +++++----- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/altsrc/yaml_file_loader_test.go b/altsrc/yaml_file_loader_test.go index ce6918917a..26bf21725a 100644 --- a/altsrc/yaml_file_loader_test.go +++ b/altsrc/yaml_file_loader_test.go @@ -3,7 +3,6 @@ package altsrc_test import ( "errors" "fmt" - "io/ioutil" "log" "os" "testing" @@ -90,7 +89,7 @@ func ExampleApp_Run_yamlFileLoaderDuration() { } func TestYamlFileInt64Slice(t *testing.T) { - _ = ioutil.WriteFile("current.yaml", []byte(`top: + _ = os.WriteFile("current.yaml", []byte(`top: test: [100, 9223372036854775808]`), 0666) defer os.Remove("current.yaml") @@ -110,7 +109,7 @@ func TestYamlFileInt64Slice(t *testing.T) { } func TestYamlFileStringSlice(t *testing.T) { - _ = ioutil.WriteFile("current.yaml", []byte(`top: + _ = os.WriteFile("current.yaml", []byte(`top: test: ["s1", "s2"]`), 0666) defer os.Remove("current.yaml") @@ -143,7 +142,7 @@ func TestYamlFileUint64(t *testing.T) { }{ { "top.test", - `top: + `top: test: 100`, false, }, @@ -180,7 +179,7 @@ func TestYamlFileUint64(t *testing.T) { } for i, test := range tests { - _ = ioutil.WriteFile("current.yaml", []byte(test.entry), 0666) + _ = os.WriteFile("current.yaml", []byte(test.entry), 0666) defer os.Remove("current.yaml") testFlag := []cli.Flag{ @@ -207,7 +206,7 @@ func TestYamlFileUint(t *testing.T) { }{ { "top.test", - `top: + `top: test: 100`, false, }, @@ -228,12 +227,12 @@ func TestYamlFileUint(t *testing.T) { }, { "test", - "test: 9223372036854775807", //int + "test: 775807", //int false, }, { "test", - "test: 9223372036854775808", //uintt64 + "test: 4775808", //uintt64 false, }, { @@ -244,7 +243,7 @@ func TestYamlFileUint(t *testing.T) { } for i, test := range tests { - _ = ioutil.WriteFile("current.yaml", []byte(test.entry), 0666) + _ = os.WriteFile("current.yaml", []byte(test.entry), 0666) defer os.Remove("current.yaml") testFlag := []cli.Flag{ @@ -271,7 +270,7 @@ func TestYamlFileInt64(t *testing.T) { }{ { "top.test", - `top: + `top: test: 100`, false, }, @@ -308,7 +307,7 @@ func TestYamlFileInt64(t *testing.T) { } for i, test := range tests { - _ = ioutil.WriteFile("current.yaml", []byte(test.entry), 0666) + _ = os.WriteFile("current.yaml", []byte(test.entry), 0666) defer os.Remove("current.yaml") testFlag := []cli.Flag{ diff --git a/flag_test.go b/flag_test.go index 4971de624f..b07e5aaf2c 100644 --- a/flag_test.go +++ b/flag_test.go @@ -199,7 +199,7 @@ func TestFlagsFromEnv(t *testing.T) { {"1", 1, &IntFlag{Name: "seconds", EnvVars: []string{"SECONDS"}}, ""}, {"08", 8, &IntFlag{Name: "seconds", EnvVars: []string{"SECONDS"}, Base: 10}, ""}, {"755", 493, &IntFlag{Name: "seconds", EnvVars: []string{"SECONDS"}, Base: 8}, ""}, - {"deadBEEF", 3735928559, &IntFlag{Name: "seconds", EnvVars: []string{"SECONDS"}, Base: 16}, ""}, + {"dBEEF", 900847, &IntFlag{Name: "seconds", EnvVars: []string{"SECONDS"}, Base: 16}, ""}, {"08", 0, &IntFlag{Name: "seconds", EnvVars: []string{"SECONDS"}, Base: 0}, `could not parse "08" as int value from environment variable "SECONDS" for flag seconds: .*`}, {"1.2", 0, &IntFlag{Name: "seconds", EnvVars: []string{"SECONDS"}}, `could not parse "1.2" as int value from environment variable "SECONDS" for flag seconds: .*`}, {"foobar", 0, &IntFlag{Name: "seconds", EnvVars: []string{"SECONDS"}}, `could not parse "foobar" as int value from environment variable "SECONDS" for flag seconds: .*`}, @@ -233,7 +233,7 @@ func TestFlagsFromEnv(t *testing.T) { {"1", uint(1), &UintFlag{Name: "seconds", EnvVars: []string{"SECONDS"}}, ""}, {"08", uint(8), &UintFlag{Name: "seconds", EnvVars: []string{"SECONDS"}, Base: 10}, ""}, {"755", uint(493), &UintFlag{Name: "seconds", EnvVars: []string{"SECONDS"}, Base: 8}, ""}, - {"deadBEEF", uint(3735928559), &UintFlag{Name: "seconds", EnvVars: []string{"SECONDS"}, Base: 16}, ""}, + {"dBEEF", uint(900847), &UintFlag{Name: "seconds", EnvVars: []string{"SECONDS"}, Base: 16}, ""}, {"08", 0, &UintFlag{Name: "seconds", EnvVars: []string{"SECONDS"}, Base: 0}, `could not parse "08" as uint value from environment variable "SECONDS" for flag seconds: .*`}, {"1.2", 0, &UintFlag{Name: "seconds", EnvVars: []string{"SECONDS"}}, `could not parse "1.2" as uint value from environment variable "SECONDS" for flag seconds: .*`}, {"foobar", 0, &UintFlag{Name: "seconds", EnvVars: []string{"SECONDS"}}, `could not parse "foobar" as uint value from environment variable "SECONDS" for flag seconds: .*`}, @@ -241,7 +241,7 @@ func TestFlagsFromEnv(t *testing.T) { {"1", uint64(1), &Uint64Flag{Name: "seconds", EnvVars: []string{"SECONDS"}}, ""}, {"08", uint64(8), &Uint64Flag{Name: "seconds", EnvVars: []string{"SECONDS"}, Base: 10}, ""}, {"755", uint64(493), &Uint64Flag{Name: "seconds", EnvVars: []string{"SECONDS"}, Base: 8}, ""}, - {"deadBEEF", uint64(3735928559), &Uint64Flag{Name: "seconds", EnvVars: []string{"SECONDS"}, Base: 16}, ""}, + {"dBEEF", uint64(900847), &Uint64Flag{Name: "seconds", EnvVars: []string{"SECONDS"}, Base: 16}, ""}, {"08", 0, &Uint64Flag{Name: "seconds", EnvVars: []string{"SECONDS"}, Base: 0}, `could not parse "08" as uint64 value from environment variable "SECONDS" for flag seconds: .*`}, {"1.2", 0, &Uint64Flag{Name: "seconds", EnvVars: []string{"SECONDS"}}, `could not parse "1.2" as uint64 value from environment variable "SECONDS" for flag seconds: .*`}, {"foobar", 0, &Uint64Flag{Name: "seconds", EnvVars: []string{"SECONDS"}}, `could not parse "foobar" as uint64 value from environment variable "SECONDS" for flag seconds: .*`}, @@ -1489,8 +1489,8 @@ var uintSliceFlagTests = []struct { }{ {"heads", nil, NewUintSlice(), "--heads value [ --heads value ]\t"}, {"H", nil, NewUintSlice(), "-H value [ -H value ]\t"}, - {"heads", []string{"H"}, NewUintSlice(uint(2), uint(17179869184)), - "--heads value, -H value [ --heads value, -H value ]\t(default: 2, 17179869184)"}, + {"heads", []string{"H"}, NewUintSlice(uint(2), uint(79869184)), + "--heads value, -H value [ --heads value, -H value ]\t(default: 2, 79869184)"}, } func TestUintSliceFlagHelpOutput(t *testing.T) { From 2a3749594ec405241af5714faf0e5429a4d85701 Mon Sep 17 00:00:00 2001 From: Naveen Gogineni Date: Sun, 11 Aug 2024 09:02:20 -0400 Subject: [PATCH 2/2] uintt64 -> unint64 --- altsrc/yaml_file_loader_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/altsrc/yaml_file_loader_test.go b/altsrc/yaml_file_loader_test.go index 26bf21725a..d8a1db9fb8 100644 --- a/altsrc/yaml_file_loader_test.go +++ b/altsrc/yaml_file_loader_test.go @@ -168,7 +168,7 @@ func TestYamlFileUint64(t *testing.T) { }, { "test", - "test: 9223372036854775808", //uintt64 + "test: 9223372036854775808", //uint64 false, }, { @@ -232,7 +232,7 @@ func TestYamlFileUint(t *testing.T) { }, { "test", - "test: 4775808", //uintt64 + "test: 4775808", //uint64 false, }, { @@ -296,7 +296,7 @@ func TestYamlFileInt64(t *testing.T) { }, { "test", - "test: 9223372036854775808", //uintt64 + "test: 9223372036854775808", //uint64 true, }, {