test: add helpers.bash to reduce boilerplate

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
Valentin Rothberg 2019-09-19 11:57:02 +02:00
parent b77abbafa3
commit 66ac3195c8
3 changed files with 17 additions and 4 deletions

View file

@ -1,23 +1,31 @@
#!/usr/bin/env bats -t #!/usr/bin/env bats -t
load helpers
@test "Help" { @test "Help" {
run $CTR_ENGINE run --rm $CTR_IMAGE -h run_ctr $CTR_IMAGE -h
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} =~ "BuildSourceImage.sh version " ]] [[ ${lines[0]} =~ "BuildSourceImage.sh version " ]]
[[ ${lines[1]} =~ "Usage: BuildSourceImage.sh " ]] [[ ${lines[1]} =~ "Usage: BuildSourceImage.sh " ]]
} }
@test "Version" { @test "Version" {
run $CTR_ENGINE run --rm $CTR_IMAGE -v run_ctr $CTR_IMAGE -v
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} =~ "BuildSourceImage.sh version " ]] [[ ${lines[0]} =~ "BuildSourceImage.sh version " ]]
} }
@test "List Drivers" { @test "List Drivers" {
run $CTR_ENGINE run --rm $CTR_IMAGE -l run_ctr $CTR_IMAGE -l
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[0]} =~ "sourcedriver_context_dir" ]] [[ ${lines[0]} =~ "sourcedriver_context_dir" ]]
[[ ${lines[1]} =~ "sourcedriver_extra_src_dir" ]] [[ ${lines[1]} =~ "sourcedriver_extra_src_dir" ]]
[[ ${lines[2]} =~ "sourcedriver_rpm_dir" ]] [[ ${lines[2]} =~ "sourcedriver_rpm_dir" ]]
[[ ${lines[3]} =~ "sourcedriver_rpm_fetch" ]] [[ ${lines[3]} =~ "sourcedriver_rpm_fetch" ]]
} }
@test "No input" {
run_ctr $CTR_IMAGE
[ "$status" -eq 1 ]
[[ ${lines[0]} =~ "[SrcImg][ERROR] provide an input (example: BuildSourceImage.sh -i docker.io/centos -e ./my-sources/ )" ]]
}

View file

@ -1,8 +1,10 @@
#!/usr/bin/env bats -t #!/usr/bin/env bats -t
load helpers
@test "build from RPMS" { @test "build from RPMS" {
d=$(mktemp -d) d=$(mktemp -d)
run $CTR_ENGINE run --rm -v $(pwd)/.testprep/srpms/:/src:ro -v ${d}:/output/ $CTR_IMAGE -s /src run_ctr -v $(pwd)/.testprep/srpms/:/src:ro -v ${d}:/output/ $CTR_IMAGE -s /src
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
#echo ${lines[@]} #echo ${lines[@]}
[[ ${lines[0]} =~ "[SrcImg][INFO] calling source collection drivers" ]] [[ ${lines[0]} =~ "[SrcImg][INFO] calling source collection drivers" ]]

3
test/helpers.bash Normal file
View file

@ -0,0 +1,3 @@
function run_ctr() {
run $CTR_ENGINE run --security-opt label=disable --rm "$@"
}