|
38 | 38 | xrWithStatus = `{"apiVersion":"example.org/v1","kind":"XR","metadata":{"name":"cool-xr"},"spec":{"count":2},"status":{"ready":"true"}}` |
39 | 39 | xrWithNestedStatusFoo = `{"apiVersion":"example.org/v1","kind":"XR","metadata":{"name":"cool-xr"},"spec":{"count":2},"status":{"state":{"foo":"bar"}}}` |
40 | 40 | xrWithNestedStatusBaz = `{"apiVersion":"example.org/v1","kind":"XR","metadata":{"name":"cool-xr"},"spec":{"count":2},"status":{"state":{"baz":"qux"}}}` |
| 41 | + xrRecursiveTmpl = `{"apiVersion":"example.org/v1","kind":"XR","metadata":{"annotations":{"gotemplating.fn.crossplane.io/composition-resource-name":"recursive-xr"},"name":"recursive-xr","labels":{"belongsTo":{{.observed.composite.resource.metadata.name|quote}}}},"spec":{"count":2}}` |
41 | 42 |
|
42 | 43 | extraResources = `{"apiVersion":"meta.gotemplating.fn.crossplane.io/v1alpha1","kind":"ExtraResources","requirements":{"cool-extra-resource":{"apiVersion":"example.org/v1","kind":"CoolExtraResource","matchName":"cool-extra-resource"}}} |
43 | 44 | {"apiVersion":"meta.gotemplating.fn.crossplane.io/v1alpha1","kind":"ExtraResources","requirements":{"another-cool-extra-resource":{"apiVersion":"example.org/v1","kind":"CoolExtraResource","matchLabels":{"key": "value"}},"yet-another-cool-extra-resource":{"apiVersion":"example.org/v1","kind":"CoolExtraResource","matchName":"foo"}}} |
@@ -381,6 +382,44 @@ func TestRunFunction(t *testing.T) { |
381 | 382 | }, |
382 | 383 | }, |
383 | 384 | }, |
| 385 | + "ResponseIsReturnedWithTemplatedXR": { |
| 386 | + reason: "The Function should return the desired composite resource and the composed templated XR resource.", |
| 387 | + args: args{ |
| 388 | + req: &fnv1beta1.RunFunctionRequest{ |
| 389 | + Meta: &fnv1beta1.RequestMeta{Tag: "status"}, |
| 390 | + Input: resource.MustStructObject( |
| 391 | + &v1beta1.GoTemplate{ |
| 392 | + Source: v1beta1.InlineSource, |
| 393 | + Inline: &v1beta1.TemplateSourceInline{Template: xrRecursiveTmpl}, |
| 394 | + }), |
| 395 | + Observed: &fnv1beta1.State{ |
| 396 | + Composite: &fnv1beta1.Resource{ |
| 397 | + Resource: resource.MustStructJSON(xr), |
| 398 | + }, |
| 399 | + }, |
| 400 | + Desired: &fnv1beta1.State{ |
| 401 | + Composite: &fnv1beta1.Resource{ |
| 402 | + Resource: resource.MustStructJSON(xr), |
| 403 | + }, |
| 404 | + }, |
| 405 | + }, |
| 406 | + }, |
| 407 | + want: want{ |
| 408 | + rsp: &fnv1beta1.RunFunctionResponse{ |
| 409 | + Meta: &fnv1beta1.ResponseMeta{Tag: "status", Ttl: durationpb.New(response.DefaultTTL)}, |
| 410 | + Desired: &fnv1beta1.State{ |
| 411 | + Composite: &fnv1beta1.Resource{ |
| 412 | + Resource: resource.MustStructJSON(xr), |
| 413 | + }, |
| 414 | + Resources: map[string]*fnv1beta1.Resource{ |
| 415 | + "recursive-xr": { |
| 416 | + Resource: resource.MustStructJSON(`{"apiVersion": "example.org/v1","kind":"XR","metadata":{"annotations":{},"name":"recursive-xr","labels":{"belongsTo":"cool-xr"}},"spec":{"count":2}}`), |
| 417 | + }, |
| 418 | + }, |
| 419 | + }, |
| 420 | + }, |
| 421 | + }, |
| 422 | + }, |
384 | 423 | "ResponseIsReturnedWithTemplatingFS": { |
385 | 424 | reason: "The Function should return the desired composite resource and the templated composed resources with FileSystem cd.", |
386 | 425 | args: args{ |
|
0 commit comments