@@ -742,6 +742,53 @@ def test_summary(self):
742
742
self .assertEqual ('error' , results ['failed' ][0 ]['status' ]) # bad
743
743
self .assertEqual ('error' , results ['failed' ][1 ]['status' ]) # bad2
744
744
745
+ @mock .patch ('json.dump' )
746
+ def test_summary_json_format (self , dump_mock ):
747
+ self .conf .set_override ('format' , 'json' )
748
+ kolla = build .KollaWorker (self .conf )
749
+ kolla .images = self .images
750
+ kolla .image_statuses_good ['good' ] = build .Status .BUILT
751
+ kolla .image_statuses_bad ['bad' ] = build .Status .ERROR
752
+ kolla .image_statuses_allowed_to_fail ['bad2' ] = build .Status .ERROR
753
+ kolla .image_statuses_unmatched ['unmatched' ] = build .Status .UNMATCHED
754
+ results = kolla .summary ()
755
+ dump_mock .assert_called_once_with (results , sys .stdout )
756
+
757
+ @mock .patch ('json.dump' )
758
+ def test_summary_json_format_file (self , dump_mock ):
759
+ tmpdir = tempfile .mkdtemp ()
760
+ file_path = os .path .join (tmpdir , 'summary.json' )
761
+ try :
762
+ self .conf .set_override ('format' , 'json' )
763
+ self .conf .set_override ('summary_json_file' , file_path )
764
+ kolla = build .KollaWorker (self .conf )
765
+ kolla .images = self .images
766
+ kolla .image_statuses_good ['good' ] = build .Status .BUILT
767
+ kolla .image_statuses_bad ['bad' ] = build .Status .ERROR
768
+ kolla .image_statuses_allowed_to_fail ['bad2' ] = build .Status .ERROR
769
+ kolla .image_statuses_unmatched ['unmatched' ] = (
770
+ build .Status .UNMATCHED )
771
+ results = kolla .summary ()
772
+ dump_mock .assert_called_once_with (results , mock .ANY , indent = 4 )
773
+ self .assertEqual (dump_mock .call_args [0 ][1 ].name , file_path )
774
+ finally :
775
+ os .remove (file_path )
776
+ os .rmdir (tmpdir )
777
+
778
+ @mock .patch ('builtins.open' )
779
+ def test_summary_json_format_file_error (self , open_mock ):
780
+ open_mock .side_effect = OSError
781
+ self .conf .set_override ('format' , 'json' )
782
+ self .conf .set_override ('summary_json_file' , 'fake-file' )
783
+ kolla = build .KollaWorker (self .conf )
784
+ kolla .images = self .images
785
+ kolla .image_statuses_good ['good' ] = build .Status .BUILT
786
+ kolla .image_statuses_bad ['bad' ] = build .Status .ERROR
787
+ kolla .image_statuses_allowed_to_fail ['bad2' ] = build .Status .ERROR
788
+ kolla .image_statuses_unmatched ['unmatched' ] = (
789
+ build .Status .UNMATCHED )
790
+ self .assertRaises (SystemExit , kolla .summary )
791
+
745
792
@mock .patch ('shutil.copytree' )
746
793
def test_work_dir (self , copytree_mock ):
747
794
self .conf .set_override ('work_dir' , 'tmp/foo' )
0 commit comments