Skip to content

Commit

Permalink
Add info on how to run/debug a test via VSCode (#642)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkralik3 authored Dec 15, 2023
1 parent d80f09b commit 3fabb60
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
# Test binary, build with `go test -c`
*.test

## Test results folders
tests/result-*

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

Expand All @@ -18,6 +21,9 @@
.vscode
.history

# a file with custom ENVs, e.g. for passing ENVs into VS code run/debbug runners
test.env

### Goland ###
.idea

Expand Down
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,51 @@ To run multi-cluster tests, ensure that the `KUBECONFIG2` environment variable p

The tests in maistra-test-tool are standard go tests and can be run in an IDE using standard methods. No special setup is required.

#### VSCode tweaks

To show/run/debug code in VSCode, you need to install the GO extension.

##### Running test

If you want to run some test case directly from VSCode (via the Testing panel or from source code tooltips), you need to pass required ENVs and flags and increase the default test timeout. Add(update) the following settings into settings.json (`CTRL+SHIFT+P` > `Open User Settings (JSON)`)
```
"go.testEnvFile": "${workspaceFolder}/test.env",
"go.testTimeout": "30m",
"go.testFlags": [
"-v"
]
```
After that, create `test.env` file in the test suite root and add all required/desired environment variables, e.g.
```
SMCP_VERSION=2.4
MUST_GATHER=false
```

##### Debugging test

The test can be also debugged (via the Testing panel or from source code tooltips) with the setting above however, the debug console doesn't show the same output in the debug console as during the running phase in output. You can use the following custom launch.json (Add it to the .vscode folder or update the existing one)
```
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug test case",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"envFile": "${workspaceFolder}/test.env",
"args": [
"-test.v",
"-test.run",
"${selectedText}"
],
}
]
}
```
After that, you can easily debug the test case by highlighting the name of the test method and pressing F5 (If you have that `Debug test case` config selected in the Run and Debug panel).

### Reducing log output

Due to the eventually-consistent nature of OpenShift clusters, each test performs a series of retry attempts of each action it performs.
Expand Down

0 comments on commit 3fabb60

Please sign in to comment.