mirror of
https://github.com/kyverno/kyverno.git
synced 2025-01-20 18:52:16 +00:00
d61e0515c2
* refactor: introduce userinfo package in the cli Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * refactor: introduce api package in cli Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> --------- Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package userinfo
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/go-git/go-billy/v5"
|
|
kyvernov1beta1 "github.com/kyverno/kyverno/api/kyverno/v1beta1"
|
|
authenticationv1 "k8s.io/api/authentication/v1"
|
|
)
|
|
|
|
func TestLoad(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
fs billy.Filesystem
|
|
path string
|
|
resourcePath string
|
|
want *kyvernov1beta1.RequestInfo
|
|
wantErr bool
|
|
}{{
|
|
name: "empty",
|
|
fs: nil,
|
|
path: "",
|
|
resourcePath: "",
|
|
want: nil,
|
|
wantErr: true,
|
|
}, {
|
|
name: "invalid",
|
|
fs: nil,
|
|
path: "../_testdata/user-infos/invalid.yaml",
|
|
resourcePath: "",
|
|
want: nil,
|
|
wantErr: true,
|
|
}, {
|
|
name: "valid",
|
|
fs: nil,
|
|
path: "../_testdata/user-infos/valid.yaml",
|
|
resourcePath: "",
|
|
want: &kyvernov1beta1.RequestInfo{
|
|
ClusterRoles: []string{"cluster-admin"},
|
|
AdmissionUserInfo: authenticationv1.UserInfo{
|
|
Username: "molybdenum@somecorp.com",
|
|
},
|
|
},
|
|
wantErr: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := Load(tt.fs, tt.path, tt.resourcePath)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("Load() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("Load() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|