fn validate_error(
    swanling_metrics: &SwanlingMetrics,
    mock_endpoints: &[MockRef],
    configuration: &SwanlingConfiguration,
    test_type: TestType,
) {
    // Confirm that we loaded the mock endpoints.
    assert!(mock_endpoints[INDEX_KEY].hits() > 0);
    assert!(mock_endpoints[A_404_KEY].hits() > 0);

    // Get request metrics.
    let index_metrics = swanling_metrics
        .requests
        .get(&format!("GET {}", INDEX_PATH))
        .unwrap();
    let a_404_metrics = swanling_metrics
        .requests
        .get(&format!("GET {}", A_404_PATH))
        .unwrap();

    // Get error metrics.
    let a_404_errors = swanling_metrics.errors.clone();

    // Confirm that the path and method are correct in the metrics.
    assert!(index_metrics.path == INDEX_PATH);
    assert!(index_metrics.method == SwanlingMethod::Get);
    assert!(a_404_metrics.path == A_404_PATH);
    assert!(a_404_metrics.method == SwanlingMethod::Get);

    // All requests to the index succeeded.
    mock_endpoints[INDEX_KEY].assert_hits(index_metrics.raw_data.counter);
    mock_endpoints[INDEX_KEY].assert_hits(index_metrics.success_count);
    // All requests to the 404 page failed.
    mock_endpoints[A_404_KEY].assert_hits(a_404_metrics.raw_data.counter);
    mock_endpoints[A_404_KEY].assert_hits(a_404_metrics.fail_count);

    match test_type {
        TestType::ErrorSummary => {
            // The 404 path was captured as an error.
            assert!(a_404_errors.len() == 1);
            // Extract the error from the BTreeMap.
            for error in a_404_errors {
                // The captured error was a GET request.
                assert!(error.1.method == SwanlingMethod::Get);
                // The captured error was for the 404 path.
                assert!(error.1.name == A_404_PATH);
                // The error was captured the number of times we requested the 404 path.
                assert!(error.1.occurrences == a_404_metrics.fail_count);
            }
        }
        TestType::NoErrorSummary => {
            // Swanling was configured to not capture any errors.
            assert!(a_404_errors.is_empty());
        }
    }

    // The index always loaded successfully.
    assert!(index_metrics.fail_count == 0);

    // The 404 path was always an error.
    assert!(a_404_metrics.success_count == 0);

    // Verify that Swanling started the correct number of users.
    assert!(swanling_metrics.users == configuration.users.unwrap());
}
// Helper to confirm all variations generate appropriate results.
Helper to confirm all variations generate appropriate results.
Helper to confirm all variations generate appropriate results .
fn validate_error(
    swanling_metrics: &SwanlingMetrics,
    mock_endpoints: &[MockRef],
    configuration: &SwanlingConfiguration,
    test_type: TestType,
) {
    // Confirm that we loaded the mock endpoints.
    assert!(mock_endpoints[INDEX_KEY].hits() > 0);
    assert!(mock_endpoints[A_404_KEY].hits() > 0);
    // Get request metrics.
    let index_metrics = swanling_metrics
        .requests
        .get(&format!("GET {}", INDEX_PATH))
        .unwrap();
    let a_404_metrics = swanling_metrics
        .requests
        .get(&format!("GET {}", A_404_PATH))
        .unwrap();
    // Get error metrics.
    let a_404_errors = swanling_metrics.errors.clone();
    // Confirm that the path and method are correct in the metrics.
    assert!(index_metrics.path == INDEX_PATH);
    assert!(index_metrics.method == SwanlingMethod::Get);
    assert!(a_404_metrics.path == A_404_PATH);
    assert!(a_404_metrics.method == SwanlingMethod::Get);
    // All requests to the index succeeded.
    mock_endpoints[INDEX_KEY].assert_hits(index_metrics.raw_data.counter);
    mock_endpoints[INDEX_KEY].assert_hits(index_metrics.success_count);
    // All requests to the 404 page failed.
    mock_endpoints[A_404_KEY].assert_hits(a_404_metrics.raw_data.counter);
    mock_endpoints[A_404_KEY].assert_hits(a_404_metrics.fail_count);
    match test_type {
        TestType::ErrorSummary => {
            // The 404 path was captured as an error.
            assert!(a_404_errors.len() == 1);
            // Extract the error from the BTreeMap.
            for error in a_404_errors {
                // The captured error was a GET request.
                assert!(error.1.method == SwanlingMethod::Get);
                // The captured error was for the 404 path.
                assert!(error.1.name == A_404_PATH);
                // The error was captured the number of times we requested the 404 path.
                assert!(error.1.occurrences == a_404_metrics.fail_count);
            }
        }
        TestType::NoErrorSummary => {
            // Swanling was configured to not capture any errors.
            assert!(a_404_errors.is_empty());
        }
    }
    // The index always loaded successfully.
    assert!(index_metrics.fail_count == 0);
    // The 404 path was always an error.
    assert!(a_404_metrics.success_count == 0);
    // Verify that Swanling started the correct number of users.
    assert!(swanling_metrics.users == configuration.users.unwrap());
}
fn validate_error ( swanling_metrics : & SwanlingMetrics , mock_endpoints : & [ MockRef ] , configuration : & SwanlingConfiguration , test_type : TestType , ) { // Confirm that we loaded the mock endpoints. assert ! ( mock_endpoints [ INDEX_KEY ] hits ( ) 0 ) ; assert ! ( mock_endpoints [ A_404_KEY ] hits ( ) 0 ) ; // Get request metrics. let index_metrics = swanling_metrics . requests . get ( & format ! ( " " INDEX_PATH ) ) . unwrap ( ) ; let a_404_metrics = swanling_metrics . requests . get ( & format ! ( " " A_404_PATH ) ) . unwrap ( ) ; // Get error metrics. let a_404_errors = swanling_metrics . errors . clone ( ) ; // Confirm that the path and method are correct in the metrics. assert ! ( index_metrics path INDEX_PATH ) ; assert ! ( index_metrics method SwanlingMethod Get ) ; assert ! ( a_404_metrics path A_404_PATH ) ; assert ! ( a_404_metrics method SwanlingMethod Get ) ; // All requests to the index succeeded. mock_endpoints [ INDEX_KEY ] . assert_hits ( index_metrics . raw_data . counter ) ; mock_endpoints [ INDEX_KEY ] . assert_hits ( index_metrics . success_count ) ; // All requests to the 404 page failed. mock_endpoints [ A_404_KEY ] . assert_hits ( a_404_metrics . raw_data . counter ) ; mock_endpoints [ A_404_KEY ] . assert_hits ( a_404_metrics . fail_count ) ; match test_type { TestType :: ErrorSummary => { // The 404 path was captured as an error. assert ! ( a_404_errors len ( ) 1 ) ; // Extract the error from the BTreeMap. for error in a_404_errors { // The captured error was a GET request. assert ! ( error 1 method SwanlingMethod Get ) ; // The captured error was for the 404 path. assert ! ( error 1 name A_404_PATH ) ; // The error was captured the number of times we requested the 404 path. assert ! ( error 1 occurrences a_404_metrics fail_count ) ; } } TestType :: NoErrorSummary => { // Swanling was configured to not capture any errors. assert ! ( a_404_errors is_empty ( ) ) ; } } // The index always loaded successfully. assert ! ( index_metrics fail_count 0 ) ; // The 404 path was always an error. assert ! ( a_404_metrics success_count 0 ) ; // Verify that Swanling started the correct number of users. assert ! ( swanling_metrics users configuration users unwrap ( ) ) ; }
Helper to confirm all variations generate appropriate results.
Helper to confirm all variations generate appropriate results .
swanling_metrics
&SwanlingMetrics
mock_endpoints
&[MockRef]
configuration
&SwanlingConfiguration
test_type
TestType