gitlab/api/projects/variables/
variables.rs1use derive_builder::Builder;
8
9use crate::api::common::NameOrId;
10use crate::api::endpoint_prelude::*;
11
12#[derive(Debug, Builder, Clone)]
14#[builder(setter(strip_option))]
15pub struct ProjectVariables<'a> {
16 #[builder(setter(into))]
18 project: NameOrId<'a>,
19}
20
21impl<'a> ProjectVariables<'a> {
22 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}