Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 16 additions & 26 deletions src/commands/add_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,10 @@ impl<'a> AddCommand<'a> {

#[cfg(test)]
mod tests {
use std::fs::{self, File};
use std::fs;

use super::AddCommand;
use crate::config::locations::LocationsProvider;
use std::io::Write;
use crate::config::{app_config::{AppConfig, Project}, locations::LocationsProvider};

#[test]
fn add_file_when_project_does_not_exist() {
Expand All @@ -162,8 +161,8 @@ mod tests {

let user_file = current_dir.path().join("file");
let config_file = config_dir.path().join("config.json");
let mut file = File::create(&config_file).unwrap();
write!(file, "{{\"projects\":[]}}").unwrap();
let config = AppConfig { projects: vec![] };
fs::write(&config_file, serde_json::to_string(&config).unwrap()).unwrap();

let sut = AddCommand::new(&locations_provider);

Expand All @@ -187,13 +186,10 @@ mod tests {

let user_file = current_dir.path().join("file");
let config_file = config_dir.path().join("config.json");
let mut file = File::create(&config_file).unwrap();
write!(
file,
"{{\"projects\":[{{\"name\":\"proj1\", \"path\":\"{}\", \"id\":\"1\"}}]}}",
current_dir.path().to_str().unwrap()
)
.unwrap();
let config = AppConfig {
projects: vec![Project { name: "proj1".into(), id: "1".into(), path: current_dir.path().to_path_buf() }],
};
fs::write(&config_file, serde_json::to_string(&config).unwrap()).unwrap();

let sut = AddCommand::new(&locations_provider);

Expand All @@ -210,13 +206,10 @@ mod tests {
LocationsProvider::new(config_dir.path().to_path_buf(), data_dir.path().to_path_buf());

let config_file = config_dir.path().join("config.json");
let mut file = File::create(&config_file).unwrap();
write!(
file,
"{{\"projects\":[{{\"name\":\"proj1\", \"path\":\"{}\", \"id\":\"1\"}}]}}",
project_root.path().to_str().unwrap()
)
.unwrap();
let config = AppConfig {
projects: vec![Project { name: "proj1".into(), id: "1".into(), path: project_root.path().to_path_buf() }],
};
fs::write(&config_file, serde_json::to_string(&config).unwrap()).unwrap();

let subdir = project_root.path().join("config");
fs::create_dir_all(&subdir).unwrap();
Expand All @@ -239,13 +232,10 @@ mod tests {
LocationsProvider::new(config_dir.path().to_path_buf(), data_dir.path().to_path_buf());

let config_file = config_dir.path().join("config.json");
let mut file = File::create(&config_file).unwrap();
write!(
file,
"{{\"projects\":[{{\"name\":\"proj1\", \"path\":\"{}\", \"id\":\"1\"}}]}}",
project_root.path().to_str().unwrap()
)
.unwrap();
let config = AppConfig {
projects: vec![Project { name: "proj1".into(), id: "1".into(), path: project_root.path().to_path_buf() }],
};
fs::write(&config_file, serde_json::to_string(&config).unwrap()).unwrap();

let subdir = project_root.path().join("config");
fs::create_dir_all(&subdir).unwrap();
Expand Down
9 changes: 9 additions & 0 deletions tests/e2e/helpers.bash
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
REPO_ROOT="$(cd "$BATS_TEST_DIRNAME/../.." && pwd)"
export PATH="$REPO_ROOT/target/release:$PATH"

# Converts an MSYS/Cygwin path to Windows-native format (no-op on Unix)
native_path() {
if command -v cygpath &>/dev/null; then
cygpath -m "$1"
else
printf '%s' "$1"
fi
}

setup_puff_env() {
export PUFF_CONFIG_PATH
PUFF_CONFIG_PATH="$(mktemp -d)"
Expand Down
17 changes: 12 additions & 5 deletions tests/e2e/migration.bats
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,22 @@ teardown() { teardown_puff_env; }
}

@test "migration: symlinks updated after migration" {
# Set up old-style layout with an associated project + symlink
# Set up old-style layout with an associated project + symlink.
# Use native_path so that config.json and symlink targets contain
# Windows-native paths when running under MSYS/Git Bash — the Rust
# binary cannot resolve MSYS-style paths like /tmp/tmp.XXX.
mkdir -p "$PUFF_CONFIG_PATH/configs/myproject"
echo "SECRET=1" >"$PUFF_CONFIG_PATH/configs/myproject/.env"
cat >"$PUFF_CONFIG_PATH/config.json" <<EOF
{"projects":[{"name":"myproject","id":"1","path":"$PROJECT_DIR"}]}
{"projects":[{"name":"myproject","id":"1","path":"$(native_path "$PROJECT_DIR")"}]}
EOF

# On Windows (MSYS/Git Bash), ln -s creates file copies by default (deepcopy
# mode), not real NTFS symlinks. The Rust binary needs real symlinks.
export MSYS="${MSYS:+$MSYS }winsymlinks:nativestrict"

# Create symlink in project dir pointing to old location
ln -s "$PUFF_CONFIG_PATH/configs/myproject/.env" "$PROJECT_DIR/.env"
ln -s "$(native_path "$PUFF_CONFIG_PATH/configs/myproject/.env")" "$PROJECT_DIR/.env"

run puff list
assert_success
Expand All @@ -62,6 +69,6 @@ EOF
assert_symlink "$PROJECT_DIR/.env"
assert_file_content "$PROJECT_DIR/.env" "SECRET=1"
local target
target="$(readlink "$PROJECT_DIR/.env")"
echo "$target" | grep -qF "$PUFF_DATA_PATH/projects/"
target="$(native_path "$(readlink "$PROJECT_DIR/.env")")"
echo "$target" | grep -qF "$(native_path "$PUFF_DATA_PATH")/projects/"
}