github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/mergeCode/runc/tests/integration/list.bats (about)

     1  #!/usr/bin/env bats
     2  
     3  load helpers
     4  
     5  function setup() {
     6    teardown_running_container_inroot test_box1 $HELLO_BUNDLE
     7    teardown_running_container_inroot test_box2 $HELLO_BUNDLE
     8    teardown_running_container_inroot test_box3 $HELLO_BUNDLE
     9    teardown_busybox
    10    setup_busybox
    11  }
    12  
    13  function teardown() {
    14    teardown_running_container_inroot test_box1 $HELLO_BUNDLE
    15    teardown_running_container_inroot test_box2 $HELLO_BUNDLE
    16    teardown_running_container_inroot test_box3 $HELLO_BUNDLE
    17    teardown_busybox
    18  }
    19  
    20  @test "list" {
    21    # run a few busyboxes detached
    22    ROOT=$HELLO_BUNDLE runc run -d --console /dev/pts/ptmx test_box1
    23    [ "$status" -eq 0 ]
    24    wait_for_container_inroot 15 1 test_box1 $HELLO_BUNDLE
    25  
    26    ROOT=$HELLO_BUNDLE runc run -d --console /dev/pts/ptmx test_box2
    27    [ "$status" -eq 0 ]
    28    wait_for_container_inroot 15 1 test_box2 $HELLO_BUNDLE
    29  
    30    ROOT=$HELLO_BUNDLE runc run -d --console /dev/pts/ptmx test_box3
    31    [ "$status" -eq 0 ]
    32    wait_for_container_inroot 15 1 test_box3 $HELLO_BUNDLE
    33  
    34    ROOT=$HELLO_BUNDLE runc list
    35    [ "$status" -eq 0 ]
    36    [[ ${lines[0]} =~ ID\ +PID\ +STATUS\ +BUNDLE\ +CREATED+ ]]
    37    [[ "${lines[1]}" == *"test_box1"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]]
    38    [[ "${lines[2]}" == *"test_box2"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]]
    39    [[ "${lines[3]}" == *"test_box3"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]]
    40  
    41    ROOT=$HELLO_BUNDLE runc list -q
    42    [ "$status" -eq 0 ]
    43    [[ "${lines[0]}" == "test_box1" ]]
    44    [[ "${lines[1]}" == "test_box2" ]]
    45    [[ "${lines[2]}" == "test_box3" ]]
    46  
    47    ROOT=$HELLO_BUNDLE runc list --format table
    48    [ "$status" -eq 0 ]
    49    [[ ${lines[0]} =~ ID\ +PID\ +STATUS\ +BUNDLE\ +CREATED+ ]]
    50    [[ "${lines[1]}" == *"test_box1"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]]
    51    [[ "${lines[2]}" == *"test_box2"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]]
    52    [[ "${lines[3]}" == *"test_box3"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]]
    53  
    54    ROOT=$HELLO_BUNDLE runc list --format json
    55    [ "$status" -eq 0 ]
    56    [[ "${lines[0]}" == [\[][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box1\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}]* ]]
    57    [[ "${lines[0]}" == *[,][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box2\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}]* ]]
    58    [[ "${lines[0]}" == *[,][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box3\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}][\]] ]]
    59  }