Skip to content

Commit

Permalink
Add all features unit test job
Browse files Browse the repository at this point in the history
Signed-off-by: Sascha Grunert <[email protected]>
  • Loading branch information
saschagrunert committed Aug 19, 2021
1 parent b67aa8f commit 5675706
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 39 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,16 @@ jobs:
- name: Install rustfmt
shell: bash
run: rustup component add rustfmt
- name: Unit tests
- name: Unit tests with all features
uses: actions-rs/cargo@v1
with:
command: test
args: --all-features --no-fail-fast
env:
CARGO_INCREMENTAL: '0'
RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests'
RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests'
- name: Unit tests with default features
uses: actions-rs/cargo@v1
with:
command: test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Build Documentation
run: cargo doc
run: cargo doc --all-features
- name: Deploy Documentation
uses: peaceiris/actions-gh-pages@v3
with:
Expand Down
86 changes: 64 additions & 22 deletions src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,37 +210,79 @@ mod tests {
.with_context(|| "Failed to create the testing rootfs")?;
{
// Test the case with absolute path
let mut spec = Spec {
root: Root {
path: rootfs_absolute_path.clone(),
..Default::default()
cfg_if::cfg_if!(
if #[cfg(feature = "builder")] {
let mut spec = SpecBuilder::default()
.root(RootBuilder::default()
.path(rootfs_absolute_path.clone())
.build()?)
.build()?;
} else {
let mut spec = Spec {
root: Root {
path: rootfs_absolute_path.clone(),
..Default::default()
}
.into(),
..Default::default()
};
}
.into(),
..Default::default()
};
);

spec.canonicalize_rootfs(bundle.path())
.with_context(|| "Failed to canonicalize rootfs")?;
assert_eq!(
rootfs_absolute_path,
spec.root.context("no root in spec")?.path
.context("failed to canonicalize rootfs")?;

cfg_if::cfg_if!(
if #[cfg(feature = "builder")] {
assert_eq!(
&rootfs_absolute_path,
spec.root.context("no root in spec")?.path()
);
} else {
assert_eq!(
rootfs_absolute_path,
spec.root.context("no root in spec")?.path
);
}
);
}

{
// Test the case with relative path
let mut spec = Spec {
root: Root {
path: PathBuf::from(rootfs_name),
..Default::default()
cfg_if::cfg_if!(
if #[cfg(feature = "builder")] {
let mut spec = SpecBuilder::default()
.root(RootBuilder::default()
.path(rootfs_name)
.build()?)
.build()?;
} else {
let mut spec = Spec {
root: Root {
path: PathBuf::from(rootfs_name),
..Default::default()
}
.into(),
..Default::default()
};
}
.into(),
..Default::default()
};
);

spec.canonicalize_rootfs(bundle.path())
.with_context(|| "Failed to canonicalize rootfs")?;
assert_eq!(
rootfs_absolute_path,
spec.root.context("no root in spec")?.path
.context("failed to canonicalize rootfs")?;

cfg_if::cfg_if!(
if #[cfg(feature = "builder")] {
assert_eq!(
&rootfs_absolute_path,
spec.root.context("no root in spec")?.path()
);
} else {
assert_eq!(
rootfs_absolute_path,
spec.root.context("no root in spec")?.path
);
}
);
}

Expand Down
54 changes: 39 additions & 15 deletions src/runtime/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,45 @@ fn serialize_and_deserialize_spec() {
}

#[test]
fn test_linux_device_cgroup_to_string() {
let ldc = LinuxDeviceCgroup {
allow: true,
typ: Some(LinuxDeviceType::B),
major: None,
minor: None,
access: Some("rwm".into()),
};
fn test_linux_device_cgroup_to_string() -> Result<()> {
cfg_if::cfg_if!(
if #[cfg(feature = "builder")] {
let ldc = LinuxDeviceCgroupBuilder::default().
allow(true).
typ(LinuxDeviceType::B).
access("rwm".to_string()).
build()?;
} else {
let ldc = LinuxDeviceCgroup {
allow: true,
typ: Some(LinuxDeviceType::B),
major: None,
minor: None,
access: Some("rwm".into()),
};
}
);
assert_eq!(ldc.to_string(), "b *:* rwm");
let ldc = LinuxDeviceCgroup {
allow: true,
typ: Some(LinuxDeviceType::B),
major: Some(1),
minor: Some(9),
access: Some("rwm".into()),
};

cfg_if::cfg_if!(
if #[cfg(feature = "builder")] {
let ldc = LinuxDeviceCgroupBuilder::default()
.allow(true)
.typ(LinuxDeviceType::B)
.major(1)
.minor(9)
.access("rwm".to_string())
.build()?;
} else {
let ldc = LinuxDeviceCgroup {
allow: true,
typ: Some(LinuxDeviceType::B),
major: Some(1),
minor: Some(9),
access: Some("rwm".into()),
};
}
);
assert_eq!(ldc.to_string(), "b 1:9 rwm");
Ok(())
}

0 comments on commit 5675706

Please sign in to comment.