Skip to content

Commit

Permalink
Merge pull request #1963 from dearchap/issue_1962
Browse files Browse the repository at this point in the history
Fix:(issue_1962) Fix tests failing on 32 bit architectures
  • Loading branch information
dearchap authored Aug 11, 2024
2 parents a4832fd + 2a37495 commit f21e902
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
25 changes: 12 additions & 13 deletions altsrc/yaml_file_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package altsrc_test
import (
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"testing"
Expand Down Expand Up @@ -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")

Expand All @@ -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")

Expand Down Expand Up @@ -143,7 +142,7 @@ func TestYamlFileUint64(t *testing.T) {
}{
{
"top.test",
`top:
`top:
test: 100`,
false,
},
Expand All @@ -169,7 +168,7 @@ func TestYamlFileUint64(t *testing.T) {
},
{
"test",
"test: 9223372036854775808", //uintt64
"test: 9223372036854775808", //uint64
false,
},
{
Expand All @@ -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{
Expand All @@ -207,7 +206,7 @@ func TestYamlFileUint(t *testing.T) {
}{
{
"top.test",
`top:
`top:
test: 100`,
false,
},
Expand All @@ -228,12 +227,12 @@ func TestYamlFileUint(t *testing.T) {
},
{
"test",
"test: 9223372036854775807", //int
"test: 775807", //int
false,
},
{
"test",
"test: 9223372036854775808", //uintt64
"test: 4775808", //uint64
false,
},
{
Expand All @@ -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{
Expand All @@ -271,7 +270,7 @@ func TestYamlFileInt64(t *testing.T) {
}{
{
"top.test",
`top:
`top:
test: 100`,
false,
},
Expand All @@ -297,7 +296,7 @@ func TestYamlFileInt64(t *testing.T) {
},
{
"test",
"test: 9223372036854775808", //uintt64
"test: 9223372036854775808", //uint64
true,
},
{
Expand All @@ -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{
Expand Down
10 changes: 5 additions & 5 deletions flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: .*`},
Expand Down Expand Up @@ -233,15 +233,15 @@ 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: .*`},

{"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: .*`},
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f21e902

Please sign in to comment.