@@ -182,3 +182,61 @@ async fn test_running_legacy_app() {
182182 let status = app. status ( ) . await . expect ( "Failed to get app status" ) ;
183183 assert ! ( status == Status :: Exited , "App should be running" ) ;
184184}
185+
186+ #[ tokio:: test]
187+ async fn test_running_app_with_secret ( ) {
188+ debug ! ( "Running 04-app-with-secret" ) ;
189+ let app_dir = get_example_app_dir ( "04-app-with-secret" ) ;
190+ let package = build_package_from_dir ( & app_dir) . await ;
191+ let ( sender, mut receiver) = unbounded_channel ( ) ;
192+
193+ let mut secrets = HashMap :: new ( ) ;
194+ secrets. insert ( "MY_SECRET" . to_string ( ) , "It's in the sauce!" . to_string ( ) ) ;
195+
196+ // We need to create the package, which will load the app
197+ let opts = StartOptions {
198+ ctx : tower_telemetry:: Context :: new ( ) ,
199+ package,
200+ output_sender : sender,
201+ cwd : None ,
202+ environment : "local" . to_string ( ) ,
203+ secrets : secrets,
204+ parameters : HashMap :: new ( ) ,
205+ env_vars : HashMap :: new ( ) ,
206+ } ;
207+
208+ // Start the app using the LocalApp runtime
209+ let app = LocalApp :: start ( opts) . await . expect ( "Failed to start app" ) ;
210+
211+ // The status should be running
212+ let status = app. status ( ) . await . expect ( "Failed to get app status" ) ;
213+ assert ! ( status == Status :: Running , "App should be running" ) ;
214+
215+ let mut count_setup = 0 ;
216+ let mut count_stdout = 0 ;
217+
218+ while let Some ( output) = receiver. recv ( ) . await {
219+ match output. channel {
220+ tower_runtime:: Channel :: Setup => {
221+ // We always have some setup lines to count on.
222+ count_setup += 1 ;
223+ }
224+ tower_runtime:: Channel :: Program => {
225+ if output. line . starts_with ( "The secret is:" ) {
226+ // Indicate that we found the line.
227+ count_stdout += 1 ;
228+
229+ // Require that the right suffix is there.
230+ assert ! ( output. line. ends_with( "It's in the sauce!" ) ) ;
231+ }
232+ }
233+ }
234+ }
235+
236+ assert ! ( count_setup > 0 , "There should be some setup output" ) ;
237+ assert ! ( count_stdout > 0 , "should be more than one output" ) ;
238+
239+ // check the status once more, should be done.
240+ let status = app. status ( ) . await . expect ( "Failed to get app status" ) ;
241+ assert ! ( status == Status :: Exited , "App should be running" ) ;
242+ }
0 commit comments