Skip to main content

gitlab/api/projects/pipelines/
test_report.rs

1// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
2// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
3// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
4// option. This file may not be copied, modified, or distributed
5// except according to those terms.
6
7use derive_builder::Builder;
8
9use crate::api::common::NameOrId;
10use crate::api::endpoint_prelude::*;
11
12/// Query for the test report of a pipeline.
13#[derive(Debug, Builder, Clone)]
14pub struct PipelineTestReport<'a> {
15    /// The project of the pipelines.
16    #[builder(setter(into))]
17    project: NameOrId<'a>,
18    /// The ID of the pipeline.
19    pipeline: u64,
20}
21
22impl<'a> PipelineTestReport<'a> {
23    /// Create a builder for the endpoint.
24    pub fn builder() -> PipelineTestReportBuilder<'a> {
25        PipelineTestReportBuilder::default()
26    }
27}
28
29impl Endpoint for PipelineTestReport<'_> {
30    fn method(&self) -> Method {
31        Method::GET
32    }
33
34    fn endpoint(&self) -> Cow<'static, str> {
35        format!(
36            "projects/{}/pipelines/{}/test_report",
37            self.project, self.pipeline,
38        )
39        .into()
40    }
41}
42
43#[cfg(test)]
44mod tests {
45    use crate::api::projects::pipelines::test_report::{
46        PipelineTestReport, PipelineTestReportBuilderError,
47    };
48    use crate::api::{self, Query};
49    use crate::test::client::{ExpectedUrl, SingleTestClient};
50
51    #[test]
52    fn project_and_pipeline_are_needed() {
53        let err = PipelineTestReport::builder().build().unwrap_err();
54        crate::test::assert_missing_field!(err, PipelineTestReportBuilderError, "project");
55    }
56
57    #[test]
58    fn project_is_needed() {
59        let err = PipelineTestReport::builder()
60            .pipeline(1)
61            .build()
62            .unwrap_err();
63        crate::test::assert_missing_field!(err, PipelineTestReportBuilderError, "project");
64    }
65
66    #[test]
67    fn pipeline_is_needed() {
68        let err = PipelineTestReport::builder()
69            .project(1)
70            .build()
71            .unwrap_err();
72        crate::test::assert_missing_field!(err, PipelineTestReportBuilderError, "pipeline");
73    }
74
75    #[test]
76    fn project_and_pipeline_are_sufficient() {
77        PipelineTestReport::builder()
78            .project(1)
79            .pipeline(1)
80            .build()
81            .unwrap();
82    }
83
84    #[test]
85    fn endpoint() {
86        let endpoint = ExpectedUrl::builder()
87            .endpoint("projects/simple%2Fproject/pipelines/1/test_report")
88            .build()
89            .unwrap();
90        let client = SingleTestClient::new_raw(endpoint, "");
91
92        let endpoint = PipelineTestReport::builder()
93            .project("simple/project")
94            .pipeline(1)
95            .build()
96            .unwrap();
97        api::ignore(endpoint).query(&client).unwrap();
98    }
99}