@@ -91,3 +91,49 @@ fn single_file_manifest(
9191
9292 Ok ( manifest)
9393}
94+
95+ #[ cfg( test) ]
96+ mod test {
97+ use std:: collections:: HashSet ;
98+
99+ use spin_app:: { retain_components, App } ;
100+
101+ use super :: * ;
102+
103+ pub async fn build_locked_app ( manifest : & toml:: Table ) -> anyhow:: Result < LockedApp > {
104+ let toml_str = toml:: to_string ( manifest) . context ( "failed serializing manifest" ) ?;
105+ let dir = tempfile:: tempdir ( ) . context ( "failed creating tempdir" ) ?;
106+ let path = dir. path ( ) . join ( "spin.toml" ) ;
107+ std:: fs:: write ( & path, toml_str) . context ( "failed writing manifest" ) ?;
108+ from_file ( & path, FilesMountStrategy :: Direct , None ) . await
109+ }
110+
111+ fn does_nothing_validator ( _: & App , _: & [ & str ] ) -> anyhow:: Result < ( ) > {
112+ Ok ( ( ) )
113+ }
114+
115+ #[ tokio:: test]
116+ async fn test_retain_components_filtering_for_only_component_works ( ) {
117+ let manifest = toml:: toml! {
118+ spin_manifest_version = 2
119+
120+ [ application]
121+ name = "test-app"
122+
123+ [ [ trigger. test-trigger] ]
124+ component = "empty"
125+
126+ [ component. empty]
127+ source = "does-not-exist.wasm"
128+ } ;
129+ let mut locked_app = build_locked_app ( & manifest) . await . unwrap ( ) ;
130+ locked_app = retain_components ( locked_app, & [ "empty" ] , & [ & does_nothing_validator] ) . unwrap ( ) ;
131+ let components = locked_app
132+ . components
133+ . iter ( )
134+ . map ( |c| c. id . to_string ( ) )
135+ . collect :: < HashSet < _ > > ( ) ;
136+ assert ! ( components. contains( "empty" ) ) ;
137+ assert ! ( components. len( ) == 1 ) ;
138+ }
139+ }
0 commit comments