1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//! This module implements test support helpers.

use app::Pencil;
use wrappers::{Request, Response};


/// This type allows to send requests to a wrapped application.
#[allow(dead_code)]
pub struct PencilClient<'c> {
    application: &'c Pencil,
}

impl<'c> PencilClient<'c> {
    /// Create a new `PencilClient`.
    pub fn new(application: &Pencil) -> PencilClient {
        PencilClient { application: application }
    }

    /// Get wrapped application.
    #[allow(dead_code)]
    pub fn get_application(&self) -> &Pencil {
        return self.application;
    }

    /// Runs the wrapped pencil app with the given request.
    fn run_pencil_app(&self, request: &mut Request) -> Response {
        self.application.handle_request(request)
    }

    fn open(&self, mut request: Request) -> Response {
        self.run_pencil_app(&mut request)
    }

    #[allow(dead_code)]
    pub fn get(&self, request: Request) -> Response {
        self.open(request)
    }
}