blob: 82df4f807897924a16c0b527727e5e7e4776ac74 [file] [log] [blame]
Dong Ma0a05b5c2024-11-24 13:27:29 +08001# Copyright (c) 2024 VEXXHOST, Inc.
2# SPDX-License-Identifier: Apache-2.0
3
4import glob
5import os
6import subprocess
7
8
9def run_helm_unittest(charts_dir, exclusions):
10 """
11 :param charts_dir: The directory containing Helm charts.
12 :param exclusions: List of subdirectories to exclude.
13 """
14 all_tests_passed = True
15 charts = [
16 os.path.basename(d)
17 for d in glob.glob(os.path.join(charts_dir, "*"))
18 if os.path.isdir(d) and os.path.basename(d) not in exclusions
19 ]
20 for chart in charts:
21 print(f"Running helm unittest for chart: {chart}")
22 chart_tests_path = f"../../roles/{chart}/tests/*.yaml"
23 chart_path = os.path.join(charts_dir, chart)
24 try:
25 # Run helm unittest
26 subprocess.run(
27 ["helm", "unittest", "-f", chart_tests_path, chart_path],
28 check=True,
29 )
30 print(f"Helm unitest passed for chart: {chart}")
31 except subprocess.CalledProcessError as e:
32 print(f"Helm unittest failed for chart: {chart}")
33 all_tests_passed = False
34 raise e
35 if all_tests_passed:
36 print("\nAll Helm unitests passed successfully!")
37 exit(0)
38 else:
39 print("\nOne or more charts had test failures.")
40 exit(1)
41
42
43def main():
44 charts_dir = os.getenv("CHARTS_DIR", "charts")
45 exclusions = ["patches"]
46 run_helm_unittest(charts_dir, exclusions)
47
48
49if __name__ == "__main__":
50 main()