-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to run tests for all modules.
- Loading branch information
1 parent
c4d6fe8
commit 3d72f7a
Showing
2 changed files
with
47 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import subprocess | ||
|
||
# Get the environment variables given to us by the Makefile | ||
ARGS = os.environ.get('ARGS', '') | ||
EXTRA_ARGS = os.environ.get('EXTRA_ARGS', '') | ||
TEST_PACKAGES = os.environ.get('TEST_PACKAGES', '') | ||
CURRENT_DIR = os.getcwd() | ||
|
||
def find_go_modules(dir='.'): | ||
""" Find all go.mod files in the current directory and subdirectories. """ | ||
go_mod_files = [] | ||
for root, _, files in os.walk(dir): | ||
if 'go.mod' in files: | ||
go_mod_files.append(root) | ||
return go_mod_files | ||
|
||
def run_tests_for_module(module): | ||
""" Run the unit tests for the given module. """ | ||
path = os.path.join(CURRENT_DIR, module) | ||
os.chdir(path) | ||
|
||
print(f"Running unit tests for {path}") | ||
|
||
test_command = f'go test -mod=readonly {ARGS} {EXTRA_ARGS} {TEST_PACKAGES} ./...' | ||
result = subprocess.run(test_command, shell=True) | ||
return result.returncode | ||
|
||
|
||
def run_tests(dir): | ||
""" Run the unit tests for all modules in dir. """ | ||
print("Starting unit tests") | ||
|
||
# Find all go.mod files and get their directory names | ||
go_modules = find_go_modules(dir) | ||
|
||
exit_code = 0 | ||
for gomod in sorted(go_modules): | ||
exit_code = run_tests_for_module(gomod) | ||
exit(exit_code) | ||
|
||
if __name__ == '__main__': | ||
run_tests(os.getcwd()) |