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