The code generated by TabNine is completely unusable:
Given('I have the sops configuration file "{sops_config_file}"'):
# Check if the sops configuration file exists
assert os.path.isfile(sops_config_file), f"SOPS configuration file {sops_config_file} does not exist"
And('I the file and folder structure "{folder}"'):
# Check if the folder exists and contains files
assert os.path.isdir(folder), f"Folder {folder} does not exist"
assert len(os.listdir(folder)) > 0, f"Folder {folder} is empty"
When('I call the python script "{script_path}" with the following arguments'):
def step_impl(context):
# Parse the arguments from the table
arguments = [row["arg_name"] + " " + row["arg_value"] for row in context.table]
# Call the python script with the arguments
context.output = call_python_script(script_path, arguments)
Then('The output should contain this <list> of files'):
def step_impl(context):
expected_files = context.table.row["list"].split(", ")
for file in expected_files:
assert file in context.output, f"Expected file {file} not found in output"
And('the output should not contain this <not_list> of files'):
def step_impl(context):
not_expected_files = context.table.row["not_list"].split(", ")
for file in not_expected_files:
assert file not in context.output, f"Unexpected file {file} found in output"
# Usage in the test runner
# Assuming the test runner is using behave
# feature_file.feature
# Feature: Sops age key rotation
# Scenario Outline: Get list of files that need to be encrypted
# Given I have the sops configuration file "../../flux/.sops.yaml"
# And I the file and folder structure "../../flux"
# When I call the python script "../../key_rotation.py" with the following arguments
# | arg_name | arg_value |
# | --age-key | <public_key> |
# | --list-files | |
# | --folder | "../../flux" |
# | --sops-config | "../../flux/.sops.yaml" |
# Then The output should contain this <list> of files
# And the output should not contain this <not_list> of files
#
# Examples:
# | public_key | list | not_list |
# | age1vzzjtxm5vx6zt5zgxa5g0kvj0h84l88n2rwzkyha49elwdkudczse8mu66 | test/secrets/database/password.yaml, test/tls-secrets/cert.pem, test/tls-secrets/key.pem | test/tls-secrets/tls-secrets.txt |
# | age19c7svc69r96apdtph2x3axmkqn7lypwmqsprnpjf06zjjq2r4epszxlnls | test/tls-secrets/cert.pem, test/tls-secrets/key.pem | test/secrets/database/password.yaml |
# | age1gwwfs5m35aqnrdxwuk3nj7h6539ewlq3kkvu6jlc6drmevueeqdq0mwcg4 | | |
In the solution, the step definitions for the scenario "Get list of files that need to be encrypted" are implemented using the behave framework. The step definitions check the existence of the sops configuration file, the folder structure, and the output of the python script. The expected and not expected files are validated against the script output.
The code generated by TabNine is completely unusable: