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:
parent
1eb67422ef
commit
870462cc6d
2 changed files with 51 additions and 0 deletions
3
.github/workflows/codecov.yaml
vendored
3
.github/workflows/codecov.yaml
vendored
|
@ -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
48
pkg/utils/os/env_test.go
Normal 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))
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue