@@ -599,6 +599,103 @@ var _ = Describe("Aggregations", func() {
599599 Expect (err ).NotTo (HaveOccurred ())
600600 Expect (res ).To (BeEmpty ())
601601 })
602+
603+ It ("should evaluate an update with demux expressions that set the object name" , func () {
604+ obj := object .NewViewObject ("view" )
605+ // must have a valid name
606+ object .SetContent (obj , unstruct {
607+ "spec" : unstruct {
608+ "list" : []any {"a" , "b" , "c" },
609+ },
610+ })
611+ object .SetName (obj , "default" , "name" )
612+
613+ jsonData := `{"@aggregate":[{"@unwind": "$.spec.list"},{"@project":{"metadata":{"name":"$.spec.list"}}}]}`
614+ ag := newAggregation (eng , []byte (jsonData ))
615+ Expect (ag .Expressions ).To (HaveLen (2 ))
616+
617+ res , err := ag .Evaluate (cache.Delta {Type : cache .Upserted , Object : obj })
618+ Expect (err ).NotTo (HaveOccurred ())
619+ Expect (res ).To (HaveLen (3 ))
620+
621+ Expect (res [0 ].Type ).To (Equal (cache .Added ))
622+ Expect (res [0 ].Object ).To (Equal (& unstructured.Unstructured {
623+ Object : unstruct {
624+ "apiVersion" : "view.dcontroller.io/v1alpha1" ,
625+ "kind" : "view" ,
626+ "metadata" : unstruct {
627+ "name" : "a" ,
628+ },
629+ },
630+ }))
631+
632+ Expect (res [1 ].Type ).To (Equal (cache .Added ))
633+ Expect (res [1 ].Object ).To (Equal (& unstructured.Unstructured {
634+ Object : unstruct {
635+ "apiVersion" : "view.dcontroller.io/v1alpha1" ,
636+ "kind" : "view" ,
637+ "metadata" : unstruct {
638+ "name" : "b" ,
639+ },
640+ },
641+ }))
642+
643+ Expect (res [2 ].Type ).To (Equal (cache .Added ))
644+ Expect (res [2 ].Object ).To (Equal (& unstructured.Unstructured {
645+ Object : unstruct {
646+ "apiVersion" : "view.dcontroller.io/v1alpha1" ,
647+ "kind" : "view" ,
648+ "metadata" : unstruct {
649+ "name" : "c" ,
650+ },
651+ },
652+ }))
653+
654+ // update the list
655+ object .SetContent (obj , unstruct {
656+ "spec" : unstruct {
657+ "list" : []any {"c" , "d" },
658+ },
659+ })
660+ object .SetName (obj , "default" , "name" )
661+
662+ res , err = ag .Evaluate (cache.Delta {Type : cache .Upserted , Object : obj })
663+ Expect (err ).NotTo (HaveOccurred ())
664+ Expect (res ).To (HaveLen (3 ))
665+
666+ Expect (res [0 ].Type ).To (Equal (cache .Deleted ))
667+ Expect (res [0 ].Object ).To (Equal (& unstructured.Unstructured {
668+ Object : unstruct {
669+ "apiVersion" : "view.dcontroller.io/v1alpha1" ,
670+ "kind" : "view" ,
671+ "metadata" : unstruct {
672+ "name" : "a" ,
673+ },
674+ },
675+ }))
676+
677+ Expect (res [1 ].Type ).To (Equal (cache .Deleted ))
678+ Expect (res [1 ].Object ).To (Equal (& unstructured.Unstructured {
679+ Object : unstruct {
680+ "apiVersion" : "view.dcontroller.io/v1alpha1" ,
681+ "kind" : "view" ,
682+ "metadata" : unstruct {
683+ "name" : "b" ,
684+ },
685+ },
686+ }))
687+
688+ Expect (res [2 ].Type ).To (Equal (cache .Added ))
689+ Expect (res [2 ].Object ).To (Equal (& unstructured.Unstructured {
690+ Object : unstruct {
691+ "apiVersion" : "view.dcontroller.io/v1alpha1" ,
692+ "kind" : "view" ,
693+ "metadata" : unstruct {
694+ "name" : "d" ,
695+ },
696+ },
697+ }))
698+ })
602699 })
603700})
604701
0 commit comments