Skip to content

Commit 3c85d97

Browse files
committed
Add image unpack test for OciImage
1 parent 811dfc5 commit 3c85d97

9 files changed

+118
-1
lines changed

Cargo.lock

Lines changed: 68 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ tokio = { version = "0.3", features = ["fs", "macros", "net", "process", "io-uti
1717
tokio-seqpacket = "0.3"
1818
uuid = { version = "0.8.1", features = ["v4"] }
1919
warp = "0.2.5"
20+
21+
[dev-dependencies]
22+
tokio = { version = "0.3", features = ["full", "test-util"] }

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ command in your terminal:
2828
cargo run
2929
```
3030

31+
To execute the included unit test suite, run:
32+
33+
```sh
34+
cargo test
35+
```
36+
3137
## Usage
3238

3339
TODO

src/image.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ impl OciImage {
4646
.output()
4747
.await?;
4848

49+
println!("{:?}", fetch_cmd);
50+
4951
if !output.status.success() {
5052
let stderr = String::from_utf8(output.stderr)?;
5153
return Err(anyhow!(
@@ -152,3 +154,38 @@ impl OciBundle {
152154
self.base_dir.path()
153155
}
154156
}
157+
158+
#[cfg(test)]
159+
mod tests {
160+
use super::*;
161+
162+
const BUSYBOX_OCI_IMAGE: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/busybox");
163+
164+
#[tokio::test]
165+
async fn unpacks_image_correctly() {
166+
let bundle = OciBundle::unpack_from(Path::new(BUSYBOX_OCI_IMAGE))
167+
.await
168+
.expect("failed to unpack bundle");
169+
170+
assert!(bundle.bundle_dir.exists());
171+
assert!(bundle.bundle_dir.is_dir());
172+
173+
let rootfs_dir = bundle.bundle_dir.join("rootfs");
174+
assert!(rootfs_dir.exists());
175+
assert!(rootfs_dir.is_dir());
176+
177+
let config_file = bundle.bundle_dir.join("config.json");
178+
assert!(config_file.exists());
179+
assert!(config_file.is_file());
180+
181+
let umoci_file = bundle.bundle_dir.join("umoci.json");
182+
assert!(umoci_file.exists());
183+
assert!(umoci_file.is_file());
184+
185+
assert!(bundle.exits_dir.exists());
186+
assert!(bundle.exits_dir.is_dir());
187+
188+
assert!(!bundle.log_file.exists());
189+
assert!(!bundle.pid_file.exists());
190+
}
191+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"created":"2020-11-23T23:23:02.382930462Z","architecture":"amd64","os":"linux","config":{"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd":["sh"]},"rootfs":{"type":"layers","diff_ids":["sha256:8f8e3c7011ee77277dc15d094222824fdc454df7b6828d31bc3bddf07d47ba33"]},"history":[{"created":"2020-11-23T23:23:02.216746559Z","created_by":"/bin/sh -c #(nop) ADD file:7f51bbea8802a227eb7cd4acfe48f02dac69bd9b039e6882d8e706fcdc95173b in / "},{"created":"2020-11-23T23:23:02.382930462Z","created_by":"/bin/sh -c #(nop) CMD [\"sh\"]","empty_layer":true}]}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"schemaVersion":2,"config":{"mediaType":"application/vnd.oci.image.config.v1+json","digest":"sha256:19a138f92230d6bf5f5d435d2e527fb29d12f88c9bd4f81b1932269ea9893ad6","size":575},"layers":[{"mediaType":"application/vnd.oci.image.layer.v1.tar+gzip","digest":"sha256:5f5dd3e95e9fd44603cbb8968144999b730545267ce74d9b442f8f7f7827f776","size":764624}]}

tests/busybox/index.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"schemaVersion":2,"manifests":[{"mediaType":"application/vnd.oci.image.manifest.v1+json","digest":"sha256:694de93787c3f1b8e1b61f4a8bd1bb555138e33b14b67a08237c3c3d678654ea","size":347,"annotations":{"org.opencontainers.image.ref.name":"latest"}}]}

tests/busybox/oci-layout

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"imageLayoutVersion": "1.0.0"}

0 commit comments

Comments
 (0)