add some tests
This commit is contained in:
parent
a52e4b4dde
commit
40af4997b0
4 changed files with 136 additions and 4 deletions
48
Cargo.lock
generated
48
Cargo.lock
generated
|
@ -58,6 +58,12 @@ version = "1.0.98"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.37"
|
||||
|
@ -104,6 +110,17 @@ version = "1.0.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.5.0"
|
||||
|
@ -116,6 +133,21 @@ version = "1.70.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.172"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
|
||||
|
||||
[[package]]
|
||||
name = "mktemp"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69fed8fbcd01affec44ac226784c6476a6006d98d13e33bc0ca7977aaf046bd8"
|
||||
dependencies = [
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.3"
|
||||
|
@ -128,6 +160,7 @@ version = "0.2.0"
|
|||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
"mktemp",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
|
@ -198,6 +231,21 @@ version = "0.2.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "1.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.59.0"
|
||||
|
|
|
@ -11,3 +11,6 @@ edition = "2024"
|
|||
anyhow = "^1.0"
|
||||
clap = { version = "^4.5", features = ["derive"] }
|
||||
thiserror = "^2.0"
|
||||
|
||||
[dev-dependencies]
|
||||
mktemp = "^0.5.1"
|
||||
|
|
47
Makefile
Normal file
47
Makefile
Normal file
|
@ -0,0 +1,47 @@
|
|||
# Default, which is handy to run before committing code
|
||||
all: fmt lint test
|
||||
|
||||
# What to have CI systems run
|
||||
ci: lint test
|
||||
|
||||
# Final pre-flight checks then deploy everywhere!
|
||||
# TODO
|
||||
# shipit: all build staging prod
|
||||
|
||||
# version := $(shell yq -p toml .tool.poetry.version < pyproject.toml)
|
||||
|
||||
|
||||
init:
|
||||
poetry install
|
||||
|
||||
# Everything to get the dev env set up
|
||||
dev: init
|
||||
|
||||
fmt:
|
||||
cargo fmt
|
||||
|
||||
lint:
|
||||
cargo clippy
|
||||
|
||||
test:
|
||||
cargo test
|
||||
|
||||
|
||||
test-watch:
|
||||
find . -name '*rs' -or -name '*html' -or -name Cargo.lock | entr -r -c make test
|
||||
|
||||
clean:
|
||||
cargo clean
|
||||
|
||||
# TODO?
|
||||
# docker:
|
||||
# podman build -t nickpegg/photojawn . --build-arg GIT_COMMIT=$(shell git rev-parse --short HEAD)
|
||||
|
||||
dist:
|
||||
cargo build --release
|
||||
|
||||
# TODO
|
||||
# release: dist
|
||||
# git push --tags
|
||||
# gh release create --verify-tag v$(version)
|
||||
# gh release upload v$(version) dist/photojawn-$(version)-*whl $(foreach plat,$(scie_platforms),dist/photojawn-$(plat))
|
42
src/skel.rs
42
src/skel.rs
|
@ -31,19 +31,53 @@ pub fn make_skeleton(album_path: &Path) -> Result<(), InitError> {
|
|||
)?;
|
||||
|
||||
let tmpl_path = album_path.join("_templates");
|
||||
fs::create_dir_all(tmpl_path)?;
|
||||
fs::create_dir_all(&tmpl_path)?;
|
||||
fs::write(
|
||||
static_path.join("base.html"),
|
||||
tmpl_path.join("base.html"),
|
||||
include_bytes!("../resources/skel/_templates/base.html"),
|
||||
)?;
|
||||
fs::write(
|
||||
static_path.join("album.html"),
|
||||
tmpl_path.join("album.html"),
|
||||
include_bytes!("../resources/skel/_templates/album.html"),
|
||||
)?;
|
||||
fs::write(
|
||||
static_path.join("photo.html"),
|
||||
tmpl_path.join("photo.html"),
|
||||
include_bytes!("../resources/skel/_templates/photo.html"),
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use mktemp::Temp;
|
||||
|
||||
#[test]
|
||||
fn not_exist() {
|
||||
let tmpdir = Temp::new_dir().unwrap();
|
||||
make_skeleton(&tmpdir).unwrap();
|
||||
assert!(tmpdir.join("photojawn.conf.yml").exists());
|
||||
assert!(tmpdir.join("static/index.css").exists());
|
||||
assert!(tmpdir.join("_templates/base.html").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_exists() {
|
||||
let tmpdir = Temp::new_dir().unwrap();
|
||||
fs::write(tmpdir.join("photojawn.conf.yml"), "some: config").unwrap();
|
||||
let res = make_skeleton(&tmpdir);
|
||||
assert!(res.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dir_exists_no_config() {
|
||||
let tmpdir = Temp::new_dir().unwrap();
|
||||
fs::create_dir(tmpdir.join("_templates")).unwrap();
|
||||
fs::write(tmpdir.join("_templates/base.html"), "some template").unwrap();
|
||||
make_skeleton(&tmpdir).unwrap();
|
||||
|
||||
let contents = fs::read(tmpdir.join("_templates/base.html")).unwrap();
|
||||
assert_ne!(contents, "some template".as_bytes());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue