Skip to content

Commit

Permalink
updated test case
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadalihussnain committed Sep 26, 2024
1 parent 00e7c5f commit 623f822
Showing 1 changed file with 33 additions and 36 deletions.
69 changes: 33 additions & 36 deletions tests/kdump_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ def test_config_kdump_add_ssh_string(self, get_cmd_module):
db = Db()
runner = CliRunner()

# Simulate enabling the remote feature
db.cfgdb.mod_entry("KDUMP", "config", {"remote": True})

# Simulate command execution for 'add ssh_string'
# Simulate command execution for 'add ssh_string' without enabling the remote feature
ssh_string = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEArV1..."

result = runner.invoke(
Expand All @@ -117,6 +114,20 @@ def test_config_kdump_add_ssh_string(self, get_cmd_module):
obj=db
)

# Assert that the command fails when the remote feature is not enabled
assert result.exit_code != 0
assert "Remote feature is not enabled. Please enable the remote feature first." in result.output

# Now enable the remote feature
db.cfgdb.mod_entry("KDUMP", "config", {"remote": True})

# Simulate command execution for 'add ssh_string' again
result = runner.invoke(
config.config.commands["kdump"].commands["add"].commands["ssh_string"],
[ssh_string],
obj=db
)

# Assert that the command executed successfully
assert result.exit_code == 0
assert f"SSH string added to KDUMP configuration: {ssh_string}" in result.output
Expand All @@ -137,44 +148,13 @@ def test_config_kdump_add_ssh_string(self, get_cmd_module):
assert result.exit_code == 1
assert "Unable to retrieve 'KDUMP' table from Config DB." in result.output

# Test case when remote feature is not enabled
db.cfgdb.mod_entry("KDUMP", "config", {"remote": False})
result = runner.invoke(
config.config.commands["kdump"].commands["add"].commands["ssh_string"],
[ssh_string],
obj=db
)

# Assert that the command fails because remote feature is disabled
assert result.exit_code == 1
assert "Remote feature is not enabled. Please enable the remote feature first." in result.output


def test_config_kdump_add_ssh_path(self, get_cmd_module):
(config, show) = get_cmd_module
db = Db()
runner = CliRunner()

# Simulate enabling the remote feature
db.cfgdb.mod_entry("KDUMP", "config", {"remote": True})

# Simulate command execution for 'add ssh_path'
ssh_path = "/root/.ssh/id_rsa"
result = runner.invoke(
config.config.commands["kdump"].commands["add"].commands["ssh_path"],
[ssh_path],
obj=db
)

# Assert that the command executed successfully
assert result.exit_code == 0
assert f"SSH path added to KDUMP configuration: {ssh_path}" in result.output

# Retrieve the updated table to ensure the SSH path was added
kdump_table = db.cfgdb.get_table("KDUMP")
assert kdump_table["config"]["ssh_path"] == ssh_path

# Test case where KDUMP table is missing
ssh_path = "/root/.ssh/id_rsa"
db.cfgdb.delete_table("KDUMP")
result = runner.invoke(
config.config.commands["kdump"].commands["add"].commands["ssh_path"],
Expand All @@ -196,6 +176,23 @@ def test_config_kdump_add_ssh_path(self, get_cmd_module):
assert result.exit_code == 1
assert "Remote feature is not enabled. Please enable the remote feature first." in result.output

# Now enable the remote feature
db.cfgdb.mod_entry("KDUMP", "config", {"remote": True})

# Simulate command execution for 'add ssh_path' again
result = runner.invoke(
config.config.commands["kdump"].commands["add"].commands["ssh_path"],
[ssh_path],
obj=db
)

# Assert that the command executed successfully
assert result.exit_code == 0
assert f"SSH path added to KDUMP configuration: {ssh_path}" in result.output

# Retrieve the updated table to ensure the SSH path was added
kdump_table = db.cfgdb.get_table("KDUMP")
assert kdump_table["config"]["ssh_path"] == ssh_path

def test_config_kdump_remove_ssh_string(self, get_cmd_module):
(config, show) = get_cmd_module
Expand Down

0 comments on commit 623f822

Please sign in to comment.