@@ -193,4 +193,56 @@ mod tests {
193193 assert_eq ! ( rendered_oci. version, Version :: from_str( & version) . unwrap( ) ) ;
194194 assert_eq ! ( rendered_oci. public_key_url, public_key_url) ;
195195 }
196+
197+ #[ test]
198+ fn test_post_download_hook_template_with_variables ( ) {
199+ let mut variables = Variables :: new ( ) ;
200+ variables. insert (
201+ "nr-var:version" . to_string ( ) ,
202+ Variable :: new_final_string_variable ( "1.0.0" . to_string ( ) ) ,
203+ ) ;
204+ variables. insert (
205+ "nr-var:script-path" . to_string ( ) ,
206+ Variable :: new_final_string_variable ( "/opt/install.sh" . to_string ( ) ) ,
207+ ) ;
208+ variables. insert (
209+ "nr-var:env-value" . to_string ( ) ,
210+ Variable :: new_final_string_variable ( "test-value" . to_string ( ) ) ,
211+ ) ;
212+
213+ let mut env = HashMap :: new ( ) ;
214+ env. insert (
215+ "AGENT_VERSION" . to_string ( ) ,
216+ TemplateableValue :: from_template ( "${nr-var:version}" . to_string ( ) ) ,
217+ ) ;
218+ env. insert (
219+ "CUSTOM_VAR" . to_string ( ) ,
220+ TemplateableValue :: from_template ( "${nr-var:env-value}" . to_string ( ) ) ,
221+ ) ;
222+
223+ let post_download_hook = PostDownloadHook {
224+ path : TemplateableValue :: from_template ( "/bin/bash" . to_string ( ) ) ,
225+ args : vec ! [
226+ TemplateableValue :: from_template( "${nr-var:script-path}" . to_string( ) ) ,
227+ TemplateableValue :: from_template( "--version=${nr-var:version}" . to_string( ) ) ,
228+ ] ,
229+ env,
230+ } ;
231+
232+ let rendered = post_download_hook. template_with ( & variables) . unwrap ( ) ;
233+
234+ assert_eq ! ( rendered. path, "/bin/bash" ) ;
235+ assert_eq ! ( rendered. args. len( ) , 2 ) ;
236+ assert_eq ! ( rendered. args[ 0 ] , "/opt/install.sh" ) ;
237+ assert_eq ! ( rendered. args[ 1 ] , "--version=1.0.0" ) ;
238+ assert_eq ! ( rendered. env. len( ) , 2 ) ;
239+ assert_eq ! (
240+ rendered. env. get( "AGENT_VERSION" ) ,
241+ Some ( & "1.0.0" . to_string( ) )
242+ ) ;
243+ assert_eq ! (
244+ rendered. env. get( "CUSTOM_VAR" ) ,
245+ Some ( & "test-value" . to_string( ) )
246+ ) ;
247+ }
196248}
0 commit comments