1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

chore: add unit tests for pkg/utils/os (#4509)

* 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>
This commit is contained in:
Charles-Edouard Brétéché 2022-09-06 09:19:29 +02:00 committed by GitHub
parent 1eb67422ef
commit 870462cc6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 0 deletions

View file

@ -22,6 +22,9 @@ jobs:
- name: Checkout
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2.4.0
- name: Unshallow
run: git fetch --prune --unshallow
- uses: actions/setup-go@424fc82d43fa5a37540bae62709ddcc23d9520d4 # v2.1.5
with:
go-version: '1.18'

48
pkg/utils/os/env_test.go Normal file
View file

@ -0,0 +1,48 @@
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))
})
}
}