1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
use std::fs;
use std::path::PathBuf;
use alt_controller_image::archive::NativeTarWriter;
use alt_controller_image::cli::{Cli, Command, run};
use alt_controller_image::manifest::{ArtifactManifest, PackageRecord};
use clap::Parser;
use tempfile::tempdir;
#[test]
fn parses_plan_with_an_explicit_spec_path() {
let cli = Cli::try_parse_from(["alt-controller-image", "plan", "--spec", "image.toml"])
.expect("plan command parses");
assert!(matches!(
cli.command,
Command::Plan { spec } if spec == PathBuf::from("image.toml")
));
}
#[test]
fn parses_build_with_explicit_workspace_and_output_paths() {
let cli = Cli::try_parse_from([
"alt-controller-image",
"build",
"--spec",
"image.toml",
"--workspace",
"work",
"--output",
"out/image.tar",
])
.expect("build command parses");
assert!(matches!(
cli.command,
Command::Build {
spec,
workspace,
apt_config,
output,
} if spec == PathBuf::from("image.toml")
&& workspace == PathBuf::from("work")
&& apt_config.is_none()
&& output == PathBuf::from("out/image.tar")
));
}
#[test]
fn parses_build_with_an_explicit_apt_configuration() {
let cli = Cli::try_parse_from([
"alt-controller-image",
"build",
"--spec",
"image.toml",
"--workspace",
"work",
"--apt-config",
"repositories/alt.conf",
"--output",
"out/image.tar",
])
.expect("build command with explicit APT configuration parses");
assert!(matches!(
cli.command,
Command::Build { apt_config, .. }
if apt_config == Some(PathBuf::from("repositories/alt.conf"))
));
}
#[test]
fn parses_inspect_with_an_explicit_artifact_path() {
let cli = Cli::try_parse_from([
"alt-controller-image",
"inspect",
"--artifact",
"out/image.tar",
])
.expect("inspect command parses");
assert!(matches!(
cli.command,
Command::Inspect { artifact } if artifact == PathBuf::from("out/image.tar")
));
}
#[test]
fn parses_compare_with_explicit_artifact_paths() {
let cli = Cli::try_parse_from([
"alt-controller-image",
"compare",
"--left",
"legacy.tar",
"--right",
"native.tar",
])
.expect("compare command parses");
assert!(matches!(
cli.command,
Command::Compare { left, right }
if left == PathBuf::from("legacy.tar") && right == PathBuf::from("native.tar")
));
}
#[test]
fn compare_uses_companion_manifests_for_tar_artifacts() {
let fixture = tempdir().expect("temporary directory");
let rootfs = fixture.path().join("rootfs");
fs::create_dir_all(&rootfs).expect("create rootfs");
let left = fixture.path().join("left.tar");
let right = fixture.path().join("right.tar");
NativeTarWriter::new()
.write(&rootfs, &left)
.expect("write left archive");
NativeTarWriter::new()
.write(&rootfs, &right)
.expect("write right archive");
ArtifactManifest::new(
vec![PackageRecord::new("controller", "1.0")],
vec![],
None,
vec![],
vec![],
)
.expect("left manifest")
.write_beside(&left)
.expect("write left companion manifest");
ArtifactManifest::new(
vec![PackageRecord::new("controller", "2.0")],
vec![],
None,
vec![],
vec![],
)
.expect("right manifest")
.write_beside(&right)
.expect("write right companion manifest");
let error = run(Cli {
command: Command::Compare { left, right },
})
.expect_err("companion package difference must be reported");
assert!(error.to_string().contains("artifacts differ semantically"));
}
|