github.com/opencontainers/runc@v1.2.0-rc.1.0.20240520010911-492dc558cdd6/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 (Bash Automated Testing System)](https://github.com/bats-core/bats-core)
    13  framework.
    14  
    15  ## Running integration tests
    16  
    17  The easiest way to run integration tests is with Docker:
    18  ```
    19  $ make integration
    20  ```
    21  Alternatively, you can run integration tests directly on your host through make:
    22  ```
    23  $ sudo make localintegration
    24  ```
    25  Or you can just run them directly using bats
    26  ```
    27  $ sudo bats tests/integration
    28  ```
    29  To run a single test bucket:
    30  ```
    31  $ make integration TESTPATH="/checkpoint.bats"
    32  ```
    33  
    34  
    35  To run them on your host, you need to set up a development environment plus
    36  [bats (Bash Automated Testing System)](https://github.com/bats-core/bats-core#installing-bats-from-source).
    37  
    38  For example:
    39  ```
    40  $ cd ~/go/src/github.com
    41  $ git clone https://github.com/bats-core/bats-core.git
    42  $ cd bats-core
    43  $ ./install.sh /usr/local
    44  ```
    45  
    46  > **Note**: There are known issues running the integration tests using
    47  > **devicemapper** as a storage driver, make sure that your docker daemon
    48  > is using **aufs** if you want to successfully run the integration tests.
    49  
    50  ## Writing integration tests
    51  
    52  [helper functions](https://github.com/opencontainers/runc/blob/master/tests/integration/helpers.bash)
    53  are provided in order to facilitate writing tests.
    54  
    55  ```sh
    56  #!/usr/bin/env bats
    57  
    58  # This will load the helpers.
    59  load helpers
    60  
    61  # setup is called at the beginning of every test.
    62  function setup() {
    63    setup_busybox
    64  }
    65  
    66  # teardown is called at the end of every test.
    67  function teardown() {
    68    teardown_bundle
    69  }
    70  
    71  @test "this is a simple test" {
    72    runc run containerid
    73    # "The runc macro" automatically populates $status, $output and $lines.
    74    # Please refer to bats documentation to find out more.
    75    [ "$status" -eq 0 ]
    76  
    77    # check expected output
    78    [[ "${output}" == *"Hello"* ]]
    79  }
    80  ```