Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DerTiedemann committed Nov 27, 2024
1 parent 68f61ee commit fed5272
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
10 changes: 5 additions & 5 deletions actions/gcp-gsm-parse-secrets/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ def main(
# Deduplicate the input secrets
input_secrets = set(input_secrets.splitlines())

output = ""
output = []
parsed_secret_names = []
for secret in input_secrets:
parsed_secret, parsed_secret_name = (
parse_secret(secret, gcp_project, github_output_delimter) + "\n"
parsed_secret, parsed_secret_name = parse_secret(
secret, gcp_project, github_output_delimter
)
output += parsed_secret
output.append(parsed_secret)
parsed_secret_names.append(parsed_secret_name)

set_github_action_output("secrets-list", output, github_output_delimter)
set_github_action_output("secrets-list", "\n".join(output), github_output_delimter)
set_github_action_output(
"secret-names", ",".join(parsed_secret_names), github_output_delimter
)
Expand Down
35 changes: 27 additions & 8 deletions actions/gcp-gsm-parse-secrets/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,36 @@

from main import parse_secret


class TestParseSecret(unittest.TestCase):
def test_parse_secret(self):
self.assertEqual(parse_secret("secret_name", "project_name"), "SECRET_NAME:project_name/secret_name")
self.assertEqual(parse_secret("secret_name/version", "project_name"), "SECRET_NAME:project_name/secret_name/version")
self.assertEqual(parse_secret("123-456", "project_name"), "123_456:project_name/123-456")
self.assertEqual(parse_secret("123___123___123", "project_name"), "123_123_123:project_name/123___123___123")
self.assertEqual(parse_secret("i-like_trains__why_this?", "project_name"), "I_LIKE_TRAINS_WHY_THIS:project_name/i-like_trains__why_this?")
self.assertEqual(
parse_secret("secret_name", "project_name")[0],
"SECRET_NAME:project_name/secret_name",
)
self.assertEqual(
parse_secret("secret_name/version", "project_name")[0],
"SECRET_NAME:project_name/secret_name/version",
)
self.assertEqual(
parse_secret("123-456", "project_name")[0], "123_456:project_name/123-456"
)
self.assertEqual(
parse_secret("123___123___123", "project_name")[0],
"123_123_123:project_name/123___123___123",
)
self.assertEqual(
parse_secret("i-like_trains__why_this?", "project_name")[0],
"I_LIKE_TRAINS_WHY_THIS:project_name/i-like_trains__why_this?",
)

def test_parse_secret_special(self):
# FIXME: this test is failing and i dont know why
self.assertEqual(parse_secret("123&&123()123__123*__*_123", "project_name"), "123_123_123_123:project_name/123&&123()123__123*__*_123")
self.assertEqual(
parse_secret("123&&123()123__123*__*_123", "project_name")[0],
"123_123_123_123:project_name/123&&123()123__123*__*_123",
)


if __name__ == '__main__':
unittest.main()
if __name__ == "__main__":
unittest.main()

0 comments on commit fed5272

Please sign in to comment.