@@ -510,22 +510,71 @@ run "test_scripts_tee_stdout_and_log_file" {
510510 }
511511
512512 assert {
513- condition = can (regex (" pre_install.sh 2>&1 \\ | tee .*pre_install.log" , coder_script. pre_install_script [0 ]. script ))
514- error_message = " pre_install wrapper must tee combined output to the log file and stdout "
513+ condition = can (regex (" pre_install.sh 2>&1 \\ | tee .*logs/ pre_install.log" , coder_script. pre_install_script [0 ]. script ))
514+ error_message = " pre_install wrapper must tee combined output to the logs/ subdirectory "
515515 }
516516
517517 assert {
518- condition = can (regex (" install.sh 2>&1 \\ | tee .*install.log" , coder_script. install_script . script ))
519- error_message = " install wrapper must tee combined output to the log file and stdout "
518+ condition = can (regex (" install.sh 2>&1 \\ | tee .*logs/ install.log" , coder_script. install_script . script ))
519+ error_message = " install wrapper must tee combined output to the logs/ subdirectory "
520520 }
521521
522522 assert {
523- condition = can (regex (" post_install.sh 2>&1 \\ | tee .*post_install.log" , coder_script. post_install_script [0 ]. script ))
524- error_message = " post_install wrapper must tee combined output to the log file and stdout "
523+ condition = can (regex (" post_install.sh 2>&1 \\ | tee .*logs/ post_install.log" , coder_script. post_install_script [0 ]. script ))
524+ error_message = " post_install wrapper must tee combined output to the logs/ subdirectory "
525525 }
526526
527527 assert {
528- condition = can (regex (" start.sh 2>&1 \\ | tee .*start.log" , coder_script. start_script [0 ]. script ))
529- error_message = " start wrapper must tee combined output to the log file and stdout"
528+ condition = can (regex (" start.sh 2>&1 \\ | tee .*logs/start.log" , coder_script. start_script [0 ]. script ))
529+ error_message = " start wrapper must tee combined output to the logs/ subdirectory"
530+ }
531+ }
532+
533+ # Logs unconditionally land under ${module_directory}/logs/. Each script
534+ # mkdirs that path before tee runs so the first script to execute creates it.
535+ run "test_logs_nested_under_module_directory" {
536+ command = plan
537+
538+ variables {
539+ agent_id = " test-agent-id"
540+ agent_name = " test-agent"
541+ module_directory = " .test-module"
542+ pre_install_script = " echo pre"
543+ install_script = " echo install"
544+ post_install_script = " echo post"
545+ start_script = " echo start"
546+ }
547+
548+ assert {
549+ condition = can (regex (" tee .test-module/logs/pre_install.log" , coder_script. pre_install_script [0 ]. script ))
550+ error_message = " pre_install log must land under module_directory/logs"
551+ }
552+
553+ assert {
554+ condition = can (regex (" tee .test-module/logs/install.log" , coder_script. install_script . script ))
555+ error_message = " install log must land under module_directory/logs"
556+ }
557+
558+ assert {
559+ condition = can (regex (" tee .test-module/logs/post_install.log" , coder_script. post_install_script [0 ]. script ))
560+ error_message = " post_install log must land under module_directory/logs"
561+ }
562+
563+ assert {
564+ condition = can (regex (" tee .test-module/logs/start.log" , coder_script. start_script [0 ]. script ))
565+ error_message = " start log must land under module_directory/logs"
566+ }
567+
568+ # Only pre_install and install mkdir the logs/ sub-path. post_install
569+ # and start sync-depend on install so the directory already exists by
570+ # the time they run.
571+ assert {
572+ condition = can (regex (" mkdir -p .test-module/logs" , coder_script. pre_install_script [0 ]. script ))
573+ error_message = " pre_install script must mkdir -p the logs/ sub-path"
574+ }
575+
576+ assert {
577+ condition = can (regex (" mkdir -p .test-module/logs" , coder_script. install_script . script ))
578+ error_message = " install script must mkdir -p the logs/ sub-path"
530579 }
531580}
0 commit comments