github.com/fastly/cli@v1.7.2-0.20240304164155-9d0f1d77c3bf/TESTING.md (about)

     1  ## Testing
     2  
     3  To run the test suite:
     4  
     5  ```sh
     6  make test
     7  ```
     8  
     9  Note that by default the tests are run using `go test` with the following configuration:
    10  
    11  ```
    12  -race ./{cmd,pkg}/...
    13  ```
    14  
    15  To run a specific test use the `-run` flag (exposed by `go test`) and also provide the path to the directory where the test files reside (replace `...` and `<path>` with appropriate values):
    16  
    17  ```sh
    18  make test TEST_ARGS="-run <...> <path>"
    19  ```
    20  
    21  **Example**:
    22  
    23  ```sh
    24  make test TEST_ARGS="-run TestBackendCreate ./pkg/commands/backend"
    25  ```
    26  
    27  Some integration tests aren't run outside of the CI environment, to enable these tests locally you'll need to set a specific environment variable relevant to the test.
    28  
    29  The available environment variables are:
    30  
    31  - `TEST_COMPUTE_INIT`: runs `TestInit`.
    32  - `TEST_COMPUTE_BUILD`: runs `TestBuildRust`, `TestBuildAssemblyScript` and `TestBuildJavaScript`.
    33  - `TEST_COMPUTE_BUILD_RUST`: runs `TestBuildRust`.
    34  - `TEST_COMPUTE_BUILD_ASSEMBLYSCRIPT`: runs `TestBuildAssemblyScript`.
    35  - `TEST_COMPUTE_BUILD_JAVASCRIPT`: runs `TestBuildJavaScript`.
    36  - `TEST_COMPUTE_DEPLOY`: runs `TestDeploy`.
    37  
    38  **Example**:
    39  
    40  ```sh
    41  TEST_COMPUTE_BUILD_RUST=1 make test TEST_ARGS="-run TestBuildRust/fastly_crate_prerelease ./pkg/compute/..." 
    42  ```
    43  
    44  When running the tests locally, if you don't have the relevant language ecosystems set-up properly then the tests will fail to run and you'll need to review the code to see what the remediation steps are, as that output doesn't get shown when running the test suite.
    45  
    46  > **NOTE**: you might notice a discrepancy between CI and your local environment which is caused by the difference in Rust toolchain versions as defined in .github/workflows/pr_test.yml which specifies the version required to be tested for in CI. Running `rustup toolchain install <version>` and `rustup target add wasm32-wasi --toolchain <version>` will resolve any failing integration tests you may be running locally.
    47  
    48  To the run the full test suite:
    49  
    50  ```sh
    51  TEST_COMPUTE_INIT=1 TEST_COMPUTE_BUILD=1 TEST_COMPUTE_DEPLOY=1 TEST_COMMAND=gotest make all
    52  ```
    53  
    54  > **NOTE**: `TEST_COMMAND` is optional and allows the use of https://github.com/rakyll/gotest to improve test output.
    55  
    56  ### Debugging
    57  
    58  To debug failing tests you can use [Delve](<>).
    59  
    60  Essentially, `cd` into a package directory (where the `_test.go` file is you want to run) and then execute...
    61  
    62  ```
    63  TEST_COMPUTE_BUILD=1 dlv test -- -test.v -test.run TestNameGoesHere
    64  ```
    65  
    66  Once that is done, you can set breakpoints. For example:
    67  
    68  ```
    69  break ../../app/run.go:152
    70  ```
    71  
    72  > **NOTE:** The path is relative to the package directory you're running the test file.