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 41c0be3 commit 00e7c5f
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions tests/kdump_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ 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'
ssh_string = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEArV1..."

Expand Down Expand Up @@ -134,14 +137,34 @@ 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)
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
Expand All @@ -153,10 +176,27 @@ def test_config_kdump_add_ssh_path(self, get_cmd_module):

# Test case where KDUMP table is missing
db.cfgdb.delete_table("KDUMP")
result = runner.invoke(config.config.commands["kdump"].commands["add"].commands["ssh_path"], [ssh_path], obj=db)
result = runner.invoke(
config.config.commands["kdump"].commands["add"].commands["ssh_path"],
[ssh_path],
obj=db
)
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_path"],
[ssh_path],
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_remove_ssh_string(self, get_cmd_module):
(config, show) = get_cmd_module
db = Db()
Expand Down

0 comments on commit 00e7c5f

Please sign in to comment.