|
1 | 1 | package main
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "encoding/json" |
5 | 4 | "testing"
|
6 | 5 |
|
7 | 6 | "github.com/google/go-cmp/cmp"
|
8 | 7 | "github.com/pkg/errors"
|
9 | 8 | extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
10 | 9 | "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
11 | 10 | "k8s.io/apimachinery/pkg/runtime"
|
| 11 | + "k8s.io/apimachinery/pkg/util/json" |
12 | 12 | "k8s.io/utils/ptr"
|
13 | 13 |
|
14 | 14 | "github.com/crossplane/crossplane-runtime/pkg/fieldpath"
|
@@ -195,6 +195,78 @@ func TestApplyFromFieldPathPatch(t *testing.T) {
|
195 | 195 | err: errors.Errorf(errFmtExpandingArrayFieldPaths, "metadata.ownerReferences[*].badField"),
|
196 | 196 | },
|
197 | 197 | },
|
| 198 | + "ValidToFieldPathWithWildcardsAndMergePolicy": { |
| 199 | + reason: "When passed a wildcarded path with appendSlice policy, appends the from field slice items to each of the expanded array field, with slice deduplication", |
| 200 | + args: args{ |
| 201 | + p: &v1beta1.ComposedPatch{ |
| 202 | + Type: v1beta1.PatchTypeFromCompositeFieldPath, |
| 203 | + Patch: v1beta1.Patch{ |
| 204 | + FromFieldPath: ptr.To[string]("spec.parameters.allowedGroups"), |
| 205 | + ToFieldPath: ptr.To[string]("spec.forProvider.accessRules[*].allowedGroups"), |
| 206 | + Policy: &v1beta1.PatchPolicy{ |
| 207 | + ToFieldPath: ptr.To(v1beta1.ToFieldPathPolicyForceMergeObjectsAppendArrays), |
| 208 | + }, |
| 209 | + }, |
| 210 | + }, |
| 211 | + from: &composite.Unstructured{ |
| 212 | + Unstructured: unstructured.Unstructured{Object: MustObject(`{ |
| 213 | + "apiVersion": "test.crossplane.io/v1", |
| 214 | + "kind": "XR", |
| 215 | + "spec": { |
| 216 | + "parameters": { |
| 217 | + "allowedGroups": [12345678, 7891234] |
| 218 | + } |
| 219 | + } |
| 220 | + }`)}, |
| 221 | + }, |
| 222 | + to: &composed.Unstructured{ |
| 223 | + Unstructured: unstructured.Unstructured{Object: MustObject(`{ |
| 224 | + "apiVersion": "test.crossplane.io/v1", |
| 225 | + "kind": "Composed", |
| 226 | + "spec": { |
| 227 | + "forProvider": { |
| 228 | + "accessRules": [ |
| 229 | + { |
| 230 | + "action": "Allow", |
| 231 | + "destination": "e1", |
| 232 | + "allowedGroups": [12345678] |
| 233 | + }, |
| 234 | + { |
| 235 | + "action": "Allow", |
| 236 | + "destination": "e2", |
| 237 | + "allowedGroups": [12345678] |
| 238 | + } |
| 239 | + ] |
| 240 | + } |
| 241 | + } |
| 242 | + }`)}, |
| 243 | + }, |
| 244 | + }, |
| 245 | + want: want{ |
| 246 | + to: &composed.Unstructured{ |
| 247 | + Unstructured: unstructured.Unstructured{Object: MustObject(`{ |
| 248 | + "apiVersion": "test.crossplane.io/v1", |
| 249 | + "kind": "Composed", |
| 250 | + "spec": { |
| 251 | + "forProvider": { |
| 252 | + "accessRules": [ |
| 253 | + { |
| 254 | + "action": "Allow", |
| 255 | + "destination": "e1", |
| 256 | + "allowedGroups": [12345678, 7891234] |
| 257 | + }, |
| 258 | + { |
| 259 | + "action": "Allow", |
| 260 | + "destination": "e2", |
| 261 | + "allowedGroups": [12345678, 7891234] |
| 262 | + } |
| 263 | + ] |
| 264 | + } |
| 265 | + } |
| 266 | + }`)}, |
| 267 | + }, |
| 268 | + }, |
| 269 | + }, |
198 | 270 | "DefaultToFieldCompositeFieldPathPatch": {
|
199 | 271 | reason: "Should correctly default the ToFieldPath value if not specified.",
|
200 | 272 | args: args{
|
|
0 commit comments