1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 16:06:56 +00:00
kyverno/pkg/utils/os/env_test.go

49 lines
720 B
Go
Raw Normal View History

package os
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetEnvWithFallback(t *testing.T) {
type args struct {
name string
fallback string
}
tests := []struct {
name string
setup map[string]string
args args
want string
}{
{
name: "fallback",
args: args{
"xxx",
"yyy",
},
want: "yyy",
},
{
name: "no fallback",
setup: map[string]string{
"xxx": "zzz",
},
args: args{
"xxx",
"yyy",
},
want: "zzz",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
for k, v := range tt.setup {
t.Setenv(k, v)
}
assert.Equal(t, tt.want, GetEnvWithFallback(tt.args.name, tt.args.fallback))
})
}
}