Skip to content

Commit b4f4051

Browse files
author
John Schulz
committed
Use after() to remove items added by test.
The test initally failed with a 500 when the `after` was added. Debugging narrowed it down to a missing default config. getDefaultAgentConfigId errors if there isn't a default config. The config is added by `setupIngestManager` which _was_ always called during plugin#start but is no longer. We could add the setup call to the test/suite, but instead I changed AgentConfigService.delete to use ensureDefaultAgentConfig instead of getDefaultAgentConfigId. ensureDefaultAgentConfig adds one if it's missing. The check in delete is to make sure we don't delete the default config. We can still do that and now we add a config if it wasn't already there (which seems like A Good Thing)
1 parent 5a8d8b8 commit b4f4051

File tree

2 files changed

+19
-1
lines changed
  • x-pack
    • plugins/ingest_manager/server/services
    • test/ingest_manager_api_integration/apis/package_config

2 files changed

+19
-1
lines changed

x-pack/plugins/ingest_manager/server/services/agent_config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ class AgentConfigService {
336336
throw new Error('Agent configuration not found');
337337
}
338338

339-
const defaultConfigId = await this.getDefaultAgentConfigId(soClient);
339+
const { id: defaultConfigId } = await this.ensureDefaultAgentConfig(soClient);
340340
if (id === defaultConfigId) {
341341
throw new Error('The default agent configuration cannot be deleted');
342342
}

x-pack/test/ingest_manager_api_integration/apis/package_config/get.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ export default function (providerContext: FtrProviderContext) {
5656
packageConfigId = packageConfigResponse.item.id;
5757
});
5858

59+
after(async function () {
60+
if (!server.enabled) {
61+
return;
62+
}
63+
64+
await supertest
65+
.post(`/api/ingest_manager/agent_configs/delete`)
66+
.set('kbn-xsrf', 'xxxx')
67+
.send({ agentConfigId })
68+
.expect(200);
69+
70+
await supertest
71+
.post(`/api/ingest_manager/package_configs/delete`)
72+
.set('kbn-xsrf', 'xxxx')
73+
.send({ packageConfigIds: [packageConfigId] })
74+
.expect(200);
75+
});
76+
5977
it('should succeed with a valid id', async function () {
6078
const { body: apiResponse } = await supertest
6179
.get(`/api/ingest_manager/package_configs/${packageConfigId}`)

0 commit comments

Comments
 (0)