Skip to main content

PluginTestRunner

Struct PluginTestRunner 

Source
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>

Source

pub fn new(plugin: P) -> Self

Create a new test runner for a plugin

Source

pub fn spec(&self) -> PluginSpec

Get plugin spec

Source

pub fn check_string(&self, content: &str) -> Result<Vec<LintError>, String>

Run the plugin check on a config string

Source

pub fn check_file(&self, path: &Path) -> Result<Vec<LintError>, String>

Run the plugin check on a file

Source

pub fn test_fixtures(&self, fixtures_dir: &str)

Test all fixtures in a directory

Source

pub fn assert_errors(&self, content: &str, expected_count: usize)

Assert that a config string produces specific errors

Source

pub fn assert_no_errors(&self, content: &str)

Assert that a config string produces no errors

Source

pub fn assert_has_errors(&self, content: &str)

Assert that a config string produces at least one error

Source

pub fn assert_error_on_line(&self, content: &str, expected_line: usize)

Assert that a config string produces an error on a specific line

Source

pub fn assert_error_message_contains( &self, content: &str, expected_substring: &str, )

Assert that errors contain a specific message substring

Source

pub fn assert_has_fix(&self, content: &str)

Assert that errors have fixes

Source

pub fn assert_fix_produces(&self, content: &str, expected: &str)

Assert that applying fixes produces the expected output

Source

pub fn test_examples(&self, bad_conf: &str, good_conf: &str)

Test using bad.conf and good.conf example content

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.