mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
b98c0775f2
* handle nested contexts Signed-off-by: Jim Bugwadia <jim@nirmata.com> * add feature flag Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix tests Signed-off-by: Jim Bugwadia <jim@nirmata.com> * add kuttl tests Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix linter issues Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix CLI regclient Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix: token permissions on report vulns workflow (#7611) Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix: token permissions (#7619) Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix: update the flag descriptions of the reports-controller (#7617) Signed-off-by: emmanuel-ferdman <emmanuelferdman@gmail.com> * fix: panic if env var not defined (#7613) * fix: panic if env var not defined 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> * 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> * use toggles instead of a flag Signed-off-by: Jim Bugwadia <jim@nirmata.com> * update toggle name Signed-off-by: Jim Bugwadia <jim@nirmata.com> * update toggle name Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix roles Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix role Signed-off-by: Jim Bugwadia <jim@nirmata.com> * update manifests Signed-off-by: Jim Bugwadia <jim@nirmata.com> * remove extra unlock Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix loader reset Signed-off-by: Jim Bugwadia <jim@nirmata.com> * add tests Signed-off-by: Jim Bugwadia <jim@nirmata.com> * propagate context Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * cm resolver Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * level management Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * address review comments Signed-off-by: Jim Bugwadia <jim@nirmata.com> * add enableDeferredLoading to other controllers Signed-off-by: Jim Bugwadia <jim@nirmata.com> * re-enable ACR credhelper Signed-off-by: Jim Bugwadia <jim@nirmata.com> * improve tests Signed-off-by: Jim Bugwadia <jim@nirmata.com> * remove image registry client init Signed-off-by: Jim Bugwadia <jim@nirmata.com> * check for invalid reset/restore Signed-off-by: Jim Bugwadia <jim@nirmata.com> * recursive kuttl test Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * add pre/post queries Signed-off-by: Jim Bugwadia <jim@nirmata.com> * add check for a recursive match Signed-off-by: Jim Bugwadia <jim@nirmata.com> * new test suite Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * eval loaders at creation level Signed-off-by: Jim Bugwadia <jim@nirmata.com> * kuttl test Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * add an index for resolving deps in order Signed-off-by: Jim Bugwadia <jim@nirmata.com> * improve comment Signed-off-by: Jim Bugwadia <jim@nirmata.com> * extract remove method Signed-off-by: Jim Bugwadia <jim@nirmata.com> * merge main Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * flags Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * feature flag Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix flag Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * update unit tests Signed-off-by: ShutingZhao <shuting@nirmata.com> * two rules kuttl test Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * update unit tests Signed-off-by: ShutingZhao <shuting@nirmata.com> * revert Signed-off-by: ShutingZhao <shuting@nirmata.com> * per rule checkpoint 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> * fix mutate chained rules Signed-off-by: ShutingZhao <shuting@nirmata.com> * per rule checpoint/restore Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * log error Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> --------- Signed-off-by: Jim Bugwadia <jim@nirmata.com> Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Signed-off-by: emmanuel-ferdman <emmanuelferdman@gmail.com> Signed-off-by: ShutingZhao <shuting@nirmata.com> Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Co-authored-by: Emmanuel Ferdman <emmanuelferdman@gmail.com> Co-authored-by: shuting <shuting@nirmata.com>
149 lines
3.1 KiB
Go
149 lines
3.1 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"reflect"
|
|
"testing"
|
|
|
|
corev1 "k8s.io/api/core/v1"
|
|
)
|
|
|
|
type dummyResolver struct {
|
|
err error
|
|
cm *corev1.ConfigMap
|
|
}
|
|
|
|
func (c dummyResolver) Get(context.Context, string, string) (*corev1.ConfigMap, error) {
|
|
return c.cm, c.err
|
|
}
|
|
|
|
func TestNewNamespacedResourceResolver(t *testing.T) {
|
|
type args struct {
|
|
resolvers []ConfigmapResolver
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want ConfigmapResolver
|
|
wantErr bool
|
|
}{{
|
|
name: "nil shoud return an error",
|
|
wantErr: true,
|
|
}, {
|
|
name: "empty list shoud return an error",
|
|
args: args{[]ConfigmapResolver{}},
|
|
wantErr: true,
|
|
}, {
|
|
name: "one nil in the list shoud return an error",
|
|
args: args{[]ConfigmapResolver{dummyResolver{}, nil}},
|
|
wantErr: true,
|
|
}, {
|
|
name: "no nil",
|
|
args: args{[]ConfigmapResolver{dummyResolver{}, dummyResolver{}, dummyResolver{}}},
|
|
want: namespacedResourceResolverChain[*corev1.ConfigMap]{dummyResolver{}, dummyResolver{}, dummyResolver{}},
|
|
}}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := NewNamespacedResourceResolver(tt.args.resolvers...)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("NewResolverChain() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("NewResolverChain() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func Test_namespacedResourceResolverChain_Get(t *testing.T) {
|
|
type fields struct {
|
|
resolvers []ConfigmapResolver
|
|
}
|
|
type args struct {
|
|
namespace string
|
|
name string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
fields fields
|
|
args args
|
|
wantErr error
|
|
wantCm *corev1.ConfigMap
|
|
}{{
|
|
name: "Test0",
|
|
fields: fields{
|
|
resolvers: []ConfigmapResolver{
|
|
dummyResolver{},
|
|
dummyResolver{},
|
|
dummyResolver{},
|
|
},
|
|
},
|
|
}, {
|
|
name: "Test1",
|
|
fields: fields{
|
|
resolvers: []ConfigmapResolver{
|
|
dummyResolver{
|
|
err: errors.New("1"),
|
|
},
|
|
dummyResolver{
|
|
err: errors.New("2"),
|
|
},
|
|
dummyResolver{
|
|
err: errors.New("3"),
|
|
},
|
|
},
|
|
},
|
|
wantErr: errors.New("3"),
|
|
}, {
|
|
name: "Test2",
|
|
fields: fields{
|
|
resolvers: []ConfigmapResolver{
|
|
dummyResolver{
|
|
err: errors.New("1"),
|
|
},
|
|
dummyResolver{},
|
|
dummyResolver{
|
|
err: errors.New("3"),
|
|
},
|
|
},
|
|
},
|
|
}, {
|
|
name: "Test3",
|
|
fields: fields{
|
|
resolvers: []ConfigmapResolver{
|
|
dummyResolver{
|
|
err: errors.New("1"),
|
|
},
|
|
dummyResolver{
|
|
err: errors.New("2"),
|
|
},
|
|
dummyResolver{},
|
|
},
|
|
},
|
|
}}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
resolver, _ := NewNamespacedResourceResolver(tt.fields.resolvers...)
|
|
got, err := resolver.Get(context.TODO(), tt.args.namespace, tt.args.name)
|
|
if !checkError(tt.wantErr, err) {
|
|
t.Errorf("ConfigmapResolver.Get() %s error = %v, wantErr %v", tt.name, err, tt.wantErr)
|
|
}
|
|
|
|
if !reflect.DeepEqual(got, tt.wantCm) {
|
|
t.Errorf("ConfigmapResolver.Get() = %v, want %v", got, tt.wantCm)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func checkError(wantErr, err error) bool {
|
|
if wantErr != nil {
|
|
if err == nil {
|
|
return false
|
|
}
|
|
return wantErr.Error() == err.Error()
|
|
}
|
|
return err == nil
|
|
}
|