Skip to content

Commit

Permalink
tests: migrate unit tests to Rust
Browse files Browse the repository at this point in the history
To avoid issues like python2 not available on distros, we should simply
migrate unit tests to Rust. That would make more sense, as the main code
is already written in Rust.

Adding edition in Cargo.toml.
Without edition = 2021, build fails due to a missing "extern crate ...".
Specifying an edition, Build passes without having to add it.

As Rust does not support global variables by default, it is necessary to
make use of lazy_static, so the variables could be accessed in multiple
tests.
  • Loading branch information
dongsupark committed Nov 15, 2023
1 parent 0e4cea6 commit 469b0fb
Show file tree
Hide file tree
Showing 6 changed files with 794 additions and 261 deletions.
77 changes: 77 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ repository = "https://github.com/coreos/update-ssh-keys"
documentation = "https://docs.rs/update-ssh-keys"
description = "A tool for managing authorized SSH keys"
version = "0.4.2-alpha.0"
edition = "2021"

[dependencies]
fs2 = "0.4"
Expand All @@ -15,6 +16,8 @@ error-chain = { version = "0.12", default-features = false }
clap = { version = "4.4.6", features = ["cargo"] }
uzers = "0.11.3"
openssh-keys = "0.6.2"
lazy_static = "1.4.0"
tempfile = "3.8.0"

[[bin]]
name = "update-ssh-keys"
Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,11 @@ impl AuthorizedKeys {
})
}

/// close file lock to release resources for other processes
pub fn close(&self) -> Result<()> {
self.lock.unlock()
}

/// get_keys gets the authorized keyset with the provided name
pub fn get_keys(&self, name: &str) -> Option<&AuthorizedKeySet> {
self.keys.get(name)
Expand Down
21 changes: 0 additions & 21 deletions tests/compat_python.rs

This file was deleted.

Loading

0 comments on commit 469b0fb

Please sign in to comment.