Skip to content

Commit

Permalink
test: add tests for tree output formats
Browse files Browse the repository at this point in the history
This commit adds tests for tree format in addition to existing tests for
the default output format (table).

Signed-off-by: Kouame Behouba Manasse <[email protected]>
  • Loading branch information
behouba committed Jun 25, 2023
1 parent 61cad9e commit 0812b22
Showing 1 changed file with 161 additions and 15 deletions.
176 changes: 161 additions & 15 deletions test/checkpointctl.bats
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,59 @@ function teardown() {
[[ ${lines[0]} == *"checkpoint directory is missing in the archive file"* ]]
}

@test "Run checkpointctl show with tar file with empty config.dump" {
@test "Run checkpointctl show with tar file with empty config.dump [table]" {
touch "$TEST_TMP_DIR1"/config.dump
mkdir "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show "$TEST_TMP_DIR2"/test.tar
checkpointctl show "$TEST_TMP_DIR2"/test.tar --format=table
[ "$status" -eq 1 ]
[[ ${lines[0]} == *"config.dump: unexpected end of JSON input" ]]
}

@test "Run checkpointctl show with tar file with empty config.dump [tree]" {
touch "$TEST_TMP_DIR1"/config.dump
mkdir "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show "$TEST_TMP_DIR2"/test.tar --format=tree
[ "$status" -eq 1 ]
[[ ${lines[0]} == *"config.dump: unexpected end of JSON input" ]]
}

@test "Run checkpointctl show with tar file with valid config.dump and no spec.dump" {
@test "Run checkpointctl show with tar file with valid config.dump and no spec.dump [table]" {
cp data/config.dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show "$TEST_TMP_DIR2"/test.tar
checkpointctl show "$TEST_TMP_DIR2"/test.tar --format=table
[ "$status" -eq 1 ]
[[ ${lines[0]} == *"spec.dump: no such file or directory" ]]
}


@test "Run checkpointctl show with tar file with valid config.dump and no spec.dump [tree]" {
cp data/config.dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show "$TEST_TMP_DIR2"/test.tar --format=tree
[ "$status" -eq 1 ]
[[ ${lines[0]} == *"spec.dump: no such file or directory" ]]
}

@test "Run checkpointctl show with tar file with valid config.dump and empty spec.dump" {
@test "Run checkpointctl show with tar file with valid config.dump and empty spec.dump [table]" {
cp data/config.dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
touch "$TEST_TMP_DIR1"/spec.dump
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show "$TEST_TMP_DIR2"/test.tar
checkpointctl show "$TEST_TMP_DIR2"/test.tar --format=table
[ "$status" -eq 1 ]
[[ ${lines[0]} == *"spec.dump: unexpected end of JSON input" ]]
}

@test "Run checkpointctl show with tar file with valid config.dump and empty spec.dump [tree]" {
cp data/config.dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
touch "$TEST_TMP_DIR1"/spec.dump
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show "$TEST_TMP_DIR2"/test.tar --format=tree
[ "$status" -eq 1 ]
[[ ${lines[0]} == *"spec.dump: unexpected end of JSON input" ]]
}
Expand All @@ -95,18 +124,32 @@ function teardown() {
[[ ${lines[4]} == *"Podman"* ]]
}

@test "Run checkpointctl show with tar file from containerd with valid config.dump and valid spec.dump and checkpoint directory" {
@test "Run checkpointctl show with tar file from containerd with valid config.dump and valid spec.dump and checkpoint directory [table]" {
cp data/config.dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
echo "{}" > "$TEST_TMP_DIR1"/status
echo "{}" > "$TEST_TMP_DIR1"/spec.dump
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show "$TEST_TMP_DIR2"/test.tar
checkpointctl show "$TEST_TMP_DIR2"/test.tar --format=table
[ "$status" -eq 0 ]
[[ ${lines[4]} == *"containerd"* ]]
}

@test "Run checkpointctl show with tar file and --stats and missing stats-dump" {
@test "Run checkpointctl show with tar file from containerd with valid config.dump and valid spec.dump and checkpoint directory [tree]" {
cp data/config.dump "$TEST_TMP_DIR1"
echo "{}" > "$TEST_TMP_DIR1"/status
echo "{}" > "$TEST_TMP_DIR1"/spec.dump
cp test-imgs/stats-dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
cp test-imgs/pstree.img \
test-imgs/core-*.img "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show "$TEST_TMP_DIR2"/test.tar --format=tree
[ "$status" -eq 0 ]
[[ ${lines[6]} == *"containerd"* ]]
}

@test "Run checkpointctl show with tar file and --stats and missing stats-dump [table]" {
cp data/config.dump "$TEST_TMP_DIR1"
cp data/spec.dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
Expand All @@ -116,7 +159,17 @@ function teardown() {
[[ ${lines[6]} == *"failed to get dump statistics"* ]]
}

@test "Run checkpointctl show with tar file and --stats and invalid stats-dump" {
@test "Run checkpointctl show with tar file and --stats and missing stats-dump [tree]" {
cp data/config.dump "$TEST_TMP_DIR1"
cp data/spec.dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show "$TEST_TMP_DIR2"/test.tar --stats --format=tree
[ "$status" -eq 1 ]
[[ ${lines[0]} == *"failed to get dump statistics"* ]]
}

@test "Run checkpointctl show with tar file and --stats and invalid stats-dump [table]" {
cp data/config.dump "$TEST_TMP_DIR1"
cp data/spec.dump "$TEST_TMP_DIR1"
cp data/spec.dump "$TEST_TMP_DIR1"/stats-dump
Expand All @@ -127,6 +180,17 @@ function teardown() {
[[ ${lines[6]} == *"Unknown magic"* ]]
}

@test "Run checkpointctl show with tar file and --stats and invalid stats-dump [tree]" {
cp data/config.dump "$TEST_TMP_DIR1"
cp data/spec.dump "$TEST_TMP_DIR1"
cp data/spec.dump "$TEST_TMP_DIR1"/stats-dump
mkdir "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show "$TEST_TMP_DIR2"/test.tar --stats --format=tree
[ "$status" -eq 1 ]
[[ ${lines[0]} == *"Unknown magic"* ]]
}

@test "Run checkpointctl show with tar file and --stats and valid stats-dump" {
cp data/config.dump "$TEST_TMP_DIR1"
cp data/spec.dump "$TEST_TMP_DIR1"
Expand Down Expand Up @@ -164,7 +228,7 @@ function teardown() {
[[ ${lines[10]} == *"/proc"* ]]
}

@test "Run checkpointctl show with tar file and --all and valid spec.dump and valid stats-dump" {
@test "Run checkpointctl show with tar file and --all and valid spec.dump and valid stats-dump [table]" {
cp data/config.dump "$TEST_TMP_DIR1"
cp data/spec.dump "$TEST_TMP_DIR1"
cp test-imgs/stats-dump "$TEST_TMP_DIR1"
Expand All @@ -185,6 +249,26 @@ function teardown() {
[[ ${lines[21]} == *"piggie"* ]]
}

@test "Run checkpointctl show with tar file and --all and valid spec.dump and valid stats-dump [tree]" {
cp data/config.dump "$TEST_TMP_DIR1"
cp data/spec.dump "$TEST_TMP_DIR1"
cp test-imgs/stats-dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
cp test-imgs/pstree.img \
test-imgs/core-*.img "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show "$TEST_TMP_DIR2"/test.tar --all --format=tree
[ "$status" -eq 0 ]
[[ ${lines[8]} == *"Overview of Mounts"* ]]
[[ ${lines[9]} == *"Destination: /proc"* ]]
[[ ${lines[12]} == *"Destination: /etc/hostname"* ]]
[[ ${lines[15]} == *"CRIU dump statistics"* ]]
[[ ${lines[19]} == *"Memwrite Time"* ]]
[[ ${lines[20]} =~ [1-9]+" us" ]]
[[ ${lines[22]} == *"Process tree"* ]]
[[ ${lines[23]} == *"piggie"* ]]
}

@test "Run checkpointctl show with tar file and missing --mounts/--all and --full-paths" {
cp data/config.dump "$TEST_TMP_DIR1"
cp data/spec.dump "$TEST_TMP_DIR1"
Expand All @@ -204,7 +288,7 @@ function teardown() {
[[ ${lines[0]} == *"Error: checkpoint directory is missing in the archive file"* ]]
}

@test "Run checkpointctl show with tar file with valid config.dump and valid spec.dump (CRI-O) and checkpoint directory" {
@test "Run checkpointctl show with tar file with valid config.dump and valid spec.dump (CRI-O) and checkpoint directory [table]" {
cp data/config.dump "$TEST_TMP_DIR1"
cp data/spec.dump.cri-o "$TEST_TMP_DIR1"/spec.dump
mkdir "$TEST_TMP_DIR1"/checkpoint
Expand All @@ -214,6 +298,19 @@ function teardown() {
[[ ${lines[4]} == *"CRI-O"* ]]
}

@test "Run checkpointctl show with tar file with valid config.dump and valid spec.dump (CRI-O) and checkpoint directory [tree]" {
cp data/config.dump "$TEST_TMP_DIR1"
cp data/spec.dump.cri-o "$TEST_TMP_DIR1"/spec.dump
cp test-imgs/stats-dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
cp test-imgs/pstree.img \
test-imgs/core-*.img "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show "$TEST_TMP_DIR2"/test.tar --format=tree
[ "$status" -eq 0 ]
[[ ${lines[6]} == *"CRI-O"* ]]
}

@test "Run checkpointctl show with tar file compressed" {
cp data/config.dump "$TEST_TMP_DIR1"
cp data/spec.dump "$TEST_TMP_DIR1"
Expand Down Expand Up @@ -246,7 +343,7 @@ function teardown() {
[[ ${lines[0]} == *"Error: unexpected EOF"* ]]
}

@test "Run checkpointctl show with tar file and rootfs-diff tar file" {
@test "Run checkpointctl show with tar file and rootfs-diff tar file [table]" {
cp data/config.dump "$TEST_TMP_DIR1"
cp data/spec.dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
Expand All @@ -258,6 +355,21 @@ function teardown() {
[[ ${lines[2]} == *"ROOT FS DIFF SIZE"* ]]
}

@test "Run checkpointctl show with tar file and rootfs-diff tar file [tree]" {
cp data/config.dump "$TEST_TMP_DIR1"
cp data/spec.dump "$TEST_TMP_DIR1"
cp test-imgs/stats-dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
echo 1 > "$TEST_TMP_DIR1"/test.pid
cp test-imgs/pstree.img \
test-imgs/core-*.img "$TEST_TMP_DIR1"/checkpoint
tar -cf "$TEST_TMP_DIR1"/rootfs-diff.tar -C "$TEST_TMP_DIR1" test.pid
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show "$TEST_TMP_DIR2"/test.tar --format=tree
[ "$status" -eq 0 ]
[[ ${lines[8]} == *"Root Fs Diff Size"* ]]
}

@test "Run checkpointctl show with tar file and --ps-tree" {
cp data/config.dump \
data/spec.dump "$TEST_TMP_DIR1"
Expand All @@ -270,17 +382,51 @@ function teardown() {
[[ ${lines[8]} == *"piggie"* ]]
}

@test "Run checkpointctl show with multiple tar files" {
@test "Run checkpointctl show with tar file with --ps-tree and missing pstree.img [table]" {
cp data/config.dump \
data/spec.dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show "$TEST_TMP_DIR2"/test.tar --ps-tree
[ "$status" -eq 1 ]
[[ ${lines[6]} == *"no such file or directory"* ]]
}

@test "Run checkpointctl show with tar file with --ps-tree and missing pstree.img [tree]" {
cp data/config.dump \
data/spec.dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show "$TEST_TMP_DIR2"/test.tar --ps-tree --format=tree
[ "$status" -eq 1 ]
[[ ${lines[0]} == *"no such file or directory"* ]]
}

@test "Run checkpointctl show with multiple tar files [table]" {
cp data/config.dump "$TEST_TMP_DIR1"
cp data/spec.dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test1.tar . && tar cf "$TEST_TMP_DIR2"/test2.tar . )
checkpointctl show "$TEST_TMP_DIR2"/*.tar
checkpointctl show "$TEST_TMP_DIR2"/*.tar --format=table
[ "$status" -eq 0 ]
[[ ${lines[3]} == *"Podman"* ]]
[[ ${lines[5]} == *"Podman"* ]]
}

@test "Run checkpointctl show with multiple tar files [tree]" {
cp data/config.dump "$TEST_TMP_DIR1"
cp data/spec.dump "$TEST_TMP_DIR1"
cp test-imgs/stats-dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
cp test-imgs/pstree.img \
test-imgs/core-*.img "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test1.tar . && tar cf "$TEST_TMP_DIR2"/test2.tar . )
checkpointctl show "$TEST_TMP_DIR2"/*.tar --format=tree
[ "$status" -eq 0 ]
[[ ${lines[6]} == *"Podman"* ]]
[[ ${lines[30]} == *"Podman"* ]]
}

@test "Run checkpointctl show with multiple tar files with additional flags" {
cp data/config.dump "$TEST_TMP_DIR1"
cp data/spec.dump "$TEST_TMP_DIR1"
Expand Down

0 comments on commit 0812b22

Please sign in to comment.