aboutsummaryrefslogtreecommitdiff
path: root/test/kpod_wait.bats
blob: 8d11e634d9c2e647ec4767785aaa250ec58208b7 (plain)
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
#!/usr/bin/env bats

load helpers

IMAGE="redis:alpine"

# Returns the POD ID
function pod_run_from_template(){
    #1=name, 2=uid, 3=namespace) {
    NAME=$1 CUID=$2 NAMESPACE=$3 envsubst < ${TESTDATA}/template_sandbox_config.json > ${TESTDIR}/pod-${1}.json
    crioctl pod run --config ${TESTDIR}/pod-${1}.json
}

# Returns the container ID
function container_create_from_template() {
    #1=name, 2=image, 3=command, 4=id) {
    NAME=$1 IMAGE=$2 COMMAND=$3 envsubst < ${TESTDATA}/template_container_config.json > ${TESTDIR}/ctr-${1}.json
    crioctl ctr create --config ${TESTDIR}/ctr-${1}.json --pod "$4"
}

function container_start() {
    #1=id
    crioctl ctr start --id "$1"

}
@test "wait on a bogus container" {
    skip "Needs to be converted to kpod run"
    start_crio
    run ${KPOD_BINARY} ${KPOD_OPTIONS} wait 12343
    echo $output
    [ "$status" -eq 1 ]
    stop_crio
}

@test "wait on a stopped container" {
    skip "Needs to be converted to kpod run"
    run ${KPOD_BINARY} ${KPOD_OPTIONS} pull docker.io/library/busybox:latest
    echo $output
    [ "$status" -eq 0 ]
    start_crio
    pod_id=$( pod_run_from_template "test" "test" "test1-1" )
    echo $pod_id
    ctr_id=$(container_create_from_template "test-CTR" "docker.io/library/busybox:latest" '["ls"]' "${pod_id}")
    echo $ctr_id
    container_start $ctr_id
    run ${KPOD_BINARY} ${KPOD_OPTIONS} wait $ctr_id
    [ "$status" -eq 0 ]
    cleanup_ctrs
    cleanup_pods
    stop_crio
}

@test "wait on a sleeping container" {
    skip "Needs to be converted to kpod run"
    run ${KPOD_BINARY} ${KPOD_OPTIONS} pull docker.io/library/busybox:latest
    echo $output
    [ "$status" -eq 0 ]
    start_crio
    pod_id=$( pod_run_from_template "test" "test" "test1-1" )
    echo $pod_id
    ctr_id=$(container_create_from_template "test-CTR" "docker.io/library/busybox:latest" '["sleep", "5"]' "${pod_id}")
    echo $ctr_id
    run container_start $ctr_id
    echo $output
    [ "$status" -eq 0 ]
    run ${KPOD_BINARY} ${KPOD_OPTIONS} wait $ctr_id
    echo $output
    [ "$status" -eq 0 ]
    cleanup_ctrs
    cleanup_pods
    stop_crio
}