gitlab/api/projects/registry/
repository_tags.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 tags of a registry repository within a project.
13#[derive(Debug, Builder, Clone)]
14pub struct RepositoryTags<'a> {
15    /// The project to query.
16    #[builder(setter(into))]
17    project: NameOrId<'a>,
18    /// The repository id to query.
19    repository_id: u64,
20}
21
22impl<'a> RepositoryTags<'a> {
23    /// Create a builder for the endpoint.
24    pub fn builder() -> RepositoryTagsBuilder<'a> {
25        RepositoryTagsBuilder::default()
26    }
27}
28
29impl Endpoint for RepositoryTags<'_> {
30    fn method(&self) -> Method {
31        Method::GET
32    }
33
34    fn endpoint(&self) -> Cow<'static, str> {
35        format!(
36            "projects/{}/registry/repositories/{}/tags",
37            self.project, self.repository_id,
38        )
39        .into()
40    }
41}
42
43impl Pageable for RepositoryTags<'_> {}
44
45#[cfg(test)]
46mod tests {
47    use crate::api::projects::registry::{RepositoryTags, RepositoryTagsBuilderError};
48    use crate::api::{self, Query};
49    use crate::test::client::{ExpectedUrl, SingleTestClient};
50
51    #[test]
52    fn project_and_repository_are_necessary() {
53        let err = RepositoryTags::builder().build().unwrap_err();
54        crate::test::assert_missing_field!(err, RepositoryTagsBuilderError, "project");
55    }
56
57    #[test]
58    fn project_is_necessary() {
59        let err = RepositoryTags::builder()
60            .repository_id(1)
61            .build()
62            .unwrap_err();
63        crate::test::assert_missing_field!(err, RepositoryTagsBuilderError, "project");
64    }
65
66    #[test]
67    fn repository_is_necessary() {
68        let err = RepositoryTags::builder().project(1).build().unwrap_err();
69        crate::test::assert_missing_field!(err, RepositoryTagsBuilderError, "repository_id");
70    }
71
72    #[test]
73    fn project_and_repository_are_sufficient() {
74        RepositoryTags::builder()
75            .project(1)
76            .repository_id(1)
77            .build()
78            .unwrap();
79    }
80
81    #[test]
82    fn endpoint() {
83        let endpoint = ExpectedUrl::builder()
84            .endpoint("projects/simple%2Fproject/registry/repositories/1/tags")
85            .build()
86            .unwrap();
87        let client = SingleTestClient::new_raw(endpoint, "");
88
89        let endpoint = RepositoryTags::builder()
90            .project("simple/project")
91            .repository_id(1)
92            .build()
93            .unwrap();
94        api::ignore(endpoint).query(&client).unwrap();
95    }
96}