feat(update): make default GOLDEN_UPDATE env var check case-insensitive (#10)

This commit is contained in:
2025-03-24 12:53:34 +00:00
committed by GitHub
parent 8f4d3d4170
commit 6817ec6101
2 changed files with 31 additions and 2 deletions

View File

@@ -1,6 +1,9 @@
package golden
import "os"
import (
"os"
"strings"
)
var truthyStrings = []string{"1", "y", "t", "yes", "on", "true"}
@@ -14,7 +17,7 @@ type UpdateFunc func() bool
func EnvUpdateFunc() bool {
env := os.Getenv("GOLDEN_UPDATE")
for _, v := range truthyStrings {
if env == v {
if strings.EqualFold(env, v) {
return true
}
}

View File

@@ -90,6 +90,32 @@ var envUpdateFuncTestCases = []struct {
env: map[string]string{"GOLDEN_UPDATE": "foobarnopebbq"},
want: false,
},
// Case-insensitive test cases
{
name: "GOLDEN_UPDATE set to Y (uppercase)",
env: map[string]string{"GOLDEN_UPDATE": "Y"},
want: true,
},
{
name: "GOLDEN_UPDATE set to TRUE (uppercase)",
env: map[string]string{"GOLDEN_UPDATE": "TRUE"},
want: true,
},
{
name: "GOLDEN_UPDATE set to Yes (mixed case)",
env: map[string]string{"GOLDEN_UPDATE": "Yes"},
want: true,
},
{
name: "GOLDEN_UPDATE set to ON (uppercase)",
env: map[string]string{"GOLDEN_UPDATE": "ON"},
want: true,
},
{
name: "GOLDEN_UPDATE set to TrUe (mixed case)",
env: map[string]string{"GOLDEN_UPDATE": "TrUe"},
want: true,
},
}
func TestEnvUpdateFunc(t *testing.T) {