Skip to content

Commit 7507cb5

Browse files
committed
feat(test): add integration tests for src-fingerprint
1 parent 69c4836 commit 7507cb5

File tree

2 files changed

+210
-0
lines changed

2 files changed

+210
-0
lines changed

.github/workflows/test.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,29 @@ jobs:
3737
run: |
3838
go test -race $(go list ./...) -v -coverprofile=.coverage.out
3939
go tool cover -func=.coverage.out
40+
integration-tests:
41+
name: Integration Tests
42+
runs-on: ${{ matrix.os }}
43+
if: github.event_name == 'push'
44+
strategy:
45+
matrix:
46+
os: [ubuntu-latest, macos-latest, windows-latest]
47+
steps:
48+
- name: Set up Go 1.16
49+
uses: actions/setup-go@v1
50+
with:
51+
go-version: 1.16
52+
id: go
53+
54+
- name: Check out code into the Go module directory
55+
uses: actions/checkout@v2
56+
57+
- name: Build
58+
run: go build -v -o . ./cmd/src-fingerprint
59+
60+
- name: Run Integration Tests
61+
env:
62+
GH_INTEGRATION_TESTS_TOKEN: ${{ secrets.GH_INTEGRATION_TESTS_TOKEN }}
63+
run: |
64+
python3 -m pip install pytest
65+
pytest tests

