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

     1  # runc Integration Tests
     2  
     3  Integration tests provide end-to-end testing of runc.
     4  
     5  Note that integration tests do **not** replace unit tests.
     6  
     7  As a rule of thumb, code should be tested thoroughly with unit tests.
     8  Integration tests on the other hand are meant to test a specific feature end
     9  to end.
    10  
    11  Integration tests are written in *bash* using the
    12  [bats](https://github.com/sstephenson/bats) framework.
    13  
    14  ## Running integration tests
    15  
    16  The easiest way to run integration tests is with Docker:
    17  ```
    18  $ make integration
    19  ```
    20  Alternatively, you can run integration tests directly on your host through make:
    21  ```
    22  $ sudo make localintegration
    23  ```
    24  Or you can just run them directly using bats
    25  ```
    26  $ sudo bats tests/integration
    27  ```
    28  To run a single test bucket:
    29  ```
    30  $ make integration TESTFLAGS="/checkpoint.bats"
    31  ```
    32  
    33  
    34  To run them on your host, you will need to setup a development environment plus
    35  [bats](https://github.com/sstephenson/bats#installing-bats-from-source)
    36  For example:
    37  ```
    38  $ cd ~/go/src/github.com
    39  $ git clone https://github.com/sstephenson/bats.git
    40  $ cd bats
    41  $ ./install.sh /usr/local
    42  ```
    43  
    44  > **Note**: There are known issues running the integration tests using
    45  > **devicemapper** as a storage driver, make sure that your docker daemon
    46  > is using **aufs** if you want to successfully run the integration tests.
    47  
    48  ## Writing integration tests
    49  
    50  [helper functions]
    51  (https://github.com/opencontainers/runc/blob/master/test/integration/helpers.bash)
    52  are provided in order to facilitate writing tests.
    53  
    54  ```sh
    55  #!/usr/bin/env bats
    56  
    57  # This will load the helpers.
    58  load helpers
    59  
    60  # setup is called at the beginning of every test.
    61  function setup() {
    62    # see functions teardown_hello and setup_hello in helpers.bash, used to
    63    # create a pristine environment for running your tests
    64    teardown_hello
    65    setup_hello
    66  }
    67  
    68  # teardown is called at the end of every test.
    69  function teardown() {
    70    teardown_hello
    71  }
    72  
    73  @test "this is a simple test" {
    74    runc run containerid
    75    # "The runc macro" automatically populates $status, $output and $lines.
    76    # Please refer to bats documentation to find out more.
    77    [ "$status" -eq 0 ]
    78  
    79    # check expected output
    80    [[ "${output}" == *"Hello"* ]]
    81  }
    82  
    83  ```