@@ -579,3 +579,119 @@ def test_project_deploy_with_prune(
579
579
# Clean up
580
580
result = runner .invoke_with_connection (["dcm" , "drop" , project_name ])
581
581
assert result .exit_code == 0 , result .output
582
+
583
+
584
+ @pytest .mark .qa_only
585
+ @pytest .mark .integration
586
+ def test_project_plan_with_output_path (
587
+ runner ,
588
+ test_database ,
589
+ project_directory ,
590
+ ):
591
+ """Test that DCM plan command with --output-path option writes output to the specified stage."""
592
+ project_name = "project_descriptive_name"
593
+ entity_id = "my_project"
594
+ source_stage_name = "source_project_stage"
595
+ output_stage_name = "output_results_stage"
596
+ output_path = f"@{ output_stage_name } /plan_results"
597
+
598
+ with project_directory ("dcm_project" ) as project_root :
599
+ # Create a new project
600
+ result = runner .invoke_with_connection (["dcm" , "create" , entity_id ])
601
+ assert result .exit_code == 0 , result .output
602
+ _assert_project_has_versions (runner , project_name , expected_versions = set ())
603
+
604
+ # Edit file_a.sql to add a table definition for testing
605
+ file_a_path = project_root / "file_a.sql"
606
+ original_content = file_a_path .read_text ()
607
+ modified_content = (
608
+ original_content
609
+ + "\n define table identifier('{{ table_name }}_OUTPUT_TEST') (id int, name string);\n "
610
+ )
611
+ file_a_path .write_text (modified_content )
612
+
613
+ # Create source stage and upload files there
614
+ result = runner .invoke_with_connection (["stage" , "create" , source_stage_name ])
615
+ assert result .exit_code == 0 , result .output
616
+
617
+ result = runner .invoke_with_connection (
618
+ ["stage" , "copy" , "." , f"@{ source_stage_name } " ]
619
+ )
620
+ assert result .exit_code == 0 , result .output
621
+
622
+ # Create output stage for plan results
623
+ result = runner .invoke_with_connection (["stage" , "create" , output_stage_name ])
624
+ assert result .exit_code == 0 , result .output
625
+
626
+ # Test plan with output-path option
627
+ result = runner .invoke_with_connection_json (
628
+ [
629
+ "dcm" ,
630
+ "plan" ,
631
+ project_name ,
632
+ "--from" ,
633
+ f"@{ source_stage_name } " ,
634
+ "--output-path" ,
635
+ output_path ,
636
+ "-D" ,
637
+ f"table_name='{ test_database } .PUBLIC.OutputTestTable'" ,
638
+ ]
639
+ )
640
+ assert result .exit_code == 0 , result .output
641
+
642
+ # Verify that the plan was executed successfully
643
+ output_str = str (result .json )
644
+ assert (
645
+ f"{ test_database } .PUBLIC.OUTPUTTESTTABLE_OUTPUT_TEST" .upper ()
646
+ in output_str .upper ()
647
+ )
648
+
649
+ # Verify that the output was written to the specified stage path
650
+ # Check if there are files in the output stage
651
+ stage_list_result = runner .invoke_with_connection_json (
652
+ ["stage" , "list-files" , output_path ]
653
+ )
654
+ assert stage_list_result .exit_code == 0 , stage_list_result .output
655
+
656
+ # There should be at least one file in the output location
657
+ assert (
658
+ len (stage_list_result .json ) > 0
659
+ ), "Plan output should be written to the specified stage path"
660
+
661
+ # Verify that one of the files contains plan-related content by checking file names
662
+ file_names = [file ["name" ] for file in stage_list_result .json ]
663
+ assert any (
664
+ "plan" in name .lower ()
665
+ or "result" in name .lower ()
666
+ or name .endswith ((".json" , ".txt" , ".sql" ))
667
+ for name in file_names
668
+ ), f"Expected plan output files, but found: { file_names } "
669
+
670
+ # Verify that the table does not exist after plan (plan should not create actual objects)
671
+ table_check_result = runner .invoke_with_connection_json (
672
+ [
673
+ "object" ,
674
+ "list" ,
675
+ "table" ,
676
+ "--like" ,
677
+ "OUTPUTTESTTABLE_OUTPUT_TEST" ,
678
+ "--in" ,
679
+ "database" ,
680
+ test_database ,
681
+ ]
682
+ )
683
+ assert table_check_result .exit_code == 0
684
+ assert (
685
+ len (table_check_result .json ) == 0
686
+ ), "Table should not exist after plan operation"
687
+
688
+ # Clean up stages
689
+ result = runner .invoke_with_connection (["stage" , "drop" , source_stage_name ])
690
+ assert result .exit_code == 0 , result .output
691
+
692
+ result = runner .invoke_with_connection (["stage" , "drop" , output_stage_name ])
693
+ assert result .exit_code == 0 , result .output
694
+
695
+ # Clean up project
696
+ result = runner .invoke_with_connection (["dcm" , "drop" , project_name ])
697
+ assert result .exit_code == 0 , result .output
0 commit comments