...

Text file src/github.com/opencontainers/runc/tests/integration/README.md

Documentation: github.com/opencontainers/runc/tests/integration

     1# runc Integration Tests
     2
     3Integration tests provide end-to-end testing of runc.
     4
     5Note that integration tests do **not** replace unit tests.
     6
     7As a rule of thumb, code should be tested thoroughly with unit tests.
     8Integration tests on the other hand are meant to test a specific feature end
     9to end.
    10
    11Integration tests are written in *bash* using the
    12[bats (Bash Automated Testing System)](https://github.com/bats-core/bats-core)
    13framework.
    14
    15## Running integration tests
    16
    17The easiest way to run integration tests is with Docker:
    18```
    19$ make integration
    20```
    21Alternatively, you can run integration tests directly on your host through make:
    22```
    23$ sudo make localintegration
    24```
    25Or you can just run them directly using bats
    26```
    27$ sudo bats tests/integration
    28```
    29To run a single test bucket:
    30```
    31$ make integration TESTPATH="/checkpoint.bats"
    32```
    33
    34
    35To 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
    38For 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)
    53are provided in order to facilitate writing tests.
    54
    55```sh
    56#!/usr/bin/env bats
    57
    58# This will load the helpers.
    59load helpers
    60
    61# setup is called at the beginning of every test.
    62function setup() {
    63  setup_busybox
    64}
    65
    66# teardown is called at the end of every test.
    67function 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```

View as plain text