@@ -1899,9 +1899,13 @@ pub mod tests {
18991899
19001900 assert_eq ! ( snapshots. len( ) , 2 , "Test fixture should have two snapshots" ) ;
19011901
1902- // First snapshot is the parent of the second
1903- let first_snapshot_id = snapshots[ 0 ] . snapshot_id ( ) ;
1904- let second_snapshot_id = snapshots[ 1 ] . snapshot_id ( ) ;
1902+ // Determine the correct order by snapshot IDs (since validation requires to_snapshot_id > from_snapshot_id)
1903+ // Sort snapshots by snapshot_id to ensure consistent ordering
1904+ let mut snapshot_ids: Vec < i64 > = snapshots. iter ( ) . map ( |s| s. snapshot_id ( ) ) . collect ( ) ;
1905+ snapshot_ids. sort ( ) ;
1906+
1907+ let first_snapshot_id = snapshot_ids[ 0 ] ;
1908+ let second_snapshot_id = snapshot_ids[ 1 ] ;
19051909
19061910 // Create an incremental scan from first to second snapshot
19071911 let table_scan = fixture
@@ -2045,67 +2049,67 @@ pub mod tests {
20452049
20462050 // We need to set up snapshots for the remaining tests
20472051 let snapshots = table. metadata ( ) . snapshots ( ) . collect :: < Vec < _ > > ( ) ;
2048- if snapshots. len ( ) >= 2 {
2049- let first_snapshot_id = snapshots[ 0 ] . snapshot_id ( ) ;
2050- let second_snapshot_id = snapshots[ 1 ] . snapshot_id ( ) ;
2051-
2052- // Test case 3: from_snapshot_id doesn't exist but to_snapshot_id does
2053- let result = table
2054- . scan ( )
2055- . from_snapshot_id ( 999998 ) // Non-existent
2056- . to_snapshot_id ( second_snapshot_id) // Existent
2057- . build ( ) ;
2052+ assert_eq ! ( snapshots. len( ) , 2 , "Test fixture should have two snapshots" ) ;
20582053
2059- assert ! (
2060- result. is_err( ) ,
2061- "Should fail when from_snapshot_id does not exist"
2062- ) ;
2063- assert_eq ! (
2064- result. unwrap_err( ) . to_string( ) ,
2065- "DataInvalid => from_snapshot_id 999998 not found" ,
2066- "Should have correct error message for non-existent from_snapshot_id"
2067- ) ;
2054+ // Sort snapshots by snapshot_id to ensure consistent ordering
2055+ let mut snapshot_ids: Vec < i64 > = snapshots. iter ( ) . map ( |s| s. snapshot_id ( ) ) . collect ( ) ;
2056+ snapshot_ids. sort ( ) ;
20682057
2069- // Determine which snapshot is newer based on snapshot IDs
2070- let ( older_snapshot_id, newer_snapshot_id) = if first_snapshot_id < second_snapshot_id {
2071- ( first_snapshot_id, second_snapshot_id)
2072- } else {
2073- ( second_snapshot_id, first_snapshot_id)
2074- } ;
2058+ let first_snapshot_id = snapshot_ids[ 0 ] ;
2059+ let second_snapshot_id = snapshot_ids[ 1 ] ;
20752060
2076- // Test case 4: Reversed snapshot order ( to_snapshot_id <= from_snapshot_id)
2077- let result = table
2078- . scan ( )
2079- . from_snapshot_id ( newer_snapshot_id ) // Later snapshot
2080- . to_snapshot_id ( older_snapshot_id ) // Earlier snapshot
2081- . build ( ) ;
2061+ // Test case 3: from_snapshot_id doesn't exist but to_snapshot_id does
2062+ let result = table
2063+ . scan ( )
2064+ . from_snapshot_id ( 999998 ) // Non-existent
2065+ . to_snapshot_id ( second_snapshot_id ) // Existent
2066+ . build ( ) ;
20822067
2083- assert ! (
2084- result. is_err( ) ,
2085- "Should fail when to_snapshot_id <= from_snapshot_id "
2086- ) ;
2087- assert_eq ! (
2088- result. unwrap_err( ) . to_string( ) ,
2089- "DataInvalid => to_snapshot_id must be greater than from_snapshot_id " ,
2090- "Should have correct error message for reversed snapshot order "
2091- ) ;
2068+ assert ! (
2069+ result. is_err( ) ,
2070+ "Should fail when from_snapshot_id does not exist "
2071+ ) ;
2072+ assert_eq ! (
2073+ result. unwrap_err( ) . to_string( ) ,
2074+ "DataInvalid => from_snapshot_id 999998 not found " ,
2075+ "Should have correct error message for non-existent from_snapshot_id "
2076+ ) ;
20922077
2093- // Test case 5: Equal snapshot IDs (empty range)
2094- let result = table
2095- . scan ( )
2096- . from_snapshot_id ( older_snapshot_id)
2097- . to_snapshot_id ( older_snapshot_id)
2098- . build ( ) ;
2078+ // Determine which snapshot is newer based on snapshot IDs
2079+ let ( older_snapshot_id, newer_snapshot_id) = ( first_snapshot_id, second_snapshot_id) ;
20992080
2100- assert ! (
2101- result. is_err( ) ,
2102- "Should fail when from_snapshot_id == to_snapshot_id"
2103- ) ;
2104- assert_eq ! (
2105- result. unwrap_err( ) . to_string( ) ,
2106- "DataInvalid => to_snapshot_id must be greater than from_snapshot_id" ,
2107- "Should have correct error message for equal snapshot IDs"
2108- ) ;
2109- }
2081+ // Test case 4: Reversed snapshot order (to_snapshot_id <= from_snapshot_id)
2082+ let result = table
2083+ . scan ( )
2084+ . from_snapshot_id ( newer_snapshot_id) // Later snapshot
2085+ . to_snapshot_id ( older_snapshot_id) // Earlier snapshot
2086+ . build ( ) ;
2087+
2088+ assert ! (
2089+ result. is_err( ) ,
2090+ "Should fail when to_snapshot_id <= from_snapshot_id"
2091+ ) ;
2092+ assert_eq ! (
2093+ result. unwrap_err( ) . to_string( ) ,
2094+ "DataInvalid => to_snapshot_id must be greater than from_snapshot_id" ,
2095+ "Should have correct error message for reversed snapshot order"
2096+ ) ;
2097+
2098+ // Test case 5: Equal snapshot IDs (empty range)
2099+ let result = table
2100+ . scan ( )
2101+ . from_snapshot_id ( older_snapshot_id)
2102+ . to_snapshot_id ( older_snapshot_id)
2103+ . build ( ) ;
2104+
2105+ assert ! (
2106+ result. is_err( ) ,
2107+ "Should fail when from_snapshot_id == to_snapshot_id"
2108+ ) ;
2109+ assert_eq ! (
2110+ result. unwrap_err( ) . to_string( ) ,
2111+ "DataInvalid => to_snapshot_id must be greater than from_snapshot_id" ,
2112+ "Should have correct error message for equal snapshot IDs"
2113+ ) ;
21102114 }
21112115}
0 commit comments