regex matchstring error parsing
Signed-off-by: Anshul Ahuja <anshulahuja@microsoft.com>pull/6452/head
parent
4a28b3b16f
commit
16ec2db1f7
|
@ -53,3 +53,4 @@ tilt-resources/cloud
|
|||
# test generated files
|
||||
test/e2e/report.xml
|
||||
coverage.out
|
||||
__debug_bin*
|
|
@ -85,7 +85,10 @@ func (r *ResourceModifierRule) Apply(obj *unstructured.Unstructured, groupResour
|
|||
return nil
|
||||
}
|
||||
if r.Conditions.ResourceNameRegex != "" {
|
||||
match, _ := regexp.MatchString(r.Conditions.ResourceNameRegex, obj.GetName())
|
||||
match, err := regexp.MatchString(r.Conditions.ResourceNameRegex, obj.GetName())
|
||||
if err != nil {
|
||||
return errors.Errorf("error in matching regex %s", err.Error())
|
||||
}
|
||||
if !match {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -144,6 +144,39 @@ func TestResourceModifiers_ApplyResourceModifierRules(t *testing.T) {
|
|||
wantErr bool
|
||||
wantObj *unstructured.Unstructured
|
||||
}{
|
||||
{
|
||||
name: "Invalid Regex throws error",
|
||||
fields: fields{
|
||||
Version: "v1",
|
||||
ResourceModifierRules: []ResourceModifierRule{
|
||||
{
|
||||
Conditions: Conditions{
|
||||
GroupKind: "persistentvolumeclaims",
|
||||
ResourceNameRegex: "[a-z",
|
||||
Namespaces: []string{"foo"},
|
||||
},
|
||||
Patches: []JSONPatch{
|
||||
{
|
||||
Operation: "test",
|
||||
Path: "/spec/storageClassName",
|
||||
Value: "standard",
|
||||
},
|
||||
{
|
||||
Operation: "replace",
|
||||
Path: "/spec/storageClassName",
|
||||
Value: "premium",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
args: args{
|
||||
obj: pvcStandardSc.DeepCopy(),
|
||||
groupResource: "persistentvolumeclaims",
|
||||
},
|
||||
wantErr: true,
|
||||
wantObj: pvcStandardSc.DeepCopy(),
|
||||
},
|
||||
{
|
||||
name: "pvc with standard storage class should be patched to premium",
|
||||
fields: fields{
|
||||
|
|
Loading…
Reference in New Issue