use derive_builder::Builder;
use crate::api::common::{self, NameOrId};
use crate::api::endpoint_prelude::*;
#[derive(Debug, Clone, Builder)]
pub struct ProtectedTag<'a> {
#[builder(setter(into))]
project: NameOrId<'a>,
#[builder(setter(into))]
name: Cow<'a, str>,
}
impl<'a> ProtectedTag<'a> {
pub fn builder() -> ProtectedTagBuilder<'a> {
ProtectedTagBuilder::default()
}
}
impl<'a> Endpoint for ProtectedTag<'a> {
fn method(&self) -> Method {
Method::GET
}
fn endpoint(&self) -> Cow<'static, str> {
format!(
"projects/{}/protected_tags/{}",
self.project,
common::path_escaped(self.name.as_ref()),
)
.into()
}
fn parameters(&self) -> QueryParams {
QueryParams::default()
}
}
#[cfg(test)]
mod tests {
use crate::api::projects::protected_tags::{ProtectedTag, ProtectedTagBuilderError};
use crate::api::{self, Query};
use crate::test::client::{ExpectedUrl, SingleTestClient};
#[test]
fn project_is_needed() {
let err = ProtectedTag::builder().build().unwrap_err();
crate::test::assert_missing_field!(err, ProtectedTagBuilderError, "project");
}
#[test]
fn name_is_needed() {
let err = ProtectedTag::builder()
.project("project_name")
.build()
.unwrap_err();
crate::test::assert_missing_field!(err, ProtectedTagBuilderError, "name");
}
#[test]
fn project_and_name_is_sufficient() {
ProtectedTag::builder()
.project(1)
.name("1.0")
.build()
.unwrap();
}
#[test]
fn endpoint() {
let endpoint = ExpectedUrl::builder()
.endpoint("projects/group%2Fproject/protected_tags/master")
.build()
.unwrap();
let client = SingleTestClient::new_raw(endpoint, "");
let endpoint = ProtectedTag::builder()
.project("group/project")
.name("master")
.build()
.unwrap();
api::ignore(endpoint).query(&client).unwrap();
}
}