Skip to content

Commit

Permalink
Fix test for force upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
John Schulz committed Mar 23, 2021
1 parent 871ebcb commit 3334dd1
Showing 1 changed file with 3 additions and 57 deletions.
60 changes: 3 additions & 57 deletions x-pack/test/fleet_api_integration/apis/agents/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ export default function (providerContext: FtrProviderContext) {
expect(typeof agent2data.body.item.upgrade_started_at).to.be('string');
});

it('enrolled in a managed policy bulk upgrade force:true should respond with 200 and object of all success results. Should update the managed agent SOs', async () => {
it('enrolled in a managed policy bulk upgrade with force flag should respond with 200 and update the agent SOs', async () => {
// update enrolled policy to managed
await supertest.put(`/api/fleet/agent_policies/policy1`).set('kbn-xsrf', 'xxxx').send({
name: 'Test policy',
Expand All @@ -628,7 +628,7 @@ export default function (providerContext: FtrProviderContext) {
doc: {
local_metadata: {
elastic: {
agent: { upgradeable: true, version: '0.0.0' },
agent: { upgradeable: true, version: semver.inc(kibanaVersion, 'patch') },
},
},
},
Expand All @@ -642,67 +642,13 @@ export default function (providerContext: FtrProviderContext) {
version: kibanaVersion,
agents: ['agent1', 'agent2'],
force: true,
})
.expect(200);
});

expect(body).to.eql({
agent1: { success: true },
agent2: { success: true },
});

const [agent1data, agent2data] = await Promise.all([
supertest.get(`/api/fleet/agents/agent1`),
supertest.get(`/api/fleet/agents/agent2`),
]);

expect(typeof agent1data.body.item.upgrade_started_at).to.be('string');
expect(typeof agent2data.body.item.upgrade_started_at).to.be('string');
});

it('enrolled in a managed policy bulk upgrade with force flag should respond with 200 and update the agent SOs', async () => {
// update enrolled policy to managed
await supertest.put(`/api/fleet/agent_policies/policy1`).set('kbn-xsrf', 'xxxx').send({
name: 'Test policy',
namespace: 'default',
is_managed: true,
});

const kibanaVersion = await kibanaServer.version.get();
await es.update({
id: 'agent1',
refresh: 'wait_for',
index: AGENTS_INDEX,
body: {
doc: {
local_metadata: { elastic: { agent: { upgradeable: true, version: '0.0.0' } } },
},
},
});
await es.update({
id: 'agent2',
refresh: 'wait_for',
index: AGENTS_INDEX,
body: {
doc: {
local_metadata: {
elastic: {
agent: { upgradeable: true, version: semver.inc(kibanaVersion, 'patch') },
},
},
},
},
});
// attempt to upgrade agent in managed policy
const { body } = await supertest
.post(`/api/fleet/agents/bulk_upgrade`)
.set('kbn-xsrf', 'xxx')
.send({
version: kibanaVersion,
agents: ['agent1', 'agent2'],
force: true,
});
expect(body).to.eql({});

const [agent1data, agent2data] = await Promise.all([
supertest.get(`/api/fleet/agents/agent1`),
supertest.get(`/api/fleet/agents/agent2`),
Expand Down

0 comments on commit 3334dd1

Please sign in to comment.