use std::borrow::Cow;
use derive_builder::Builder;
use crate::api::common::NameOrId;
use crate::api::endpoint_prelude::*;
#[derive(Debug, Clone, Builder)]
pub struct CustomAttribute<'a> {
#[builder(setter(into))]
project: NameOrId<'a>,
#[builder(setter(into))]
key: Cow<'a, str>,
}
impl<'a> CustomAttribute<'a> {
pub fn builder() -> CustomAttributeBuilder<'a> {
CustomAttributeBuilder::default()
}
}
impl<'a> Endpoint for CustomAttribute<'a> {
fn method(&self) -> Method {
Method::GET
}
fn endpoint(&self) -> Cow<'static, str> {
format!("projects/{}/custom_attributes/{}", self.project, self.key).into()
}
}
#[cfg(test)]
mod tests {
use crate::api::projects::custom_attributes::{CustomAttribute, CustomAttributeBuilderError};
use crate::api::{self, Query};
use crate::test::client::{ExpectedUrl, SingleTestClient};
use http::Method;
#[test]
fn project_is_needed() {
let err = CustomAttribute::builder().key("test").build().unwrap_err();
crate::test::assert_missing_field!(err, CustomAttributeBuilderError, "project");
}
#[test]
fn key_is_needed() {
let err = CustomAttribute::builder().project(1).build().unwrap_err();
crate::test::assert_missing_field!(err, CustomAttributeBuilderError, "key");
}
#[test]
fn project_key_are_sufficient() {
CustomAttribute::builder()
.project(1)
.key("test")
.build()
.unwrap();
}
#[test]
fn endpoint() {
let endpoint = ExpectedUrl::builder()
.method(Method::GET)
.endpoint("projects/group%2Fproject/custom_attributes/test")
.build()
.unwrap();
let client = SingleTestClient::new_raw(endpoint, "");
let endpoint = CustomAttribute::builder()
.project("group/project")
.key("test")
.build()
.unwrap();
api::ignore(endpoint).query(&client).unwrap();
}
}