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