@@ -141,60 +141,118 @@ when running them manually, such as `ELASTICSEARCH_HOST`, `ELASTICSEARCH_USERNAM
141
141
142
142
### Debugging tests
143
143
144
- #### Manually debugging tests on VMs
145
- Many of the integration tests will install the Elastic-Agent and/or
146
- require root to run, which makes it hard to just run them on our work
147
- machines, the best way to circumvent that is to debug the tests
148
- directly on a VM. ` mage integration:DeployDebugTools ` will show a menu
149
- to select a VM and then install the common debugging tools: Delve,
150
- Mage and Docker. It will also create the ` ~/elastic-agent ` folder
151
- containing the Git repository (required to package from within the VM)
144
+ #### Connecting to VMs
145
+ All VMs (including Windows) support connections via SSH, the framework
146
+ generates and stores the necessary SSH keys to access the VMs, the
147
+ easiest way to connect to them is using the SSH command returned by
148
+ ` mage integration:SSH ` . It will list the VMs and ask to select
149
+ one.
150
+
151
+ On a Unix shell you can run ` $(mage integration:SSH) ` , the menu is
152
+ printed to stderr and the SSH command to stdout. After selecting the
153
+ VM you will have shell connected to it.
154
+
155
+ #### Credentials for cloud stack/projects
156
+ All cloud deployments and projects can be listed with `mage
157
+ integration: listStacks `, they can be used to manually connect to
158
+ Kibana and Elasticsearch.
159
+
160
+ If you need to manually run tests against any deployments, `mage
161
+ integration: GenerateEnvFile ` will generate a file called ` env.sh` that
162
+ exports environment variables for Unix compatible shells, you can load
163
+ them into your shell by running ` source ./env.sh ` .
164
+
165
+ To easily deploy the credentials to any VM, just run `mage
166
+ integration: DeployEnvFile `. A menu will ask for the desired Stack and
167
+ VM.
168
+
169
+ #### Manually running the tests (using ` go test ` )
170
+ If you want to run the tests manually, skipping the test runner, set the
171
+ ` TEST_DEFINE_PREFIX ` environment variable to any value and run your tests normally
172
+ with ` go test ` . E.g.:
173
+
174
+ ``` shell
175
+ TEST_DEFINE_PREFIX=gambiarra go test -v -tags integration -run TestProxyURL ./testing/integration/
176
+ ```
177
+
178
+ You will need the environment variables containing the stack URL and
179
+ credentials for the tests to succeed.
180
+
181
+ #### Installing debug/build tools
182
+ ` mage integration:DeployDebugTools ` will install a few tools necessary
183
+ to build the Elastic-Agent in the VM and debug tests:
184
+ - Docker
185
+ - Delve
186
+ - Mage
187
+
188
+ When called, it will show a menu to select a VM and then install the
189
+ tools listed above. It will also create the ` ~/elastic-agent ` folder
190
+ containing the Git repository (required o package from within the VM)
152
191
and the last version of the code uploaded to the VM. This allows you
153
192
to easily build/package the Elastic-Agent from within the VM as well
154
193
as run any tests.
155
194
156
- After deploying the debug tools, ` mage integrationDeployEnvFile ` will
157
- create a ` env.sh ` and copy it to a selected VM, sourcing it will allow
158
- you to any test against the Cloud Stack you selected.
195
+ In the VM there are two important folders:
196
+ - ` agent ` : that is created by the integration test framework and used
197
+ by ` mage ` to run the tests, it gets updated every time you run an
198
+ integration test from your machine.
199
+ - ` elastic-agen ` : that is a copy ` agent ` with Git information created
200
+ by ` mage integration:DeployDebugTools ` , the Git information there is
201
+ not a copy from your machine, but it will work if you need to
202
+ package the Elastic-Agent from the VM. Most of the time you won't
203
+ need it.
159
204
160
- Example of how to run a test from within the VM:
161
- ```
162
- ## Run a single test
163
- SNAPSHOT=true TEST_PLATFORMS="linux/amd64" mage integration:single TestLogIngestionFleetManaged
164
- ## Let's suppose it has failed
205
+ ** Step-by-Step commands**
165
206
207
+ ``` shell
166
208
# # Install DebugTools
167
209
mage -v integration:DeployDebugTools
168
210
169
211
# # Generate and deploy env file
170
212
mage -v integration:DeployEnvFile
171
213
172
214
# # SSH into the VM
173
- $(mage integration:SSHVM )
215
+ $( mage integration:SSH )
174
216
175
217
# # From inside the VM, the test needs root
176
218
sudo su
177
219
source ./env.sh
178
- cd elastic-agent
220
+ cd agent # That's the folder the mage automation uses to run the tests
221
+
222
+ # # Then run the test using `go test`
223
+
224
+ TEST_DEFINE_PREFIX=gambiarra AGENT_VERSION=" 8.16.0-SNAPSHOT" go test -tags=integration -v ./testing/integration/ -run TestLogIngestionFleetManaged
225
+
226
+ # # Run the test using delve:
179
227
# # Any flags passed to the test binary go after the '--', they also need to
180
228
# # include the `test.` prefix if they're for `go test`
181
229
TEST_DEFINE_PREFIX=gambiarra dlv test ./testing/integration/ --build-flags=" -tags integration" -- -test.v -test.run TestLogIngestionFleetManaged
182
230
```
183
231
184
- ** A Delve trick**
232
+ ** A Delve trick: **
185
233
If you didn't build the Elastic-Agent directly on the machine you're
186
234
debugging, it is very likely the location of the source code is
187
235
different, hence delve cannot show you the code it is running. To
188
236
solve this, once on Delve shell, run:
189
237
``
190
- config substitute-path /go/src/github.com/elastic/elastic-agent /home/ubuntu/elastic- agent`
238
+ config substitute-path /go/src/github.com/elastic/elastic-agent /home/ubuntu/agent
191
239
``
192
240
where:
193
241
- ` /go/src/github.com/elastic/elastic-agent ` is the path annotated in
194
242
the binary you are debugging (the one Delve shows).
195
- - ` /home/ubuntu/elastic- agent ` is where Delve should read the source
243
+ - ` /home/ubuntu/agent ` is where Delve should read the source
196
244
code form.
197
245
246
+ #### Other useful mage targets:
247
+ - ` integration:stacks ` lists all stack deployments and connection
248
+ information in a human readable table.
249
+ - ` integration:listInstances ` lists all VMs and their connection
250
+ command in a human readable table. It also lists the URL for the
251
+ VM page on GCP, which is helpful to verify if the VM still exists
252
+ (OGC VMs are automatically deleted)
253
+ - ` integration:printState ` is a shortcut for running the two commands
254
+ above.
255
+
198
256
#### Auto diagnostics retrieval
199
257
When an integration test fails the testing fixture will try its best to automatically collect the diagnostic
200
258
information of the installed Elastic Agent. In the case that diagnostics is collected the test runner will
@@ -223,42 +281,6 @@ until it reports a failure.
223
281
224
282
- ` TEST_RUN_UNTIL_FAILURE=true mage integration:single [testName] `
225
283
226
- ## Manually running the tests
227
-
228
- If you want to run the tests manually, skipping the test runner, set the
229
- ` TEST_DEFINE_PREFIX ` environment variable to any value and run your tests normally
230
- with ` go test ` . E.g.:
231
-
232
- ``` shell
233
- TEST_DEFINE_PREFIX=gambiarra go test -v -tags integration -run TestProxyURL ./testing/integration/
234
- ```
235
-
236
- ## Connecting to VMs and running tests
237
- ### Connecting to VMs
238
- All VMs (including Windows) support connections via SSH, the framework
239
- generates and stores the necessary SSH keys to access the VMs, the
240
- easiest way to connect to them is using the SSH command returned by
241
- ` mage integration:SSHVM ` . It will list the VMs and ask to select
242
- one.
243
-
244
- On a Unix shell you can run ` $(mage integration:SSHVM) ` , the menu is
245
- printed to stderr and the SSH command to stdout. After selecting the
246
- VM you will have shell connected to it.
247
-
248
- ### Credentials for cloud stack/projects
249
- All cloud deployments and projects can be listed with `mage
250
- integration: stacks `, they can be used to manually connect to
251
- Kibana and Elasticsearch.
252
-
253
- If you need to manually run tests against any deployments, `mage
254
- integration: GenerateEnvFile ` will generate a file called ` env.sh` that
255
- exports environment variables for Unix compatible shells, you can load
256
- them into your shell by running ` source ./env.sh ` .
257
-
258
- To easily deploy the credentials to any VM, just run `mage
259
- integration: DeployEnvFile `. A menu will ask for the desired Stack and
260
- VM.
261
-
262
284
## Writing tests
263
285
264
286
Write integration and E2E tests by adding them to the ` testing/integration `
0 commit comments