Skip to content

Commit

Permalink
skip tests that require passwordless sudo for local development
Browse files Browse the repository at this point in the history
Only run them when ST2_CI==true to minimize requirements for local development.
Also fix a typo in a comment.
  • Loading branch information
cognifloyd committed Nov 12, 2024
1 parent c1c4c7c commit dddedf0
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from __future__ import absolute_import
import os
import unittest
import uuid

import mock
Expand Down Expand Up @@ -45,6 +46,8 @@

__all__ = ["LocalShellCommandRunnerTestCase", "LocalShellScriptRunnerTestCase"]

ST2_CI = os.environ.get("ST2_CI", "false").lower() == "true"

MOCK_EXECUTION = mock.Mock()
MOCK_EXECUTION.id = "598dbf0c0640fd54bffc688b"

Expand Down Expand Up @@ -94,6 +97,11 @@ def test_shell_command_action_basic(self):
self.assertEqual(output_dbs[0].output_type, "stdout")
self.assertEqual(output_dbs[0].data, "10\n")

# This test depends on passwordless sudo. Don't require that for local development.
@unittest.skipIf(
not ST2_CI,
'Skipping tests because ST2_CI environment variable is not set to "true"',
)
def test_timeout(self):
models = self.fixtures_loader.load_models(
fixtures_pack=GENERIC_PACK, fixtures_dict={"actions": ["local.yaml"]}
Expand Down Expand Up @@ -141,8 +149,13 @@ def test_common_st2_env_vars_are_available_to_the_action(self):
self.assertEqual(status, action_constants.LIVEACTION_STATUS_SUCCEEDED)
self.assertEqual(result["stdout"].strip(), "mock-token")

# This test depends on passwordless sudo. Don't require that for local development.
@unittest.skipIf(
not ST2_CI,
'Skipping tests because ST2_CI environment variable is not set to "true"',
)
def test_sudo_and_env_variable_preservation(self):
# Verify that the environment environment are correctly preserved when running as a
# Verify that the environment vars are correctly preserved when running as a
# root / non-system user
# Note: This test will fail if SETENV option is not present in the sudoers file
models = self.fixtures_loader.load_models(
Expand Down Expand Up @@ -297,6 +310,11 @@ def test_action_stdout_and_stderr_is_stored_in_the_db_short_running_action(
self.assertEqual(output_dbs[db_index_1].data, mock_stderr[0])
self.assertEqual(output_dbs[db_index_2].data, mock_stderr[1])

# This test depends on passwordless sudo. Don't require that for local development.
@unittest.skipIf(
not ST2_CI,
'Skipping tests because ST2_CI environment variable is not set to "true"',
)
def test_shell_command_sudo_password_is_passed_to_sudo_binary(self):
# Verify that sudo password is correctly passed to sudo binary via stdin
models = self.fixtures_loader.load_models(
Expand Down

0 comments on commit dddedf0

Please sign in to comment.