message: Reformat the user agent and add tests
diff: @@ -8,7 +8,7 @@ use crate::{
  ApiVersion, Headers, StripeError,
  };
  -static USER_AGENT: &str = concat!("Stripe/v3 RustBindings/", env!("CARGO_PKG_VERSION"));
  +static USER_AGENT: &str = concat!("Stripe/v1 RustBindings/", env!("CARGO_PKG_VERSION"));
  #[derive(Clone)]
  pub struct Client {
  @@ -75,7 +75,7 @@ impl Client {
  url: Option<String>,
  ) -> Self {
  let app_info = AppInfo { name, version, url };
  - self.headers.user_agent = format!("{}/{}", USER_AGENT, app_info.to_string());
  + self.headers.user_agent = format!("{} {}", USER_AGENT, app_info.to_string());
  self.app_info = Some(app_info);
  self
  }
  @@ -164,3 +164,50 @@ impl Client {
  req
  }
  }
  +
  +#[cfg(test)]
  +mod test {
  + //! Ensures our user agent matches the format of the other stripe clients.
  + //!
  + //! See: <https://github.com/stripe/stripe-python/blob/3b917dc4cec6a3cccfd46961e05fe7b55c6bee87/stripe/api_requestor.py#L241>
  +
  + use super::Client;
  +
  + #[test]
  + fn user_agent_base() {
  + let client = Client::new("sk_test_12345");
  +
  + assert_eq!(
  + client.headers.user_agent,
  + format!("Stripe/v1 RustBindings/{}", env!("CARGO_PKG_VERSION"))
  + );
  + }
  +
  + #[test]
  + fn user_agent_minimal_app_info() {
  + let client =
  + Client::new("sk_test_12345").with_app_info("sick-new-startup".to_string(), None, None);
  +
  + assert_eq!(
  + client.headers.user_agent,
  + format!("Stripe/v1 RustBindings/{} sick-new-startup", env!("CARGO_PKG_VERSION"))
  + );
  + }
  +
  + #[test]
  + fn user_agent_all() {
  + let client = Client::new("sk_test_12345").with_app_info(
  + "sick-new-startup".to_string(),
  + Some("0.1.0".to_string()),
  + Some("https://sick-startup.io".to_string()),
  + );
  +
  + assert_eq!(
  + client.headers.user_agent,
  + format!(
  + "Stripe/v1 RustBindings/{} sick-new-startup/0.1.0 (https://sick-startup.io)",
  + env!("CARGO_PKG_VERSION")
  + )
  + );
  + }
  +}
  