Skip to content

Commit

Permalink
rework github workflow config handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Szefler committed Jul 5, 2024
1 parent 98eb998 commit 49e5324
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test-prometrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jobs:
kubectl get namespaces
echo "=== PODS ==="
kubectl get pods --all-namespaces
echo "=== PROMETHEUS NS ==="
kubectl get all –namespace prometheus
# install Prometrix so that we can run tests on it
- name: Install Prometrix
Expand All @@ -44,7 +46,5 @@ jobs:
# run the actual tests
- name: Test Prometrix
env:
TEST_CONFIG: ${{ secrets.TEST_CONFIG }}
run: |
python tests/main.py --from-env
python tests/main.py tests/config_github_kind.yaml
9 changes: 9 additions & 0 deletions tests/config_github_kind.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
testConfig:
- type: "PrometheusConfig"
params:
url:
disable_ssl:
headers:
prometheus_auth:
prometheus_url_query_string:
additional_labels:
35 changes: 13 additions & 22 deletions tests/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,18 @@ def run_test(test_type: str, config: PrometheusConfig):
print(f"Test {test_type} failed, results of wrong format")


def main(from_env=False):
if not from_env:
test_config_file_name = "config.yaml"
if not os.path.isfile(test_config_file_name):
print(
f"To run tests you must create a test config file called '{test_config_file_name}'.\n See 'test_config_example.yaml' for the format and examples"
)
return
with open(test_config_file_name, "r") as tests_yaml_file:
yaml_obj = yaml.safe_load(
tests_yaml_file
) # yaml_object will be a list or a dict
else:
print(f"Getting config YAML from env variable TEST_CONFIG")
yaml_text = os.environ.get("TEST_CONFIG")
if not yaml_text:
print("To run tests inside Github workflow, you must define the TEST_CONFIG secret")
sys.exit(1)
yaml_obj = yaml.safe_load(yaml_text)
def main(config_file="config.yaml"):
print(f"Using config file {config_file}")
if not os.path.isfile(config_file):
print(
"To run tests you must create a test config file.\n See 'test_config_example.yaml' for "
"the format and examples"
)
return
with open(config_file, "r") as tests_yaml_file:
yaml_obj = yaml.safe_load(
tests_yaml_file
) # yaml_object will be a list or a dict

for test_config in yaml_obj["testConfig"]:
config_type = test_config["type"]
Expand All @@ -100,8 +93,6 @@ def main(from_env=False):

if __name__ == "__main__":
if len(sys.argv) == 2:
# Get configuration from Github secrets
main(from_env=True)
main(config_file=sys.argv[1])
else:
# Get configuration from a local file
main()

0 comments on commit 49e5324

Please sign in to comment.