14
14
15
15
class TestCiCheckListsSourceRef (unittest .TestCase ):
16
16
@patch ("subprocess.check_output" , return_value = "invalid" .encode ())
17
- def test_ref_does_not_exist (self , mock_check_output : MagicMock ) -> None :
17
+ def test_ref_branch_tag_does_not_exist (self , mock_check_output : MagicMock ) -> None :
18
18
component = InputComponentFromSource ({"name" : "common-utils" , "repository" : "url" , "ref" : "ref" })
19
19
with self .assertRaises (CiCheckListSourceRef .MissingRefError ) as ctx :
20
20
list = CiCheckListSourceRef (component , MagicMock ())
@@ -23,8 +23,35 @@ def test_ref_does_not_exist(self, mock_check_output: MagicMock) -> None:
23
23
mock_check_output .assert_called_with ("git ls-remote url ref" , shell = True )
24
24
25
25
@patch ("subprocess.check_output" , return_value = "valid\t ref" .encode ())
26
- def test_ref_exists (self , mock_check_output : MagicMock ) -> None :
26
+ def test_ref_branch_tag_exists (self , mock_check_output : MagicMock ) -> None :
27
27
component = InputComponentFromSource ({"name" : "common-utils" , "repository" : "url" , "ref" : "ref" })
28
28
list = CiCheckListSourceRef (component , MagicMock ())
29
29
list .check ()
30
30
mock_check_output .assert_called_with ("git ls-remote url ref" , shell = True )
31
+
32
+ @patch ("ci_workflow.ci_check_list_source_ref.GitRepository" )
33
+ def test_ref_commit_checkout (self , mock_git_repo : MagicMock ) -> None :
34
+ component = InputComponentFromSource ({"name" : "common-utils" , "repository" : "url" , "ref" : "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" })
35
+ list = CiCheckListSourceRef (component , MagicMock ())
36
+ list .checkout ("path" )
37
+ mock_git_repo .assert_called ()
38
+
39
+ @patch ("ci_workflow.ci_check_list_source_ref.GitRepository" )
40
+ @patch ("subprocess.check_output" , return_value = "fatal" .encode ())
41
+ def test_ref_commit_does_not_exist (self , mock_check_output : MagicMock , mock_git_repo : MagicMock ) -> None :
42
+ component = InputComponentFromSource ({"name" : "common-utils" , "repository" : "url" , "ref" : "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" })
43
+ with self .assertRaises (CiCheckListSourceRef .MissingRefError ) as ctx :
44
+ list = CiCheckListSourceRef (component , MagicMock ())
45
+ list .checkout ("path" )
46
+ list .check ()
47
+ self .assertEqual ("Missing url@aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa." , str (ctx .exception ))
48
+ mock_check_output .assert_called_with ("git cat-file -t aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" , shell = True , cwd = mock_git_repo ().working_directory )
49
+
50
+ @patch ("ci_workflow.ci_check_list_source_ref.GitRepository" )
51
+ @patch ("subprocess.check_output" , return_value = "commit" .encode ())
52
+ def test_ref_commit_exists (self , mock_check_output : MagicMock , mock_git_repo : MagicMock ) -> None :
53
+ component = InputComponentFromSource ({"name" : "common-utils" , "repository" : "url" , "ref" : "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" })
54
+ list = CiCheckListSourceRef (component , MagicMock ())
55
+ list .checkout ("path" )
56
+ list .check ()
57
+ mock_check_output .assert_called_with ("git cat-file -t aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" , shell = True , cwd = mock_git_repo ().working_directory )
0 commit comments