gitlab/api/groups/
group.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 Group<'a> {
16 #[builder(setter(into))]
18 group: NameOrId<'a>,
19
20 #[builder(default)]
22 with_custom_attributes: Option<bool>,
23}
24
25impl<'a> Group<'a> {
26 pub fn builder() -> GroupBuilder<'a> {
28 GroupBuilder::default()
29 }
30}
31
32impl Endpoint for Group<'_> {
33 fn method(&self) -> Method {
34 Method::GET
35 }
36
37 fn endpoint(&self) -> Cow<'static, str> {
38 format!("groups/{}", self.group).into()
39 }
40
41 fn parameters(&self) -> QueryParams {
42 let mut params = QueryParams::default();
43
44 params.push_opt("with_custom_attributes", self.with_custom_attributes);
45
46 params
47 }
48}
49
50#[cfg(test)]
51mod tests {
52 use crate::api::groups::{Group, GroupBuilderError};
53 use crate::api::{self, Query};
54 use crate::test::client::{ExpectedUrl, SingleTestClient};
55
56 #[test]
57 fn group_is_necessary() {
58 let err = Group::builder().build().unwrap_err();
59 crate::test::assert_missing_field!(err, GroupBuilderError, "group");
60 }
61
62 #[test]
63 fn group_is_sufficient() {
64 Group::builder().group(1).build().unwrap();
65 }
66
67 #[test]
68 fn endpoint() {
69 let endpoint = ExpectedUrl::builder()
70 .endpoint("groups/group%2Fsubgroup")
71 .build()
72 .unwrap();
73 let client = SingleTestClient::new_raw(endpoint, "");
74
75 let endpoint = Group::builder().group("group/subgroup").build().unwrap();
76 api::ignore(endpoint).query(&client).unwrap();
77 }
78
79 #[test]
80 fn endpoint_with_custom_attributes() {
81 let endpoint = ExpectedUrl::builder()
82 .endpoint("groups/group%2Fsubgroup")
83 .add_query_params(&[("with_custom_attributes", "true")])
84 .build()
85 .unwrap();
86 let client = SingleTestClient::new_raw(endpoint, "");
87
88 let endpoint = Group::builder()
89 .group("group/subgroup")
90 .with_custom_attributes(true)
91 .build()
92 .unwrap();
93 api::ignore(endpoint).query(&client).unwrap();
94 }
95}