@@ -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 :: {
@@ -527,6 +527,71 @@ impl Struct {
527527 } )
528528 }
529529
530+ pub ( super ) fn generate_conversion_roundtrip_test (
531+ & self ,
532+ versions : & [ VersionDefinition ] ,
533+ mod_gen_ctx : ModuleGenerationContext < ' _ > ,
534+ spec_gen_ctx : & SpecGenerationContext < ' _ > ,
535+ ) -> TokenStream {
536+ let versioned_path = & * mod_gen_ctx. crates . versioned ;
537+ let struct_ident = & self . common . idents . original ;
538+ let kind_ident = & spec_gen_ctx. kubernetes_idents . kind ;
539+
540+ let api_versions = spec_gen_ctx
541+ . version_strings
542+ . iter ( )
543+ . map ( |version| {
544+ format ! (
545+ "{group}/{version}" ,
546+ group = & spec_gen_ctx. kubernetes_arguments. group
547+ )
548+ } )
549+ . collect :: < Vec < _ > > ( ) ;
550+
551+ let earliest_version_module_ident = & versions
552+ . first ( )
553+ . expect ( "there must be at least one version present" )
554+ . idents
555+ . module ;
556+ let latest_version_module_ident = & versions
557+ . last ( )
558+ . expect ( "there must be at least one version present" )
559+ . idents
560+ . module ;
561+ let earliest_api_version = api_versions
562+ . first ( )
563+ . expect ( "there must be at least one version present" ) ;
564+ let latest_api_version = api_versions
565+ . last ( )
566+ . expect ( "there must be at least one version present" ) ;
567+ let test_function_down_up = format_ident ! ( "{struct_ident}_roundtrip_down_up" ) ;
568+ let test_function_up_down = format_ident ! ( "{struct_ident}_roundtrip_up_down" ) ;
569+
570+ quote ! {
571+ #[ cfg( test) ]
572+ #[ test]
573+ fn #test_function_down_up( ) {
574+ #versioned_path:: test_utils:: test_roundtrip:: <#latest_version_module_ident:: #struct_ident>(
575+ stringify!( #kind_ident) ,
576+ #latest_api_version,
577+ #earliest_api_version,
578+ #kind_ident:: try_convert,
579+ ) ;
580+ }
581+
582+ #[ cfg( test) ]
583+ #[ test]
584+ fn #test_function_up_down( ) {
585+ #versioned_path:: test_utils:: test_roundtrip:: <#earliest_version_module_ident:: #struct_ident>(
586+ stringify!( #kind_ident) ,
587+ #earliest_api_version,
588+ #latest_api_version,
589+ #kind_ident:: try_convert,
590+ ) ;
591+ }
592+ }
593+ }
594+
530595 pub ( super ) fn generate_from_json_object_fn (
531596 & self ,
532597 mod_gen_ctx : ModuleGenerationContext < ' _ > ,
0 commit comments