tests/integration_test.py

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
import os
2+
import json
3+
import subprocess
4+
import pytest
5+
6+
from typing import Set, Optional, List
7+
8+
GH_INTEGRATION_TESTS_TOKEN = os.environ["GH_INTEGRATION_TESTS_TOKEN"]
9+
10+
def run_src_fingerprint(provider: str, args: Optional[List[str]] = []):
11+
subprocess.run(
12+
[
13+
"./src-fingerprint",
14+
"-p",
15+
provider,
16+
"--token",
17+
GH_INTEGRATION_TESTS_TOKEN,
18+
"-f",
19+
"jsonl",
20+
"-o",
21+
"fingerprints.jsonl"
22+
] + args,
23+
check=True
24+
)
25+
26+
def load_jsonl(jsonl_path):
27+
with open(jsonl_path) as f:
28+
for line in f:
29+
yield json.loads(line)
30+
31+
def get_output_repos(output_path) -> Set[str]:
32+
return {x["repository_name"] for x in load_jsonl(output_path)}
33+
34+
35+
def test_local_repository():
36+
run_src_fingerprint(provider="repository", args=["--object", "."])
37+
repos = get_output_repos("fingerprints.jsonl")
38+
os.remove("fingerprints.jsonl")
39+
assert len(repos) == 1
40+
41+
42+
@pytest.mark.parametrize(
43+
"title, cmd_args, expected_output_repos", [
44+
(
45+
"Get all private repos accesible to user gg-src-fingerprint except archived ones",
46+
[],
47+
{
48+
# Repos for user gg-src-fingerprint
49+
"main_private",
50+
# Repos for org gg-src-fingerprint-org
51+
"external_private",
52+
"gg_src_fingerprint_private",
53+
}
54+
),
55+
(
56+
"Get all private repos accesible to user gg-src-fingerprint",
57+
["--include-archived-repos"],
58+
{
59+
# Repos for user gg-src-fingerprint
60+
"main_private_archive",
61+
"main_private",
62+
# Repos for org gg-src-fingerprint-org
63+
"gg_src_fingerprint_private",
64+
"gg_src_fingerprint_private_archive",
65+
"external_private",
66+
}
67+
),
68+
(
69+
"Get all repos accesible to user gg-src-fingerprint except archived ones",
70+
["--include-public-repos", "--include-forked-repos"],
71+
{
72+
# Repos for user gg-src-fingerprint
73+
"main_private",
74+
"main_public",
75+
"src-fingerprint",
76+
# Repos for org gg-src-fingerprint-org
77+
"external_private",
78+
"gg_src_fingerprint_private",
79+
"gg_src_fingerprint_public",
80+
}
81+
),
82+
(
83+
"Get all repos accesible to user gg-src-fingerprint except forked ones",
84+
["--include-public-repos", "--include-archived-repos"],
85+
{
86+
# Repos for user gg-src-fingerprint
87+
"main_archive",
88+
"main_private",
89+
"main_private_archive",
90+
"main_public",
91+
# Repos for org gg-src-fingerprint-org
92+
"external_private",
93+
"gg_src_fingerprint_private",
94+
"gg_src_fingerprint_private_archive",
95+
"gg_src_fingerprint_public",
96+
"gg_src_fingerprint_public_archive",
97+
}
98+
),
99+
(
100+
"Get all repos accesible to user gg-src-fingerprint",
101+
["--include-public-repos", "--include-archived-repos", "--include-forked-repos"],
102+
{
103+
# Repos for user gg-src-fingerprint
104+
"main_archive",
105+
"main_private",
106+
"main_private_archive",
107+
"main_public",
108+
"src-fingerprint",
109+
# Repos for org gg-src-fingerprint-org
110+
"external_private",
111+
"gg_src_fingerprint_private",
112+
"gg_src_fingerprint_private_archive",
113+
"gg_src_fingerprint_public",
114+
"gg_src_fingerprint_public_archive",
115+
}
116+
)
117+
]
118+
)
119+
def test_src_fingerprint_no_object_specified(title, cmd_args, expected_output_repos):
120+
run_src_fingerprint(provider="github", args=cmd_args)
121+
output_repos = get_output_repos("fingerprints.jsonl")
122+
os.remove("fingerprints.jsonl")
123+
assert output_repos == expected_output_repos
124+
125+
126+
@pytest.mark.parametrize(
127+
"title, cmd_args, expected_output_repos", [
128+
(
129+
"Get all private repos except archived ones for org gg-src-fingerprint-org",
130+
[],
131+
{
132+
"gg_src_fingerprint_private",
133+
"external_private"
134+
}
135+
),
136+
(
137+
"Get all private repos for org gg-src-fingerprint-org",
138+
["--include-archived-repos"],
139+
{
140+
"gg_src_fingerprint_private",
141+
"gg_src_fingerprint_private_archive",
142+
"external_private",
143+
}
144+
),
145+
(
146+
"Get all repos for org gg-src-fingerprint-org except archived ones",
147+
["--include-public-repos", "--include-forked-repos"],
148+
{
149+
"external_private",
150+
"gg_src_fingerprint_private",
151+
"gg_src_fingerprint_public",
152+
"src-fingerprint",
153+
}
154+
),
155+
(
156+
"Get all repos for org gg-src-fingerprint-org except forked ones",
157+
["--include-public-repos", "--include-archived-repos"],
158+
{
159+
"external_private",
160+
"gg_src_fingerprint_private",
161+
"gg_src_fingerprint_private_archive",
162+
"gg_src_fingerprint_public",
163+
"gg_src_fingerprint_public_archive",
164+
}
165+
),
166+
(
167+
"Get all repos for org gg-src-fingerprint-org",
168+
["--include-public-repos", "--include-archived-repos", "--include-forked-repos"],
169+
{
170+
"external_private",
171+
"gg_src_fingerprint_private",
172+
"gg_src_fingerprint_private_archive",
173+
"gg_src_fingerprint_public",
174+
"gg_src_fingerprint_public_archive",
175+
"src-fingerprint",
176+
}
177+
)
178+
]
179+
)
180+
def test_src_fingerprint_on_org(title, cmd_args, expected_output_repos):
181+
run_src_fingerprint(provider="github", args=["--object", "gg-src-fingerprint-org"]+cmd_args)
182+
output_repos = get_output_repos("fingerprints.jsonl")
183+
os.remove("fingerprints.jsonl")
184+
assert output_repos == expected_output_repos

0 commit comments

Comments
 (0)