44 "context"
55 "fmt"
66 "testing"
7+ "time"
78
89 "github.com/golang/mock/gomock"
910 "github.com/stretchr/testify/assert"
@@ -26,6 +27,7 @@ func Test_Targets(t *testing.T) {
2627 srvExportName string
2728 srvExportNamespace string
2829 endPoints []corev1.Endpoints
30+ svc corev1.Service
2931 inDataStore bool
3032 refByServiceExport bool
3133 refByService bool
@@ -50,6 +52,13 @@ func Test_Targets(t *testing.T) {
5052 },
5153 },
5254 },
55+ svc : corev1.Service {
56+ ObjectMeta : metav1.ObjectMeta {
57+ Namespace : "ns1" ,
58+ Name : "export1" ,
59+ DeletionTimestamp : nil ,
60+ },
61+ },
5362 inDataStore : true ,
5463 refByServiceExport : true ,
5564 wantErrIsNil : true ,
@@ -72,6 +81,57 @@ func Test_Targets(t *testing.T) {
7281 },
7382 },
7483 },
84+ {
85+ name : "Delete svc and all endpoints to build spec" ,
86+ srvExportName : "export1" ,
87+ srvExportNamespace : "ns1" ,
88+ endPoints : []corev1.Endpoints {
89+ {
90+ ObjectMeta : metav1.ObjectMeta {
91+ Namespace : "ns1" ,
92+ Name : "export1" ,
93+ },
94+ Subsets : []corev1.EndpointSubset {
95+ {
96+ Addresses : []corev1.EndpointAddress {{IP : "10.10.1.1" }, {IP : "10.10.2.2" }},
97+ Ports : []corev1.EndpointPort {{Name : "a" , Port : 8675 }, {Name : "b" , Port : 309 }},
98+ },
99+ },
100+ },
101+ },
102+ svc : corev1.Service {
103+ ObjectMeta : metav1.ObjectMeta {
104+ Namespace : "ns1" ,
105+ Name : "export1" ,
106+ DeletionTimestamp : & metav1.Time {
107+ Time : time .Now (),
108+ },
109+ },
110+ },
111+ inDataStore : true ,
112+ refByServiceExport : true ,
113+ wantErrIsNil : true ,
114+ expectedTargetList : nil ,
115+ },
116+ {
117+ name : "Delete svc and no endpoints to build spec" ,
118+ srvExportName : "export1" ,
119+ srvExportNamespace : "ns1" ,
120+ endPoints : []corev1.Endpoints {},
121+ svc : corev1.Service {
122+ ObjectMeta : metav1.ObjectMeta {
123+ Namespace : "ns1" ,
124+ Name : "export1" ,
125+ DeletionTimestamp : & metav1.Time {
126+ Time : time .Now (),
127+ },
128+ },
129+ },
130+ inDataStore : true ,
131+ refByServiceExport : true ,
132+ wantErrIsNil : true ,
133+ expectedTargetList : nil ,
134+ },
75135 {
76136 name : "Endpoints without TargetGroup" ,
77137 srvExportName : "export2" ,
@@ -90,6 +150,13 @@ func Test_Targets(t *testing.T) {
90150 },
91151 },
92152 },
153+ svc : corev1.Service {
154+ ObjectMeta : metav1.ObjectMeta {
155+ Namespace : "ns1" ,
156+ Name : "export1" ,
157+ DeletionTimestamp : nil ,
158+ },
159+ },
93160 inDataStore : false ,
94161 refByServiceExport : true ,
95162 wantErrIsNil : false ,
@@ -112,6 +179,13 @@ func Test_Targets(t *testing.T) {
112179 },
113180 },
114181 },
182+ svc : corev1.Service {
183+ ObjectMeta : metav1.ObjectMeta {
184+ Namespace : "ns1" ,
185+ Name : "export1" ,
186+ DeletionTimestamp : nil ,
187+ },
188+ },
115189 inDataStore : true ,
116190 refByServiceExport : false ,
117191 refByService : false ,
@@ -124,6 +198,13 @@ func Test_Targets(t *testing.T) {
124198 inDataStore : false ,
125199 refByServiceExport : true ,
126200 wantErrIsNil : false ,
201+ svc : corev1.Service {
202+ ObjectMeta : metav1.ObjectMeta {
203+ Namespace : "ns1" ,
204+ Name : "export1" ,
205+ DeletionTimestamp : nil ,
206+ },
207+ },
127208 },
128209 {
129210 name : "Add all endpoints to build spec" ,
@@ -143,6 +224,13 @@ func Test_Targets(t *testing.T) {
143224 },
144225 },
145226 },
227+ svc : corev1.Service {
228+ ObjectMeta : metav1.ObjectMeta {
229+ Namespace : "ns1" ,
230+ Name : "export5" ,
231+ DeletionTimestamp : nil ,
232+ },
233+ },
146234 inDataStore : true ,
147235 refByService : true ,
148236 wantErrIsNil : true ,
@@ -180,6 +268,8 @@ func Test_Targets(t *testing.T) {
180268 assert .NoError (t , k8sClient .Create (ctx , tt .endPoints [0 ].DeepCopy ()))
181269 }
182270
271+ assert .NoError (t , k8sClient .Create (ctx , tt .svc .DeepCopy ()))
272+
183273 ds := latticestore .NewLatticeDataStore ()
184274
185275 if tt .inDataStore {
0 commit comments