11// Copyright 2025 Oxide Computer Company
22
3- //! Common test utilities and infrastructure for dropshot-api-manager integration tests.
3+ //! Test environment infrastructure for integration tests.
44
55use anyhow:: { Context , Result , anyhow} ;
66use camino:: { Utf8Path , Utf8PathBuf } ;
77use camino_tempfile:: Utf8TempDir ;
88use camino_tempfile_ext:: { fixture:: ChildPath , prelude:: * } ;
99use clap:: Parser ;
10- use dropshot_api_manager:: { Environment , ManagedApiConfig , ManagedApis } ;
11- use dropshot_api_manager_types:: { ManagedApiMetadata , Versions } ;
12- use semver:: Version ;
10+ use dropshot_api_manager:: { Environment , ManagedApis } ;
1311use std:: {
1412 fs,
1513 process:: { Command , ExitCode } ,
1614} ;
1715
18- pub mod fixtures;
19-
2016/// A temporary test environment that manages directories and cleanup.
2117pub struct TestEnvironment {
2218 /// Temporary directory that will be cleaned up automatically.
@@ -153,8 +149,8 @@ impl TestEnvironment {
153149 Ok ( maybe_path. is_some ( ) )
154150 }
155151
156- /// Check that a versioned document exists for a versioned API at a specific
157- /// version, and is blessed.
152+ /// Check that a versioned document exists for a versioned API at a
153+ /// specific version, and is blessed.
158154 pub fn versioned_local_and_blessed_document_exists (
159155 & self ,
160156 api_ident : & str ,
@@ -166,7 +162,7 @@ impl TestEnvironment {
166162 return Ok ( false ) ;
167163 } ;
168164
169- // Query git on main at the blessed path (main)
165+ // Query git on main at the blessed path (main).
170166 let output = Self :: run_git_command (
171167 & self . workspace_root ,
172168 & [ "ls-tree" , "-r" , "--name-only" , "main" , path. as_str ( ) ] ,
@@ -386,225 +382,3 @@ pub fn rel_path_forward_slashes(path: &str) -> String {
386382pub fn rel_path_forward_slashes ( path : & str ) -> String {
387383 path. to_string ( )
388384}
389-
390- pub fn versioned_health_api ( ) -> ManagedApiConfig {
391- ManagedApiConfig {
392- ident : "versioned-health" ,
393- versions : Versions :: Versioned {
394- supported_versions : fixtures:: versioned_health:: supported_versions ( ) ,
395- } ,
396- title : "Versioned Health API" ,
397- metadata : ManagedApiMetadata {
398- description : Some ( "A versioned health API for testing version evolution" ) ,
399- ..Default :: default ( )
400- } ,
401- api_description : fixtures:: versioned_health:: versioned_health_api_mod:: stub_api_description,
402- extra_validation : None ,
403- }
404- }
405-
406- pub fn versioned_user_api ( ) -> ManagedApiConfig {
407- ManagedApiConfig {
408- ident : "versioned-user" ,
409- versions : Versions :: Versioned {
410- supported_versions : fixtures:: versioned_user:: supported_versions ( ) ,
411- } ,
412- title : "Versioned User API" ,
413- metadata : ManagedApiMetadata {
414- description : Some ( "A versioned user API for testing complex schema evolution" ) ,
415- ..Default :: default ( )
416- } ,
417- api_description : fixtures:: versioned_user:: versioned_user_api_mod:: stub_api_description,
418- extra_validation : None ,
419- }
420- }
421-
422- pub fn lockstep_health_api ( ) -> ManagedApiConfig {
423- ManagedApiConfig {
424- ident : "health" ,
425- versions : Versions :: Lockstep { version : Version :: new ( 1 , 0 , 0 ) } ,
426- title : "Health API" ,
427- metadata : ManagedApiMetadata {
428- description : Some ( "A health API for testing schema evolution" ) ,
429- ..Default :: default ( )
430- } ,
431- api_description : fixtures:: health_api_mod:: stub_api_description,
432- extra_validation : None ,
433- }
434- }
435-
436- pub fn lockstep_counter_api ( ) -> ManagedApiConfig {
437- ManagedApiConfig {
438- ident : "counter" ,
439- versions : Versions :: Lockstep { version : Version :: new ( 1 , 0 , 0 ) } ,
440- title : "Counter Test API" ,
441- metadata : ManagedApiMetadata {
442- description : Some ( "A counter API for testing state changes" ) ,
443- ..Default :: default ( )
444- } ,
445- api_description : fixtures:: counter_api_mod:: stub_api_description,
446- extra_validation : None ,
447- }
448- }
449-
450- pub fn lockstep_user_api ( ) -> ManagedApiConfig {
451- ManagedApiConfig {
452- ident : "user" ,
453- versions : Versions :: Lockstep { version : Version :: new ( 1 , 0 , 0 ) } ,
454- title : "User Test API" ,
455- metadata : ManagedApiMetadata {
456- description : Some ( "A user API for testing state changes" ) ,
457- ..Default :: default ( )
458- } ,
459- api_description : fixtures:: user_api_mod:: stub_api_description,
460- extra_validation : None ,
461- }
462- }
463-
464- /// Create a health API for basic testing.
465- pub fn lockstep_health_apis ( ) -> Result < ManagedApis > {
466- ManagedApis :: new ( vec ! [ lockstep_health_api( ) ] )
467- . context ( "failed to create ManagedApis" )
468- }
469-
470- /// Create a counter test API configuration.
471- pub fn lockstep_counter_apis ( ) -> Result < ManagedApis > {
472- ManagedApis :: new ( vec ! [ lockstep_counter_api( ) ] )
473- . context ( "failed to create ManagedApis" )
474- }
475-
476- /// Create a user test API configuration.
477- pub fn lockstep_user_apis ( ) -> Result < ManagedApis > {
478- ManagedApis :: new ( vec ! [ lockstep_user_api( ) ] )
479- . context ( "failed to create ManagedApis" )
480- }
481-
482- /// Helper to create multiple test APIs.
483- pub fn lockstep_multi_apis ( ) -> Result < ManagedApis > {
484- let configs = vec ! [
485- lockstep_health_api( ) ,
486- lockstep_counter_api( ) ,
487- lockstep_user_api( ) ,
488- ] ;
489- ManagedApis :: new ( configs) . context ( "failed to create ManagedApis" )
490- }
491-
492- /// Create a versioned health API for testing.
493- pub fn versioned_health_apis ( ) -> Result < ManagedApis > {
494- ManagedApis :: new ( vec ! [ versioned_health_api( ) ] )
495- . context ( "failed to create versioned health ManagedApis" )
496- }
497-
498- /// Create a versioned user API for testing.
499- pub fn versioned_user_apis ( ) -> Result < ManagedApis > {
500- ManagedApis :: new ( vec ! [ versioned_user_api( ) ] )
501- . context ( "failed to create versioned user ManagedApis" )
502- }
503-
504- /// Helper to create multiple versioned test APIs.
505- pub fn multi_versioned_apis ( ) -> Result < ManagedApis > {
506- let configs = vec ! [ versioned_health_api( ) , versioned_user_api( ) ] ;
507- ManagedApis :: new ( configs) . context ( "failed to create versioned ManagedApis" )
508- }
509-
510- /// Helper to create mixed lockstep and versioned test APIs.
511- pub fn create_mixed_test_apis ( ) -> Result < ManagedApis > {
512- let configs = vec ! [
513- lockstep_health_api( ) ,
514- lockstep_counter_api( ) ,
515- versioned_health_api( ) ,
516- versioned_user_api( ) ,
517- ] ;
518- ManagedApis :: new ( configs) . context ( "failed to create mixed ManagedApis" )
519- }
520-
521- /// Create versioned health API with a trivial change (title/metadata updated).
522- pub fn versioned_health_trivial_change_apis ( ) -> Result < ManagedApis > {
523- // Create a modified API config that would produce different OpenAPI
524- // documents.
525- let mut config = versioned_health_api ( ) ;
526-
527- // Modify the title to create a different document signature.
528- config. title = "Modified Versioned Health API" ;
529- config. metadata . description =
530- Some ( "A versioned health API with breaking changes" ) ;
531-
532- ManagedApis :: new ( vec ! [ config] )
533- . context ( "failed to create trivial change versioned health ManagedApis" )
534- }
535-
536- /// Create versioned health API with reduced versions (simulating version
537- /// removal).
538- pub fn versioned_health_reduced_apis ( ) -> Result < ManagedApis > {
539- // Create a configuration similar to versioned health but with fewer
540- // versions. We'll create a new fixture for this.
541- let config = ManagedApiConfig {
542- ident : "versioned-health" ,
543- versions : Versions :: Versioned {
544- // Use a subset of versions (only 1.0.0 and 2.0.0, not 3.0.0).
545- supported_versions :
546- fixtures:: versioned_health_reduced:: supported_versions ( ) ,
547- } ,
548- title : "Versioned Health API" ,
549- metadata : ManagedApiMetadata {
550- description : Some ( "A versioned health API with reduced versions" ) ,
551- ..Default :: default ( )
552- } ,
553- api_description :
554- fixtures:: versioned_health_reduced:: api_mod:: stub_api_description,
555- extra_validation : None ,
556- } ;
557-
558- ManagedApis :: new ( vec ! [ config] )
559- . context ( "failed to create reduced versioned health ManagedApis" )
560- }
561-
562- pub fn versioned_health_skip_middle_apis ( ) -> Result < ManagedApis > {
563- // Create a configuration similar to versioned health but skipping the
564- // middle version. This has versions 3.0.0 and 1.0.0, simulating retirement
565- // of version 2.0.0.
566- let config = ManagedApiConfig {
567- ident : "versioned-health" ,
568- versions : Versions :: Versioned {
569- // Use versions 3.0.0 and 1.0.0 (skip 2.0.0).
570- supported_versions : fixtures:: versioned_health_skip_middle:: supported_versions ( ) ,
571- } ,
572- title : "Versioned Health API" ,
573- metadata : ManagedApiMetadata {
574- description : Some ( "A versioned health API that skips middle version" ) ,
575- ..Default :: default ( )
576- } ,
577- api_description : fixtures:: versioned_health_skip_middle:: api_mod:: stub_api_description,
578- extra_validation : None ,
579- } ;
580-
581- ManagedApis :: new ( vec ! [ config] )
582- . context ( "failed to create skip middle versioned health ManagedApis" )
583- }
584-
585- /// Create a versioned health API with incompatible changes that break backward
586- /// compatibility.
587- pub fn versioned_health_incompat_apis ( ) -> Result < ManagedApis > {
588- // Create a configuration similar to versioned health but with incompatible
589- // changes that break backward compatibility.
590- let config = ManagedApiConfig {
591- ident : "versioned-health" ,
592- versions : Versions :: Versioned {
593- supported_versions :
594- fixtures:: versioned_health_incompat:: supported_versions ( ) ,
595- } ,
596- title : "Versioned Health API" ,
597- metadata : ManagedApiMetadata {
598- description : Some (
599- "A versioned health API with incompatible changes" ,
600- ) ,
601- ..Default :: default ( )
602- } ,
603- api_description :
604- fixtures:: versioned_health_incompat:: api_mod:: stub_api_description,
605- extra_validation : None ,
606- } ;
607-
608- ManagedApis :: new ( vec ! [ config] )
609- . context ( "failed to create incompatible versioned health ManagedApis" )
610- }
0 commit comments