@@ -2729,6 +2729,99 @@ func TestRunFunction(t *testing.T) {
27292729 },
27302730 },
27312731 },
2732+ "OperationWithWatchedResourceQueryNoDriftWithExistingAnnotations" : {
2733+ reason : "The Function should set annotations on XR that notify user about lack of drift in query results and in the same time not override existing annotations" ,
2734+ args : args {
2735+ ctx : context .Background (),
2736+ req : & fnv1.RunFunctionRequest {
2737+ Meta : & fnv1.RequestMeta {Tag : "hello" },
2738+ Input : resource .MustStructJSON (`{
2739+ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1",
2740+ "kind": "Input",
2741+ "queryType": "UserValidation",
2742+ "users": ["user@example.com"],
2743+ "target": "status.validatedUsers"
2744+ }` ),
2745+ Credentials : map [string ]* fnv1.Credentials {
2746+ "azure-creds" : {
2747+ Source : & fnv1.Credentials_CredentialData {CredentialData : creds },
2748+ },
2749+ },
2750+ RequiredResources : map [string ]* fnv1.Resources {
2751+ "ops.crossplane.io/watched-resource" : {
2752+ Items : []* fnv1.Resource {
2753+ {
2754+ Resource : resource .MustStructJSON (`{
2755+ "apiVersion": "example.org/v1",
2756+ "kind": "XR",
2757+ "metadata": {
2758+ "name": "cool-xr",
2759+ "finalizers": [
2760+ "composite.apiextensions.crossplane.io"
2761+ ],
2762+ "annotations": {
2763+ "my-cool-annotation": "love-msgraph"
2764+ }
2765+ },
2766+ "spec": {
2767+ "count": 2
2768+ },
2769+ "status": {
2770+ "validatedUsers": [
2771+ {
2772+ "id": "test-user-id",
2773+ "displayName": "Test User",
2774+ "userPrincipalName": "user@example.com",
2775+ "mail": "user@example.com"
2776+ }
2777+ ]
2778+ }
2779+ }` ),
2780+ },
2781+ },
2782+ },
2783+ },
2784+ },
2785+ },
2786+ want : want {
2787+ rsp : & fnv1.RunFunctionResponse {
2788+ Meta : & fnv1.ResponseMeta {Tag : "hello" , Ttl : durationpb .New (response .DefaultTTL )},
2789+ Conditions : []* fnv1.Condition {
2790+ {
2791+ Type : "FunctionSuccess" ,
2792+ Status : fnv1 .Status_STATUS_CONDITION_TRUE ,
2793+ Reason : "Success" ,
2794+ Target : fnv1 .Target_TARGET_COMPOSITE_AND_CLAIM .Enum (),
2795+ },
2796+ },
2797+ Results : []* fnv1.Result {
2798+ {
2799+ Severity : fnv1 .Severity_SEVERITY_NORMAL ,
2800+ Message : `QueryType: "UserValidation"` ,
2801+ Target : fnv1 .Target_TARGET_COMPOSITE .Enum (),
2802+ },
2803+ },
2804+ Desired : & fnv1.State {
2805+ Resources : map [string ]* fnv1.Resource {
2806+ "xr" : {
2807+ Resource : resource .MustStructJSON (`{
2808+ "apiVersion": "example.org/v1",
2809+ "kind": "XR",
2810+ "metadata": {
2811+ "name": "cool-xr",
2812+ "annotations": {
2813+ "function-msgraph/last-execution": "2025-01-01T00:00:00+01:00",
2814+ "function-msgraph/last-execution-query-drift-detected": "false",
2815+ "my-cool-annotation": "love-msgraph"
2816+ }
2817+ }
2818+ }` ),
2819+ },
2820+ },
2821+ },
2822+ },
2823+ },
2824+ },
27322825 "OperationWithWatchedResourceQueryDrift" : {
27332826 reason : "The Function should set annotations on XR that notify user about drift in query results" ,
27342827 args : args {
0 commit comments