github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/docs/contributing/how-integration-tests-work.md (about)

     1  ---
     2  title: "How integration tests work"
     3  linkTitle: "How integration tests work"
     4  weight: 5
     5  slug: how-integration-tests-work
     6  ---
     7  
     8  Cortex integration tests are written in Go and based on a [custom framework](https://github.com/cortexproject/cortex/tree/master/integration/e2e) running Cortex and its dependencies in Docker containers and using the Go [`testing`](https://golang.org/pkg/testing/) package for assertions. Integration tests run in CI for every PR, and can be easily executed locally during development (it just requires Docker).
     9  
    10  ## How to run integration tests
    11  
    12  When integration tests run in CI, we build the Cortex docker image based on the PR code and then run the integration tests against it. When running tests **locally** you should build the Cortex Docker image first:
    13  
    14  ```
    15  make ./cmd/cortex/.uptodate
    16  ```
    17  
    18  This will locally build the `quay.io/cortexproject/cortex:latest` image used by integration tests. Whenever the Cortex code changes (`cmd/`, `pkg/` or vendors) you should rebuild the Cortex image, while it's **not** necessary to rebuild it while developing integration tests.
    19  
    20  Once the Docker image is built, you can run integration tests:
    21  
    22  ```
    23  go test -v -tags=requires_docker ./integration/...
    24  ```
    25  
    26  If you want to run a single test you can use a filter. For example, to only run `TestChunksStorageAllIndexBackends`:
    27  
    28  ```
    29  go test -v -tags=requires_docker ./integration -run "^TestChunksStorageAllIndexBackends$"
    30  ```
    31  
    32  ### Supported environment variables
    33  
    34  - **`CORTEX_IMAGE`**<br />
    35    Docker image used to run Cortex in integration tests (defaults to `quay.io/cortexproject/cortex:latest`)
    36  - **`CORTEX_CHECKOUT_DIR`**<br />
    37    The absolute path of the Cortex repository local checkout (defaults to `$GOPATH/src/github.com/cortexproject/cortex`)
    38  - **`E2E_TEMP_DIR`**<br />
    39    The absolute path to a directory where the integration test will create an additional temporary directory to store files generated during the test.
    40  - **`E2E_NETWORK_NAME`**<br />
    41    Name of the docker network to create and use for integration tests. If no variable is set, defaults to `e2e-cortex-test`.
    42  
    43  ### The `requires_docker` tag
    44  
    45  Integration tests have `requires_docker` tag (`// +build requires_docker` line followed by empty line on top of Go files), to avoid running them unintentionally as they require Docker, e.g. by running `go test ./...` in main Cortex package.
    46  
    47  ## Isolation
    48  
    49  Each integration test runs in isolation. For each integration test, we do create a Docker network, start Cortex and its dependencies containers, push/query series to/from Cortex and run assertions on it. Once the test has done, both the Docker network and containers are terminated and deleted.