44import os
55import pytest
66
7- from fosslight_util .download import cli_download_and_extract
7+ from fosslight_util .download import cli_download_and_extract , download_git_clone
88from tests import constants
99
1010
1111def test_download_from_github ():
12+ # given
13+ git_url = "https://github.com/LGE-OSS/example"
14+ target_dir = os .path .join (constants .TEST_RESULT_DIR , "download/example" )
15+ log_dir = "test_result/download_log/example"
16+
1217 # when
18+ success , _ , _ , _ = cli_download_and_extract (git_url , target_dir , log_dir )
19+
20+ # then
21+ assert success is True
22+ assert len (os .listdir (target_dir )) > 0
23+
24+
25+ @pytest .mark .parametrize ("git_url" ,
26+ ["git://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git;protocol=git;branch=ci-test" ,
27+ "git://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git;protocol=git;tag=v32" ])
28+ def test_download_from_github_with_branch_or_tag (git_url ):
29+ # given
1330 target_dir = os .path .join (constants .TEST_RESULT_DIR , "download/example" )
14- success , _ , _ , _ = cli_download_and_extract ("https://github.com/LGE-OSS/example" ,
15- target_dir ,
16- "test_result/download_log/example" )
31+ log_dir = "test_result/download_log/example"
32+
33+ # when
34+ success , _ , _ , _ = cli_download_and_extract (git_url , target_dir , log_dir )
1735
1836 # then
1937 assert success is True
@@ -38,3 +56,85 @@ def test_download_from_wget(project_name, project_url):
3856 # then
3957 assert success is True
4058 assert len (os .listdir (target_dir )) > 0
59+
60+
61+ def test_download_git_clone_with_branch ():
62+ # given
63+ git_url = "git://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git"
64+ target_dir = os .path .join (constants .TEST_RESULT_DIR , "download/example" )
65+ branch_name = "ci-test"
66+
67+ # when
68+ success , _ , oss_name , oss_version = download_git_clone (git_url , target_dir , branch = branch_name )
69+
70+ # then
71+ assert success is True
72+ assert len (os .listdir (target_dir )) > 0
73+ assert oss_name == ''
74+ assert oss_version == branch_name
75+
76+
77+ def test_download_git_clone_with_tag ():
78+ # given
79+ git_url = "git://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git"
80+ target_dir = os .path .join (constants .TEST_RESULT_DIR , "download/example" )
81+ tag_name = "v32"
82+
83+ # when
84+ success , _ , oss_name , oss_version = download_git_clone (git_url , target_dir , tag = tag_name )
85+
86+ # then
87+ assert success is True
88+ assert len (os .listdir (target_dir )) > 0
89+ assert oss_name == ''
90+ assert oss_version == tag_name
91+
92+
93+ def test_download_main_branch_when_any_branch_or_tag_not_entered ():
94+ # given
95+ git_url = "https://github.com/LGE-OSS/example"
96+ target_dir = os .path .join (constants .TEST_RESULT_DIR , "download/example" )
97+ expected_oss_name = "main"
98+
99+ # when
100+ success , _ , oss_name , oss_version = download_git_clone (git_url , target_dir )
101+
102+ # then
103+ assert success is True
104+ assert len (os .listdir (target_dir )) > 0
105+ assert oss_name == 'LGE-OSS-example'
106+ assert oss_version == expected_oss_name
107+
108+
109+ def test_download_main_branch_when_non_existent_branch_entered ():
110+ # given
111+ git_url = "https://github.com/LGE-OSS/example"
112+ target_dir = os .path .join (constants .TEST_RESULT_DIR , "download/example" )
113+ branch_name = "non-existent-branch"
114+ expected_oss_name = "main"
115+
116+ # when
117+ success , _ , oss_name , oss_version = download_git_clone (git_url , target_dir , branch = branch_name )
118+
119+ # then
120+ assert success is True
121+ assert len (os .listdir (target_dir )) > 0
122+ assert oss_name == 'LGE-OSS-example'
123+ assert oss_version == expected_oss_name
124+
125+
126+ def test_download_main_branch_when_non_existent_tag_entered ():
127+ # given
128+ git_url = "https://github.com/LGE-OSS/example"
129+ target_dir = os .path .join (constants .TEST_RESULT_DIR , "download/example" )
130+ tag_name = "non-existent-tag"
131+ expected_oss_name = "main"
132+
133+ # when
134+ success , _ , oss_name , oss_version = download_git_clone (git_url , target_dir , tag = tag_name )
135+
136+ # then
137+ assert success is True
138+ assert len (os .listdir (target_dir )) > 0
139+ assert oss_name == 'LGE-OSS-example'
140+ assert oss_version == expected_oss_name
0 commit comments