Skip to content

Commit

Permalink
chore: fix upcoming rust 1.77 clippy issues and chrono deprecations (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkna committed Mar 20, 2024
1 parent 49575e5 commit 0e334e3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/context.rs
Expand Up @@ -38,9 +38,9 @@ pub struct Context<'a> {
/// The current working directory that starship is being called in.
pub current_dir: PathBuf,

/// A logical directory path which should represent the same directory as current_dir,
/// A logical directory path which should represent the same directory as `current_dir`,
/// though may appear different.
/// E.g. when navigating to a PSDrive in PowerShell, or a path without symlinks resolved.
/// E.g. when navigating to a `PSDrive` in `PowerShell`, or a path without symlinks resolved.
pub logical_dir: PathBuf,

/// A struct containing directory contents in a lookup-optimized format.
Expand All @@ -61,10 +61,10 @@ pub struct Context<'a> {
/// Width of terminal, or zero if width cannot be detected.
pub width: usize,

/// A HashMap of environment variable mocks
/// A `HashMap` of environment variable mocks
pub env: Env<'a>,

/// A HashMap of command mocks
/// A `HashMap` of command mocks
#[cfg(test)]
pub cmd: HashMap<&'a str, Option<CommandOutput>>,

Expand Down
2 changes: 1 addition & 1 deletion src/context_env.rs
Expand Up @@ -6,7 +6,7 @@ use std::ffi::OsString;

#[derive(Default)]
pub struct Env<'a> {
/// A HashMap of environment variable mocks
/// A `HashMap` of environment variable mocks
#[cfg(test)]
pub env: HashMap<&'a str, String>,

Expand Down
25 changes: 9 additions & 16 deletions src/modules/aws.rs
Expand Up @@ -684,15 +684,12 @@ credential_process = /opt/bin/awscreds-retriever

#[test]
fn expiration_date_set() {
use chrono::{DateTime, NaiveDateTime, SecondsFormat, Utc};
use chrono::{DateTime, SecondsFormat, Utc};

let expiration_env_vars = ["AWS_SESSION_EXPIRATION", "AWS_CREDENTIAL_EXPIRATION"];
expiration_env_vars.iter().for_each(|env_var| {
let now_plus_half_hour: DateTime<Utc> = DateTime::from_naive_utc_and_offset(
NaiveDateTime::from_timestamp_opt(chrono::Local::now().timestamp() + 1800, 0)
.unwrap(),
Utc,
);
let now_plus_half_hour: DateTime<Utc> =
DateTime::from_timestamp(chrono::Local::now().timestamp() + 1800, 0).unwrap();

let actual = ModuleRenderer::new("aws")
.env("AWS_PROFILE", "astronauts")
Expand Down Expand Up @@ -727,12 +724,10 @@ credential_process = /opt/bin/awscreds-retriever
let credentials_path = dir.path().join("credentials");
let mut file = File::create(&credentials_path)?;

use chrono::{DateTime, NaiveDateTime, Utc};
use chrono::{DateTime, Utc};

let now_plus_half_hour: DateTime<Utc> = DateTime::from_naive_utc_and_offset(
NaiveDateTime::from_timestamp_opt(chrono::Local::now().timestamp() + 1800, 0).unwrap(),
Utc,
);
let now_plus_half_hour: DateTime<Utc> =
DateTime::from_timestamp(chrono::Local::now().timestamp() + 1800, 0).unwrap();

let expiration_date = now_plus_half_hour.to_rfc3339_opts(chrono::SecondsFormat::Secs, true);

Expand Down Expand Up @@ -800,12 +795,10 @@ aws_secret_access_key=dummy

#[test]
fn expiration_date_set_expired() {
use chrono::{DateTime, NaiveDateTime, SecondsFormat, Utc};
use chrono::{DateTime, SecondsFormat, Utc};

let now: DateTime<Utc> = DateTime::from_naive_utc_and_offset(
NaiveDateTime::from_timestamp_opt(chrono::Local::now().timestamp() - 1800, 0).unwrap(),
Utc,
);
let now: DateTime<Utc> =
DateTime::from_timestamp(chrono::Local::now().timestamp() - 1800, 0).unwrap();

let symbol = "!!!";

Expand Down
5 changes: 4 additions & 1 deletion src/test/mod.rs
Expand Up @@ -70,7 +70,9 @@ impl<'a> ModuleRenderer<'a> {
T: Into<PathBuf>,
{
self.context.current_dir = path.into();
self.context.logical_dir = self.context.current_dir.clone();
self.context
.logical_dir
.clone_from(&self.context.current_dir);
self
}

Expand Down Expand Up @@ -184,6 +186,7 @@ pub fn fixture_repo(provider: FixtureProvider) -> io::Result<TempDir> {
fs::OpenOptions::new()
.create(true)
.write(true)
.truncate(false)
.open(path.path().join(checkout_db))?
.sync_all()?;
Ok(path)
Expand Down

0 comments on commit 0e334e3

Please sign in to comment.