|
| 1 | +use insta::glob; |
| 2 | +use kube::core::response::StatusSummary; |
| 3 | + |
| 4 | +use crate::person::{Person, PersonVersion}; |
| 5 | + |
| 6 | +mod person; |
| 7 | + |
| 8 | +#[test] |
| 9 | +fn person_v3_v1alpha1_v3() { |
| 10 | + glob!("./inputs/roundtrip", "*.json", |path| { |
| 11 | + // Convert from v3 to v1alpha1 |
| 12 | + // NOTE (@Techassi): It should be noted that the input conversion review |
| 13 | + // contains a status with empty changedValues to be able to assert_eq |
| 14 | + // the objects at the end. As mentioned in the actual macro code, we |
| 15 | + // should avoid "polluting" the status if it is empty. |
| 16 | + let (request_v1alpha1, response_v1alpha1) = person::convert_via_file(path); |
| 17 | + let response = response_v1alpha1 |
| 18 | + .response |
| 19 | + .as_ref() |
| 20 | + .expect("v1alpha1 review must have a response"); |
| 21 | + |
| 22 | + assert_eq!(response.result.status, Some(StatusSummary::Success)); |
| 23 | + |
| 24 | + // Construct the roundtrip review |
| 25 | + let roundtrip_review = |
| 26 | + person::roundtrip_conversion_review(response_v1alpha1, PersonVersion::V3); |
| 27 | + |
| 28 | + // Convert back to v3 from v1alpha1 |
| 29 | + let response_v3 = Person::try_convert(roundtrip_review); |
| 30 | + let response = response_v3 |
| 31 | + .response |
| 32 | + .as_ref() |
| 33 | + .expect("v3 review must have a response"); |
| 34 | + |
| 35 | + assert_eq!(response.result.status, Some(StatusSummary::Success)); |
| 36 | + |
| 37 | + // Now let compare the object how it started out with the object which |
| 38 | + // was produced through the conversion roundtrip. They must match. |
| 39 | + let original_object = request_v1alpha1 |
| 40 | + .request |
| 41 | + .as_ref() |
| 42 | + .expect("v1alpha1 review must have a request") |
| 43 | + .objects |
| 44 | + .first() |
| 45 | + .expect("there must be at least one object"); |
| 46 | + |
| 47 | + let converted_object = response |
| 48 | + .converted_objects |
| 49 | + .first() |
| 50 | + .expect("there must be at least one object"); |
| 51 | + |
| 52 | + assert_eq!(original_object, converted_object); |
| 53 | + }); |
| 54 | +} |
0 commit comments