@@ -103,7 +103,14 @@ var _ = Describe("Collector", Ordered, func() {
103
103
Replicas : & replicas ,
104
104
},
105
105
ObjectMeta : metav1.ObjectMeta {
106
- UID : "test-pod-owner-uid" ,
106
+ Name : "replica" ,
107
+ OwnerReferences : []metav1.OwnerReference {
108
+ {
109
+ Kind : "Deployment" ,
110
+ Name : "Deployment1" ,
111
+ UID : "test-uid-replicaSet" ,
112
+ },
113
+ },
107
114
},
108
115
}
109
116
@@ -129,7 +136,7 @@ var _ = Describe("Collector", Ordered, func() {
129
136
ClusterID : string (kubeNamespace .GetUID ()),
130
137
ImageSource : "local" ,
131
138
Arch : runtime .GOARCH ,
132
- DeploymentID : string (ngfPod .OwnerReferences [0 ].UID ),
139
+ DeploymentID : string (ngfReplicaSet . ObjectMeta .OwnerReferences [0 ].UID ),
133
140
}
134
141
135
142
k8sClientReader = & eventsfakes.FakeReader {}
@@ -589,26 +596,68 @@ var _ = Describe("Collector", Ordered, func() {
589
596
_ , err := dataCollector .Collect (ctx )
590
597
Expect (err ).To (MatchError (expectedErr ))
591
598
})
592
- It ("should error if the replicaSet's UID is empty" , func () {
593
- ngfPod = & v1.Pod {
594
- ObjectMeta : metav1.ObjectMeta {
595
- Name : "pod1" ,
596
- OwnerReferences : []metav1.OwnerReference {
597
- {
598
- Kind : "ReplicaSet" ,
599
- Name : "replicaset1" ,
599
+ })
600
+ })
601
+ })
602
+
603
+ Describe ("DeploymentID collector" , func () {
604
+ When ("collecting deploymentID" , func () {
605
+ When ("it encounters an error while collecting data" , func () {
606
+ It ("should error if the replicaSet's owner reference is nil" , func () {
607
+ replicas := int32 (1 )
608
+ k8sClientReader .GetCalls (mergeGetCallsWithBase (createGetCallsFunc (
609
+ & appsv1.ReplicaSet {
610
+ Spec : appsv1.ReplicaSetSpec {
611
+ Replicas : & replicas ,
612
+ },
613
+ },
614
+ )))
615
+
616
+ expectedErr := errors .New ("expected one owner reference of the NGF ReplicaSet, got 0" )
617
+ _ , err := dataCollector .Collect (ctx )
618
+ Expect (err ).To (MatchError (expectedErr ))
619
+ })
620
+
621
+ It ("should error if the replicaSet's owner reference kind is not deployment" , func () {
622
+ replicas := int32 (1 )
623
+ k8sClientReader .GetCalls (mergeGetCallsWithBase (createGetCallsFunc (
624
+ & appsv1.ReplicaSet {
625
+ Spec : appsv1.ReplicaSetSpec {
626
+ Replicas : & replicas ,
627
+ },
628
+ ObjectMeta : metav1.ObjectMeta {
629
+ OwnerReferences : []metav1.OwnerReference {
630
+ {
631
+ Name : "replica" ,
632
+ Kind : "ReplicaSet" ,
633
+ UID : "replica-uid" ,
634
+ },
600
635
},
601
636
},
602
637
},
603
- }
638
+ )))
604
639
640
+ expectedErr := errors .New ("expected replicaSet owner reference to be Deployment, got ReplicaSet" )
641
+ _ , err := dataCollector .Collect (ctx )
642
+ Expect (err ).To (MatchError (expectedErr ))
643
+ })
644
+ It ("should error if the replicaSet's owner reference has empty UID" , func () {
605
645
replicas := int32 (1 )
606
- ngfReplicaSet = & appsv1.ReplicaSet {
607
- Spec : appsv1.ReplicaSetSpec {
608
- Replicas : & replicas ,
646
+ k8sClientReader .GetCalls (mergeGetCallsWithBase (createGetCallsFunc (
647
+ & appsv1.ReplicaSet {
648
+ Spec : appsv1.ReplicaSetSpec {
649
+ Replicas : & replicas ,
650
+ },
651
+ ObjectMeta : metav1.ObjectMeta {
652
+ OwnerReferences : []metav1.OwnerReference {
653
+ {
654
+ Name : "replica" ,
655
+ Kind : "Deployment" ,
656
+ },
657
+ },
658
+ },
609
659
},
610
- }
611
- k8sClientReader .GetCalls (createGetCallsFunc (ngfPod , ngfReplicaSet ))
660
+ )))
612
661
613
662
expectedErr := errors .New ("expected replicaSet to have a UID" )
614
663
_ , err := dataCollector .Collect (ctx )
0 commit comments