gitlab 0.1810.0

Gitlab API client.
Documentation
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use derive_builder::Builder;

use crate::api::common::NameOrId;
use crate::api::endpoint_prelude::*;

/// Remove a group from the 'CI/CD job token allowlist' of a project.
#[derive(Debug, Builder, Clone)]
pub struct DisallowJobTokenGroup<'a> {
    /// The ID or URL-encoded path of the project.
    #[builder(setter(into))]
    project: NameOrId<'a>,

    /// The ID of the group that is removed from the 'CI/CD job token groups allowlist'.
    target_group_id: u64,
}

impl<'a> DisallowJobTokenGroup<'a> {
    /// Create a builder for the endpoint.
    pub fn builder() -> DisallowJobTokenGroupBuilder<'a> {
        DisallowJobTokenGroupBuilder::default()
    }
}

impl Endpoint for DisallowJobTokenGroup<'_> {
    fn method(&self) -> Method {
        Method::DELETE
    }

    fn endpoint(&self) -> Cow<'static, str> {
        format!(
            "projects/{}/job_token_scope/groups_allowlist/{}",
            self.project, self.target_group_id
        )
        .into()
    }
}

#[cfg(test)]
mod tests {
    use http::Method;

    use crate::api::projects::job_token_scopes::{
        DisallowJobTokenGroup, DisallowJobTokenGroupBuilderError,
    };
    use crate::api::{self, Query};
    use crate::test::client::{ExpectedUrl, SingleTestClient};

    #[test]
    fn project_is_required() {
        let err = DisallowJobTokenGroup::builder().build().unwrap_err();
        crate::test::assert_missing_field!(err, DisallowJobTokenGroupBuilderError, "project");
    }

    #[test]
    fn target_is_required() {
        let err = DisallowJobTokenGroup::builder()
            .project("blah")
            .build()
            .unwrap_err();
        crate::test::assert_missing_field!(
            err,
            DisallowJobTokenGroupBuilderError,
            "target_group_id",
        );
    }

    #[test]
    fn project_and_target_is_sufficient() {
        DisallowJobTokenGroup::builder()
            .project("blah")
            .target_group_id(42)
            .build()
            .unwrap();
    }

    #[test]
    fn endpoint() {
        let endpoint = ExpectedUrl::builder()
            .method(Method::DELETE)
            .endpoint("projects/blah/job_token_scope/groups_allowlist/42")
            .build()
            .unwrap();
        let client = SingleTestClient::new_raw(endpoint, "");

        let endpoint = DisallowJobTokenGroup::builder()
            .project("blah")
            .target_group_id(42)
            .build()
            .unwrap();
        api::ignore(endpoint).query(&client).unwrap();
    }
}