Skip to content

Commit a35a8f4

Browse files
authored
Fix windows tests (#9)
1 parent 10c4db6 commit a35a8f4

3 files changed

Lines changed: 37 additions & 31 deletions

File tree

src/commands/add_command.rs

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,10 @@ impl<'a> AddCommand<'a> {
145145

146146
#[cfg(test)]
147147
mod tests {
148-
use std::fs::{self, File};
148+
use std::fs;
149149

150150
use super::AddCommand;
151-
use crate::config::locations::LocationsProvider;
152-
use std::io::Write;
151+
use crate::config::{app_config::{AppConfig, Project}, locations::LocationsProvider};
153152

154153
#[test]
155154
fn add_file_when_project_does_not_exist() {
@@ -162,8 +161,8 @@ mod tests {
162161

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

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

@@ -187,13 +186,10 @@ mod tests {
187186

188187
let user_file = current_dir.path().join("file");
189188
let config_file = config_dir.path().join("config.json");
190-
let mut file = File::create(&config_file).unwrap();
191-
write!(
192-
file,
193-
"{{\"projects\":[{{\"name\":\"proj1\", \"path\":\"{}\", \"id\":\"1\"}}]}}",
194-
current_dir.path().to_str().unwrap()
195-
)
196-
.unwrap();
189+
let config = AppConfig {
190+
projects: vec![Project { name: "proj1".into(), id: "1".into(), path: current_dir.path().to_path_buf() }],
191+
};
192+
fs::write(&config_file, serde_json::to_string(&config).unwrap()).unwrap();
197193

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

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

212208
let config_file = config_dir.path().join("config.json");
213-
let mut file = File::create(&config_file).unwrap();
214-
write!(
215-
file,
216-
"{{\"projects\":[{{\"name\":\"proj1\", \"path\":\"{}\", \"id\":\"1\"}}]}}",
217-
project_root.path().to_str().unwrap()
218-
)
219-
.unwrap();
209+
let config = AppConfig {
210+
projects: vec![Project { name: "proj1".into(), id: "1".into(), path: project_root.path().to_path_buf() }],
211+
};
212+
fs::write(&config_file, serde_json::to_string(&config).unwrap()).unwrap();
220213

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

241234
let config_file = config_dir.path().join("config.json");
242-
let mut file = File::create(&config_file).unwrap();
243-
write!(
244-
file,
245-
"{{\"projects\":[{{\"name\":\"proj1\", \"path\":\"{}\", \"id\":\"1\"}}]}}",
246-
project_root.path().to_str().unwrap()
247-
)
248-
.unwrap();
235+
let config = AppConfig {
236+
projects: vec![Project { name: "proj1".into(), id: "1".into(), path: project_root.path().to_path_buf() }],
237+
};
238+
fs::write(&config_file, serde_json::to_string(&config).unwrap()).unwrap();
249239

250240
let subdir = project_root.path().join("config");
251241
fs::create_dir_all(&subdir).unwrap();

tests/e2e/helpers.bash

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
REPO_ROOT="$(cd "$BATS_TEST_DIRNAME/../.." && pwd)"
22
export PATH="$REPO_ROOT/target/release:$PATH"
33

4+
# Converts an MSYS/Cygwin path to Windows-native format (no-op on Unix)
5+
native_path() {
6+
if command -v cygpath &>/dev/null; then
7+
cygpath -m "$1"
8+
else
9+
printf '%s' "$1"
10+
fi
11+
}
12+
413
setup_puff_env() {
514
export PUFF_CONFIG_PATH
615
PUFF_CONFIG_PATH="$(mktemp -d)"

tests/e2e/migration.bats

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,22 @@ teardown() { teardown_puff_env; }
4545
}
4646

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

58+
# On Windows (MSYS/Git Bash), ln -s creates file copies by default (deepcopy
59+
# mode), not real NTFS symlinks. The Rust binary needs real symlinks.
60+
export MSYS="${MSYS:+$MSYS }winsymlinks:nativestrict"
61+
5562
# Create symlink in project dir pointing to old location
56-
ln -s "$PUFF_CONFIG_PATH/configs/myproject/.env" "$PROJECT_DIR/.env"
63+
ln -s "$(native_path "$PUFF_CONFIG_PATH/configs/myproject/.env")" "$PROJECT_DIR/.env"
5764

5865
run puff list
5966
assert_success
@@ -62,6 +69,6 @@ EOF
6269
assert_symlink "$PROJECT_DIR/.env"
6370
assert_file_content "$PROJECT_DIR/.env" "SECRET=1"
6471
local target
65-
target="$(readlink "$PROJECT_DIR/.env")"
66-
echo "$target" | grep -qF "$PUFF_DATA_PATH/projects/"
72+
target="$(native_path "$(readlink "$PROJECT_DIR/.env")")"
73+
echo "$target" | grep -qF "$(native_path "$PUFF_DATA_PATH")/projects/"
6774
}

0 commit comments

Comments
 (0)