mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
870462cc6d
* chore: add unit tests for pkg/utils/os Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com> * review Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com> Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
48 lines
720 B
Go
48 lines
720 B
Go
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))
|
|
})
|
|
}
|
|
}
|