Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[unit test][pfcwd] Fix tests that require sudo access #1340

Merged
merged 2 commits into from
Dec 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions tests/pfcwd_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import imp
import os
import sys
from unittest.mock import patch

from click.testing import CliRunner

from utilities_common.db import Db

from .pfcwd_input.pfcwd_test_vectors import *
Expand Down Expand Up @@ -78,7 +80,8 @@ def executor(self, testcase):
if 'rc_output' in input:
assert result.output == input['rc_output']

def test_pfcwd_start_ports_valid(self):
@patch('pfcwd.main.os')
def test_pfcwd_start_ports_valid(self, mock_os):
# pfcwd start --action drop --restoration-time 200 Ethernet0 200
import pfcwd.main as pfcwd
runner = CliRunner()
Expand All @@ -92,6 +95,7 @@ def test_pfcwd_start_ports_valid(self):
print(result.output)
assert result.output == pfcwd_show_config_output

mock_os.geteuid.return_value = 0
result = runner.invoke(
pfcwd.cli.commands["start"],
[
Expand All @@ -112,7 +116,8 @@ def test_pfcwd_start_ports_valid(self):
assert result.exit_code == 0
assert result.output == pfcwd_show_start_config_output_pass

def test_pfcwd_start_actions(self):
@patch('pfcwd.main.os')
def test_pfcwd_start_actions(self, mock_os):
# pfcwd start --action fwd --restoration-time 200 Ethernet0 200
import pfcwd.main as pfcwd
runner = CliRunner()
Expand All @@ -126,6 +131,7 @@ def test_pfcwd_start_actions(self):
print(result.output)
assert result.output == pfcwd_show_config_output

mock_os.geteuid.return_value = 0
result = runner.invoke(
pfcwd.cli.commands["start"],
[
Expand Down Expand Up @@ -267,7 +273,8 @@ def test_pfcwd_config_with_ports(self):
assert result.exit_code == 0
assert result.output == show_pfcwd_config_with_ports

def test_pfcwd_start_ports_masic_valid(self):
@patch('pfcwd.main.os')
def test_pfcwd_start_ports_masic_valid(self, mock_os):
# pfcwd start --action forward --restoration-time 200 Ethernet0 200
import pfcwd.main as pfcwd
runner = CliRunner()
Expand All @@ -280,6 +287,7 @@ def test_pfcwd_start_ports_masic_valid(self):
print(result.output)
assert result.output == show_pfc_config_all

mock_os.geteuid.return_value = 0
result = runner.invoke(
pfcwd.cli.commands["start"],
[
Expand All @@ -300,7 +308,8 @@ def test_pfcwd_start_ports_masic_valid(self):
assert result.exit_code == 0
assert result.output == show_pfc_config_start_pass

def test_pfcwd_start_actions_masic(self):
@patch('pfcwd.main.os')
def test_pfcwd_start_actions_masic(self, mock_os):
# pfcwd start --action drop --restoration-time 200 Ethernet0 200
import pfcwd.main as pfcwd
runner = CliRunner()
Expand All @@ -313,6 +322,7 @@ def test_pfcwd_start_actions_masic(self):
print(result.output)
assert result.output == show_pfc_config_all

mock_os.geteuid.return_value = 0
result = runner.invoke(
pfcwd.cli.commands["start"],
[
Expand Down