@@ -3,7 +3,7 @@ use std::{borrow::Cow, cmp::Ordering};
33use indoc:: formatdoc;
44use itertools:: Itertools as _;
55use proc_macro2:: TokenStream ;
6- use quote:: quote;
6+ use quote:: { format_ident , quote} ;
77use syn:: parse_quote;
88
99use crate :: {
@@ -530,6 +530,71 @@ impl Struct {
530530 } )
531531 }
532532
533+ pub ( super ) fn generate_conversion_roundtrip_test (
534+ & self ,
535+ versions : & [ VersionDefinition ] ,
536+ mod_gen_ctx : ModuleGenerationContext < ' _ > ,
537+ spec_gen_ctx : & SpecGenerationContext < ' _ > ,
538+ ) -> TokenStream {
539+ let versioned_path = & * mod_gen_ctx. crates . versioned ;
540+ let struct_ident = & self . common . idents . original ;
541+ let kind_ident = & spec_gen_ctx. kubernetes_idents . kind ;
542+
543+ let api_versions = spec_gen_ctx
544+ . version_strings
545+ . iter ( )
546+ . map ( |version| {
547+ format ! (
548+ "{group}/{version}" ,
549+ group = & spec_gen_ctx. kubernetes_arguments. group
550+ )
551+ } )
552+ . collect :: < Vec < _ > > ( ) ;
553+
554+ let earliest_version_module_ident = & versions
555+ . first ( )
556+ . expect ( "there must be at least one version present" )
557+ . idents
558+ . module ;
559+ let latest_version_module_ident = & versions
560+ . last ( )
561+ . expect ( "there must be at least one version present" )
562+ . idents
563+ . module ;
564+ let earliest_api_version = api_versions
565+ . first ( )
566+ . expect ( "there must be at least one version present" ) ;
567+ let latest_api_version = api_versions
568+ . last ( )
569+ . expect ( "there must be at least one version present" ) ;
570+ let test_function_down_up = format_ident ! ( "{struct_ident}_roundtrip_down_up" ) ;
571+ let test_function_up_down = format_ident ! ( "{struct_ident}_roundtrip_up_down" ) ;
572+
573+ quote ! {
574+ #[ cfg( test) ]
575+ #[ test]
576+ fn #test_function_down_up( ) {
577+ #versioned_path:: test_utils:: test_roundtrip:: <#latest_version_module_ident:: #struct_ident>(
578+ stringify!( #kind_ident) ,
579+ #latest_api_version,
580+ #earliest_api_version,
581+ #kind_ident:: try_convert,
582+ ) ;
583+ }
584+
585+ #[ cfg( test) ]
586+ #[ test]
587+ fn #test_function_up_down( ) {
588+ #versioned_path:: test_utils:: test_roundtrip:: <#earliest_version_module_ident:: #struct_ident>(
589+ stringify!( #kind_ident) ,
590+ #earliest_api_version,
591+ #latest_api_version,
592+ #kind_ident:: try_convert,
593+ ) ;
594+ }
595+ }
596+ }
597+
533598 pub ( super ) fn generate_from_json_object_fn (
534599 & self ,
535600 mod_gen_ctx : ModuleGenerationContext < ' _ > ,
0 commit comments