pub struct PluginTestRunner<P: Plugin> { /* private fields */ }Expand description
Test runner for plugins.
Provides assertion methods for testing plugin behavior against nginx config strings and fixture directories.
§Example
use nginx_lint_plugin::prelude::*;
use nginx_lint_plugin::testing::PluginTestRunner;
let runner = PluginTestRunner::new(MyPlugin);
// Test a config string
runner.assert_has_errors("http {\n bad on;\n}");
runner.assert_no_errors("http {\n good on;\n}");
runner.assert_errors("http {\n bad on;\n bad on;\n}", 2);
runner.assert_error_on_line("http {\n bad on;\n}", 2);Implementations§
Source§impl<P: Plugin> PluginTestRunner<P>
impl<P: Plugin> PluginTestRunner<P>
Sourcepub fn spec(&self) -> PluginSpec
pub fn spec(&self) -> PluginSpec
Get plugin spec
Sourcepub fn check_string(&self, content: &str) -> Result<Vec<LintError>, String>
pub fn check_string(&self, content: &str) -> Result<Vec<LintError>, String>
Run the plugin check on a config string
Sourcepub fn check_file(&self, path: &Path) -> Result<Vec<LintError>, String>
pub fn check_file(&self, path: &Path) -> Result<Vec<LintError>, String>
Run the plugin check on a file
Sourcepub fn test_fixtures(&self, fixtures_dir: &str)
pub fn test_fixtures(&self, fixtures_dir: &str)
Test all fixtures in a directory
Sourcepub fn assert_errors(&self, content: &str, expected_count: usize)
pub fn assert_errors(&self, content: &str, expected_count: usize)
Assert that a config string produces specific errors
Sourcepub fn assert_no_errors(&self, content: &str)
pub fn assert_no_errors(&self, content: &str)
Assert that a config string produces no errors
Sourcepub fn assert_has_errors(&self, content: &str)
pub fn assert_has_errors(&self, content: &str)
Assert that a config string produces at least one error
Sourcepub fn assert_error_on_line(&self, content: &str, expected_line: usize)
pub fn assert_error_on_line(&self, content: &str, expected_line: usize)
Assert that a config string produces an error on a specific line
Sourcepub fn assert_error_message_contains(
&self,
content: &str,
expected_substring: &str,
)
pub fn assert_error_message_contains( &self, content: &str, expected_substring: &str, )
Assert that errors contain a specific message substring
Sourcepub fn assert_has_fix(&self, content: &str)
pub fn assert_has_fix(&self, content: &str)
Assert that errors have fixes
Sourcepub fn assert_fix_produces(&self, content: &str, expected: &str)
pub fn assert_fix_produces(&self, content: &str, expected: &str)
Assert that applying fixes produces the expected output
Sourcepub fn test_examples(&self, bad_conf: &str, good_conf: &str)
pub fn test_examples(&self, bad_conf: &str, good_conf: &str)
Test using bad.conf and good.conf example content
Sourcepub fn test_examples_with_fix(&self, bad_conf: &str, good_conf: &str)
pub fn test_examples_with_fix(&self, bad_conf: &str, good_conf: &str)
Test using bad.conf and good.conf, and verify fix converts bad to good
Auto Trait Implementations§
impl<P> Freeze for PluginTestRunner<P>where
P: Freeze,
impl<P> RefUnwindSafe for PluginTestRunner<P>where
P: RefUnwindSafe,
impl<P> Send for PluginTestRunner<P>where
P: Send,
impl<P> Sync for PluginTestRunner<P>where
P: Sync,
impl<P> Unpin for PluginTestRunner<P>where
P: Unpin,
impl<P> UnsafeUnpin for PluginTestRunner<P>where
P: UnsafeUnpin,
impl<P> UnwindSafe for PluginTestRunner<P>where
P: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more