@@ -48,15 +48,15 @@ def test_with_leases_columns(self):
4848 add_display_columns (table , options )
4949
5050 columns = [col .header for col in table .columns ]
51- assert columns == ["NAME" , "LABELS" , "LEASED BY" , "LEASE STATUS" , "EXPECTED RELEASE" ]
51+ assert columns == ["NAME" , "LABELS" , "LEASED BY" , "LEASE STATUS" , "RELEASE TIME " ]
5252
5353 def test_with_all_columns (self ):
5454 table = Table ()
5555 options = WithOptions (show_online = True , show_leases = True )
5656 add_display_columns (table , options )
5757
5858 columns = [col .header for col in table .columns ]
59- assert columns == ["NAME" , "ONLINE" , "LABELS" , "LEASED BY" , "LEASE STATUS" , "EXPECTED RELEASE" ]
59+ assert columns == ["NAME" , "ONLINE" , "LABELS" , "LEASED BY" , "LEASE STATUS" , "RELEASE TIME " ]
6060
6161
6262class TestAddExporterRow :
@@ -91,7 +91,7 @@ def test_row_with_lease_info(self):
9191 add_exporter_row (table , exporter , options , lease_info )
9292
9393 assert len (table .rows ) == 1
94- assert len (table .columns ) == 5 # NAME, LABELS, LEASED BY, LEASE STATUS, EXPECTED RELEASE
94+ assert len (table .columns ) == 5 # NAME, LABELS, LEASED BY, LEASE STATUS, RELEASE TIME
9595
9696 def test_row_with_lease_info_available (self ):
9797 table = Table ()
@@ -115,21 +115,23 @@ def test_row_with_all_options(self):
115115 add_exporter_row (table , exporter , options , lease_info )
116116
117117 assert len (table .rows ) == 1
118- assert len (table .columns ) == 6 # NAME, ONLINE, LABELS, LEASED BY, LEASE STATUS, EXPECTED RELEASE
118+ assert len (table .columns ) == 6 # NAME, ONLINE, LABELS, LEASED BY, LEASE STATUS, RELEASE TIME
119119
120120
121121class TestExporterList :
122122 def create_test_lease (self , client = "test-client" , status = "Active" ,
123123 effective_begin_time = datetime (2023 , 1 , 1 , 10 , 0 , 0 ),
124124 effective_duration = timedelta (hours = 1 ),
125- begin_time = None , duration = timedelta (hours = 1 )):
125+ begin_time = None , duration = timedelta (hours = 1 ),
126+ effective_end_time = None ):
126127 lease = Mock (spec = Lease )
127128 lease .client = client
128129 lease .get_status .return_value = status
129130 lease .effective_begin_time = effective_begin_time
130131 lease .effective_duration = effective_duration
131132 lease .begin_time = begin_time
132133 lease .duration = duration
134+ lease .effective_end_time = effective_end_time
133135 return lease
134136
135137 def test_exporter_without_lease (self ):
@@ -181,7 +183,7 @@ def test_exporter_with_lease_display(self):
181183 exporter .rich_add_rows (table , options )
182184
183185 assert len (table .rows ) == 1
184- assert len (table .columns ) == 5 # NAME, LABELS, LEASED BY, LEASE STATUS, EXPECTED RELEASE
186+ assert len (table .columns ) == 5 # NAME, LABELS, LEASED BY, LEASE STATUS, RELEASE TIME
185187
186188 # Test actual table content by rendering it
187189 console = Console (file = StringIO (), width = 120 )
@@ -209,7 +211,7 @@ def test_exporter_without_lease_but_show_leases(self):
209211 exporter .rich_add_rows (table , options )
210212
211213 assert len (table .rows ) == 1
212- assert len (table .columns ) == 5 # NAME, LABELS, LEASED BY, LEASE STATUS, EXPECTED RELEASE
214+ assert len (table .columns ) == 5 # NAME, LABELS, LEASED BY, LEASE STATUS, RELEASE TIME
213215
214216 # Test actual table content by rendering it
215217 console = Console (file = StringIO (), width = 120 )
@@ -291,7 +293,7 @@ def test_exporter_all_features_display(self):
291293 exporter_offline_no_lease .rich_add_rows (table , options )
292294
293295 assert len (table .rows ) == 2
294- assert len (table .columns ) == 6 # NAME, ONLINE, LABELS, LEASED BY, LEASE STATUS, EXPECTED RELEASE
296+ assert len (table .columns ) == 6 # NAME, ONLINE, LABELS, LEASED BY, LEASE STATUS, RELEASE TIME
295297
296298 # Test actual table content by rendering it
297299 console = Console (file = StringIO (), width = 150 )
@@ -312,7 +314,11 @@ def test_exporter_all_features_display(self):
312314
313315 def test_exporter_lease_info_extraction (self ):
314316 """Test that lease information is correctly extracted from lease objects"""
315- lease = self .create_test_lease (client = "my-client" , status = "Expired" )
317+ lease = self .create_test_lease (
318+ client = "my-client" ,
319+ status = "Expired" ,
320+ effective_end_time = datetime (2023 , 1 , 1 , 11 , 0 , 0 ) # Ended after 1 hour
321+ )
316322 exporter = Exporter (
317323 namespace = "default" ,
318324 name = "test-exporter" ,
@@ -332,8 +338,16 @@ def test_exporter_lease_info_extraction(self):
332338 lease_client = exporter .lease .client
333339 lease_status = exporter .lease .get_status ()
334340 expected_release = ""
335- if exporter .lease .effective_begin_time and exporter .lease .effective_duration :
336- release_time = exporter .lease .effective_begin_time + exporter .lease .effective_duration
341+ if exporter .lease .effective_end_time :
342+ # Ended: use actual end time
343+ expected_release = exporter .lease .effective_end_time .strftime ("%Y-%m-%d %H:%M:%S" )
344+ elif exporter .lease .effective_begin_time :
345+ # Active: calculate expected end
346+ release_time = exporter .lease .effective_begin_time + exporter .lease .duration
347+ expected_release = release_time .strftime ("%Y-%m-%d %H:%M:%S" )
348+ elif exporter .lease .begin_time :
349+ # Scheduled: calculate expected end
350+ release_time = exporter .lease .begin_time + exporter .lease .duration
337351 expected_release = release_time .strftime ("%Y-%m-%d %H:%M:%S" )
338352 lease_info = (lease_client , lease_status , expected_release )
339353
@@ -384,7 +398,7 @@ def test_exporter_scheduled_lease_expected_release(self):
384398 Exporter .rich_add_columns (table , options )
385399 exporter .rich_add_rows (table , options )
386400
387- # Should have 5 columns: NAME, LABELS, LEASED BY, LEASE STATUS, EXPECTED RELEASE
401+ # Should have 5 columns: NAME, LABELS, LEASED BY, LEASE STATUS, RELEASE TIME
388402 assert len (table .columns ) == 5
389403 assert len (table .rows ) == 1
390404
0 commit comments