mod common;
use common::*;
use std::process::Command;
#[tokio::test]
async fn test_setup_brand_new_repository() {
let container = setup_fedora_container().await;
let container_id = container.id();
let status = Command::new("docker")
.args(&[
"exec",
container_id,
"mkdir",
"-p",
"/root/.config/fp-dotfiles-manager",
])
.status()
.expect("Failed to create config dir");
assert!(status.success());
let status = Command::new("docker")
.args(&[
"exec",
container_id,
"ssh-keygen",
"-t",
"ed25519",
"-N",
"",
"-f",
"/root/.config/fp-dotfiles-manager/ssh_gitlab",
])
.status()
.expect("Failed to generate ed25519 SSH keys");
assert!(status.success(), "Failed to generate valid SSH keys inside container");
let status = Command::new("docker")
.args(&[
"exec",
container_id,
"git",
"config",
"--global",
"user.name",
"Test User",
])
.status()
.expect("Failed to configure git user.name");
assert!(status.success());
let status = Command::new("docker")
.args(&[
"exec",
container_id,
"git",
"config",
"--global",
"user.email",
"test@example.com",
])
.status()
.expect("Failed to configure git user.email");
assert!(status.success());
let stdout = run_manager_success(
&container,
&[
"setup",
"--repo-url",
"/tmp/non-existent-repo.git",
"--ssh-key",
"/root/.config/fp-dotfiles-manager/ssh_gitlab",
"--force",
],
).await;
assert!(stdout.contains("Initializing a brand new dotfiles repository locally"));
assert!(stdout.contains("Generating brand new age encryption key pair"));
assert!(stdout.contains("Generated default .chezmoi.toml.tmpl in the dotfiles repository"));
assert!(stdout.contains("Generated ~/.config/chezmoi/chezmoi.toml for immediate use"));
assert!(stdout.contains("Created initial commit in the local dotfiles repository"));
let age_key = read_file_in_container(&container, "/root/.config/chezmoi/.age-private-key.txt");
assert!(age_key.contains("AGE-SECRET-KEY-"));
let chezmoi_toml = read_file_in_container(&container, "/root/.config/chezmoi/chezmoi.toml");
assert!(chezmoi_toml.contains("encryption = \"age\""));
assert!(chezmoi_toml.contains("/root/.config/chezmoi/.age-private-key.txt"));
let tmpl = read_file_in_container(&container, "/root/.local/share/chezmoi/.chezmoi.toml.tmpl");
assert!(tmpl.contains("encryption = \"age\""));
assert!(tmpl.contains(".chezmoi.homeDir"));
let git_remote = Command::new("docker")
.args(&[
"exec",
container_id,
"git",
"-C",
"/root/.local/share/chezmoi",
"remote",
"get-url",
"origin",
])
.output()
.expect("Failed to query git remote URL");
assert!(git_remote.status.success());
let remote_url = String::from_utf8_lossy(&git_remote.stdout).trim().to_string();
assert_eq!(remote_url, "/tmp/non-existent-repo.git");
}