Skip to content

Commit

Permalink
Remove unused methods from ActiveDatetime
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Apr 14, 2024
1 parent 356cbc1 commit 62f0e66
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 26 deletions.
22 changes: 2 additions & 20 deletions src/private/active_datetime.rs
Expand Up @@ -8,23 +8,9 @@ pub struct Error;
pub(crate) struct ActiveDatetime(UnixTimestamp);

impl ActiveDatetime {
pub(crate) fn from_unix_timestamp(unix_timestamp: i64) -> Result<Self, Error> {
Ok(Self(
UnixTimestamp::try_from(unix_timestamp).map_err(|_| Error)?,
))
}

pub(crate) fn from_unix_timestamp_obj(unix_timestamp: UnixTimestamp) -> Self {
Self(unix_timestamp)
}

pub(crate) fn unix_timestamp(&self) -> i64 {
i64::from(self.0)
}

pub(crate) fn unix_timestamp_obj(&self) -> UnixTimestamp {
self.0
}
}

impl std::fmt::Display for ActiveDatetime {
Expand All @@ -39,15 +25,11 @@ mod tests {

#[test]
fn test() -> anyhow::Result<()> {
let unix_timestamp = i64::from(UnixTimestamp::from_rfc3339("2020-01-02T03:04:05+00:00")?);
let unix_timestamp = UnixTimestamp::from_rfc3339("2020-01-02T03:04:05+00:00")?;
assert_eq!(
ActiveDatetime::from_unix_timestamp(unix_timestamp)?.to_string(),
ActiveDatetime::from_unix_timestamp_obj(unix_timestamp).to_string(),
"20200102T030405Z"
);

let active_datetime = ActiveDatetime::from_unix_timestamp(unix_timestamp)?;
assert_eq!(active_datetime.unix_timestamp(), unix_timestamp);

Ok(())
}
}
6 changes: 3 additions & 3 deletions src/private/canonical_request.rs
Expand Up @@ -153,7 +153,7 @@ UNSIGNED-PAYLOAD

#[test]
fn test_request() -> anyhow::Result<()> {
let unix_timestamp = i64::from(UnixTimestamp::from_rfc3339("2020-01-02T03:04:05Z")?);
let unix_timestamp = UnixTimestamp::from_rfc3339("2020-01-02T03:04:05Z")?;
let expiration = Expiration::try_from(604800)?;
let service_account_name = "service_account_name1";
let request = http::Request::builder()
Expand Down Expand Up @@ -197,13 +197,13 @@ UNSIGNED-PAYLOAD
let authorizer = service_account_name;
// <https://cloud.google.com/storage/docs/authentication/signatures#credential-scope>
let credential_scope = CredentialScope::new(
date::Date::from_unix_timestamp(unix_timestamp)?,
date::Date::from_unix_timestamp_obj(unix_timestamp),
Location::try_from("us-central1")?,
Service::Storage,
RequestType::Goog4Request,
)?
.to_string();
let x_goog_date = ActiveDatetime::from_unix_timestamp(unix_timestamp)?.to_string();
let x_goog_date = ActiveDatetime::from_unix_timestamp_obj(unix_timestamp).to_string();
let mut url1 = url::Url::parse(request.uri().to_string().as_str())?;
let url_required_query_string_parameters_sadded = url1
.query_pairs_mut()
Expand Down
6 changes: 3 additions & 3 deletions src/private/signed_url.rs
Expand Up @@ -164,7 +164,7 @@ mod tests {

#[test]
fn test_add_signed_url_required_query_string_parameters() -> anyhow::Result<()> {
let unix_timestamp = i64::from(UnixTimestamp::from_rfc3339("2020-01-02T03:04:05Z")?);
let unix_timestamp = UnixTimestamp::from_rfc3339("2020-01-02T03:04:05Z")?;
let expiration = Expiration::try_from(604800)?;
let service_account_client_email = "service_account_name1";
let mut request = http::Request::builder()
Expand All @@ -179,9 +179,9 @@ mod tests {
&mut request,
service_account_client_email,
SigningAlgorithm::Goog4RsaSha256,
ActiveDatetime::from_unix_timestamp(unix_timestamp)?,
ActiveDatetime::from_unix_timestamp_obj(unix_timestamp),
&CredentialScope::new(
Date::from_unix_timestamp(unix_timestamp)?,
Date::from_unix_timestamp_obj(unix_timestamp),
Location::try_from("us-central1")?,
Service::Storage,
RequestType::Goog4Request,
Expand Down

0 comments on commit 62f0e66

Please sign in to comment.