2
2
import json
3
3
import subprocess
4
4
import pytest
5
+ import sys
5
6
6
7
from typing import Set , Optional , List
7
8
8
9
GH_INTEGRATION_TESTS_TOKEN = os .environ ["GH_INTEGRATION_TESTS_TOKEN" ]
10
+ BITBUCKET_INTEGRATION_TESTS_TOKEN = os .environ ["BITBUCKET_INTEGRATION_TESTS_TOKEN" ]
11
+ BITBUCKET_INTEGRATION_TESTS_URL = os .environ ["BITBUCKET_INTEGRATION_TESTS_URL" ]
9
12
10
- def run_src_fingerprint (provider : str , args : Optional [List [str ]] = []):
11
- subprocess .run (
13
+ def run_src_fingerprint (provider : str , token : str , args : Optional [List [str ]] = []):
14
+ return subprocess .run (
12
15
[
13
16
"./src-fingerprint" ,
17
+ "-v" ,
14
18
"collect" ,
15
19
"-p" ,
16
20
provider ,
17
21
"--token" ,
18
- GH_INTEGRATION_TESTS_TOKEN ,
22
+ token ,
19
23
"-f" ,
20
24
"jsonl" ,
21
25
"-o" ,
22
26
"fingerprints.jsonl"
23
27
] + args ,
24
- check = True
28
+ check = True ,
29
+ stdout = subprocess .PIPE ,
30
+ stderr = subprocess .STDOUT ,
25
31
)
26
32
27
33
def load_jsonl (jsonl_path ):
@@ -34,7 +40,7 @@ def get_output_repos(output_path) -> Set[str]:
34
40
35
41
36
42
def test_local_repository ():
37
- run_src_fingerprint (provider = "repository" , args = ["--object" , "../src-fingerprint" ])
43
+ run_src_fingerprint (provider = "repository" , token = GH_INTEGRATION_TESTS_TOKEN , args = ["--object" , "../src-fingerprint" ])
38
44
repos = get_output_repos ("fingerprints.jsonl" )
39
45
os .remove ("fingerprints.jsonl" )
40
46
assert len (repos ) == 1
@@ -118,8 +124,8 @@ def test_local_repository():
118
124
)
119
125
]
120
126
)
121
- def test_src_fingerprint_no_object_specified (title , cmd_args , expected_output_repos ):
122
- run_src_fingerprint (provider = "github" , args = cmd_args )
127
+ def test_src_fingerprint_github_no_object_specified (title , cmd_args , expected_output_repos ):
128
+ run_src_fingerprint (provider = "github" , token = GH_INTEGRATION_TESTS_TOKEN , args = cmd_args )
123
129
output_repos = get_output_repos ("fingerprints.jsonl" )
124
130
os .remove ("fingerprints.jsonl" )
125
131
assert output_repos == expected_output_repos
@@ -179,8 +185,48 @@ def test_src_fingerprint_no_object_specified(title, cmd_args, expected_output_re
179
185
)
180
186
]
181
187
)
182
- def test_src_fingerprint_on_org (title , cmd_args , expected_output_repos ):
183
- run_src_fingerprint (provider = "github" , args = ["--object" , "gg-src-fingerprint-org" ]+ cmd_args )
188
+ def test_src_fingerprint_github_on_org (title , cmd_args , expected_output_repos ):
189
+ run_src_fingerprint (provider = "github" , token = GH_INTEGRATION_TESTS_TOKEN , args = ["--object" , "gg-src-fingerprint-org" ]+ cmd_args )
190
+ output_repos = get_output_repos ("fingerprints.jsonl" )
191
+ os .remove ("fingerprints.jsonl" )
192
+ assert output_repos == expected_output_repos
193
+
194
+
195
+ @pytest .mark .parametrize (
196
+ "title, cmd_args, number_of_expected_output_repos" , [
197
+ (
198
+ "Get all repos accesible to integration tests token" ,
199
+ ["--limit" , "10" ],
200
+ 10
201
+ ),
202
+ ]
203
+ )
204
+ def test_src_fingerprint_bitbucket_no_object_specified (title , cmd_args , number_of_expected_output_repos ):
205
+ output = run_src_fingerprint (
206
+ provider = "bitbucket" ,
207
+ token = BITBUCKET_INTEGRATION_TESTS_TOKEN ,
208
+ args = cmd_args + ["--provider-url" , BITBUCKET_INTEGRATION_TESTS_URL ]
209
+ )
210
+ output_repos = get_output_repos ("fingerprints.jsonl" )
211
+ os .remove ("fingerprints.jsonl" )
212
+ assert len (output_repos ) == number_of_expected_output_repos
213
+
214
+
215
+ @pytest .mark .parametrize (
216
+ "title, cmd_args, expected_output_repos" , [
217
+ (
218
+ "Get all repos accesible to integration tests token for project 'src fingerprint'" ,
219
+ ["--limit" , "10" ,"--object" , "src fingerprint" ],
220
+ {"src fingerprint test" , "main-test-repo" }
221
+ ),
222
+ ]
223
+ )
224
+ def test_src_fingerprint_bitbucket_object_specified (title , cmd_args , expected_output_repos ):
225
+ output = run_src_fingerprint (
226
+ provider = "bitbucket" ,
227
+ token = BITBUCKET_INTEGRATION_TESTS_TOKEN ,
228
+ args = cmd_args + ["--provider-url" , BITBUCKET_INTEGRATION_TESTS_URL ]
229
+ )
184
230
output_repos = get_output_repos ("fingerprints.jsonl" )
185
231
os .remove ("fingerprints.jsonl" )
186
232
assert output_repos == expected_output_repos
0 commit comments