Skip to main content

gitlab/api/projects/variables/
variables.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 list of variables
13#[derive(Debug, Builder, Clone)]
14#[builder(setter(strip_option))]
15pub struct ProjectVariables<'a> {
16    /// The project to query variables from
17    #[builder(setter(into))]
18    project: NameOrId<'a>,
19}
20
21impl<'a> ProjectVariables<'a> {
22    /// Create a builder for the endpoint.
23    pub fn builder() -> ProjectVariablesBuilder<'a> {
24        ProjectVariablesBuilder::default()
25    }
26}
27
28impl Endpoint for ProjectVariables<'_> {
29    fn method(&self) -> Method {
30        Method::GET
31    }
32
33    fn endpoint(&self) -> Cow<'static, str> {
34        format!("projects/{}/variables", self.project).into()
35    }
36}
37
38impl Pageable for ProjectVariables<'_> {}
39
40#[cfg(test)]
41mod tests {
42    use http::Method;
43
44    use crate::api::projects::variables::variables::{
45        ProjectVariables, ProjectVariablesBuilderError,
46    };
47    use crate::api::{self, Query};
48    use crate::test::client::{ExpectedUrl, SingleTestClient};
49
50    #[test]
51    fn all_parameters_are_needed() {
52        let err = ProjectVariables::builder().build().unwrap_err();
53        crate::test::assert_missing_field!(err, ProjectVariablesBuilderError, "project");
54    }
55
56    #[test]
57    fn sufficient_parameters() {
58        ProjectVariables::builder().project(1).build().unwrap();
59    }
60
61    #[test]
62    fn endpoint() {
63        let endpoint = ExpectedUrl::builder()
64            .method(Method::GET)
65            .endpoint("projects/simple%2Fproject/variables")
66            .build()
67            .unwrap();
68        let client = SingleTestClient::new_raw(endpoint, "");
69
70        let endpoint = ProjectVariables::builder()
71            .project("simple/project")
72            .build()
73            .unwrap();
74        api::ignore(endpoint).query(&client).unwrap();
75    }
76}