Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RAM][Maintenance Window] Improve Maintenance Window Backend Integration Testing #157120

Merged
merged 8 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ export default function activeMaintenanceWindowTests({ getService }: FtrProvider
for (const scenario of UserAtSpaceScenarios) {
const { user, space } = scenario;
describe(scenario.id, () => {
afterEach(() => objectRemover.removeAll());
it('should handle update maintenance window request appropriately', async () => {
it('should handle get active maintenance window request appropriately', async () => {
// Create 2 active and 1 inactive maintenance window
const { body: createdMaintenanceWindow1 } = await supertest
.post(`${getUrlPrefix(space.id)}/internal/alerting/rules/maintenance_window`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function updateMaintenanceWindowTests({ getService }: FtrProvider
freq: 2, // weekly
},
};
after(() => objectRemover.removeAll());
afterEach(() => objectRemover.removeAll());

for (const scenario of UserAtSpaceScenarios) {
const { user, space } = scenario;
Expand Down Expand Up @@ -84,5 +84,103 @@ export default function updateMaintenanceWindowTests({ getService }: FtrProvider
});
});
}

it('can archive and unarchive a maintenance window', async () => {
const space1 = UserAtSpaceScenarios[1].space.id;
const { body: createdMaintenanceWindow } = await supertest
.post(`${getUrlPrefix(space1)}/internal/alerting/rules/maintenance_window`)
.set('kbn-xsrf', 'foo')
.send(createParams)
.expect(200);

objectRemover.add(
space1,
createdMaintenanceWindow.id,
'rules/maintenance_window',
'alerting',
true
);

expect(createdMaintenanceWindow.status).eql('running');

const { body: archive } = await supertest
.post(
`${getUrlPrefix(space1)}/internal/alerting/rules/maintenance_window/${
createdMaintenanceWindow.id
}/_archive`
)
.set('kbn-xsrf', 'foo')
.send({ archive: true })
.expect(200);

expect(archive.status).eql('archived');

const { body: unarchived } = await supertest
.post(
`${getUrlPrefix(space1)}/internal/alerting/rules/maintenance_window/${
createdMaintenanceWindow.id
}/_archive`
)
.set('kbn-xsrf', 'foo')
.send({ archive: false })
.expect(200);

expect(unarchived.status).eql('running');
});

it('archiving a finished maintenance window does not change the events', async () => {
const space1 = UserAtSpaceScenarios[1].space.id;
const { body: createdMaintenanceWindow } = await supertest
.post(`${getUrlPrefix(space1)}/internal/alerting/rules/maintenance_window`)
.set('kbn-xsrf', 'foo')
.send({
...createParams,
r_rule: {
...createParams.r_rule,
dtstart: moment.utc().subtract(1, 'day').toISOString(),
freq: 3, // daily
count: 4,
},
})
.expect(200);

objectRemover.add(
space1,
createdMaintenanceWindow.id,
'rules/maintenance_window',
'alerting',
true
);

const { body: finish } = await supertest
.post(
`${getUrlPrefix(space1)}/internal/alerting/rules/maintenance_window/${
createdMaintenanceWindow.id
}/_finish`
)
.set('kbn-xsrf', 'foo')
.send()
.expect(200);

// The finished maintenance window has a different end date for the first event
expect(finish.events[0].lte).eql(createdMaintenanceWindow.events[0].lte);
expect(finish.events[1].lte).not.eql(createdMaintenanceWindow.events[1].lte);
expect(finish.events[2].lte).eql(createdMaintenanceWindow.events[2].lte);
expect(finish.events[3].lte).eql(createdMaintenanceWindow.events[3].lte);

const { body: archive } = await supertest
.post(
`${getUrlPrefix(space1)}/internal/alerting/rules/maintenance_window/${
createdMaintenanceWindow.id
}/_archive`
)
.set('kbn-xsrf', 'foo')
.send({ archive: true })
.expect(200);

// Archiving should not change the events
expect(finish.events[0].lte).eql(archive.events[0].lte);
expect(finish.events[1].lte).eql(archive.events[1].lte);
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function createMaintenanceWindowTests({ getService }: FtrProvider
freq: 2, // weekly
},
};
after(() => objectRemover.removeAll());
afterEach(() => objectRemover.removeAll());

for (const scenario of UserAtSpaceScenarios) {
const { user, space } = scenario;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function deleteMaintenanceWindowTests({ getService }: FtrProvider
freq: 2, // weekly
},
};
after(() => objectRemover.removeAll());
afterEach(() => objectRemover.removeAll());

for (const scenario of UserAtSpaceScenarios) {
const { user, space } = scenario;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ export default function findMaintenanceWindowTests({ getService }: FtrProviderCo
freq: 2, // weekly
},
};
after(() => objectRemover.removeAll());
afterEach(() => objectRemover.removeAll());

for (const scenario of UserAtSpaceScenarios) {
const { user, space } = scenario;
describe(scenario.id, () => {
afterEach(() => objectRemover.removeAll());
it('should handle update maintenance window request appropriately', async () => {
it('should handle find maintenance window request appropriately', async () => {
const { body: createdMaintenanceWindow1 } = await supertest
.post(`${getUrlPrefix(space.id)}/internal/alerting/rules/maintenance_window`)
.set('kbn-xsrf', 'foo')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,99 @@ export default function findMaintenanceWindowTests({ getService }: FtrProviderCo
});
});
}

it('should error when trying to finish a finished maintenance window', async () => {
const space1 = UserAtSpaceScenarios[1].space.id;
const { body: createdMaintenanceWindow } = await supertest
.post(`${getUrlPrefix(space1)}/internal/alerting/rules/maintenance_window`)
.set('kbn-xsrf', 'foo')
.send({
...createParams,
r_rule: {
...createParams.r_rule,
count: 1,
},
})
.expect(200);

objectRemover.add(
space1,
createdMaintenanceWindow.id,
'rules/maintenance_window',
'alerting',
true
);

const { body: finish } = await supertest
.post(
`${getUrlPrefix(space1)}/internal/alerting/rules/maintenance_window/${
createdMaintenanceWindow.id
}/_finish`
)
.set('kbn-xsrf', 'foo')
.send()
.expect(200);
expect(finish.status).eql('finished');

// Cant finish a finished maintenance window
await supertest
.post(
`${getUrlPrefix(space1)}/internal/alerting/rules/maintenance_window/${
createdMaintenanceWindow.id
}/_finish`
)
.set('kbn-xsrf', 'foo')
.send()
.expect(400);
});

it('should error when trying to finish a upcoming maintenance window', async () => {
const space1 = UserAtSpaceScenarios[1].space.id;
const { body: createdMaintenanceWindow } = await supertest
.post(`${getUrlPrefix(space1)}/internal/alerting/rules/maintenance_window`)
.set('kbn-xsrf', 'foo')
.send({
...createParams,
r_rule: {
...createParams.r_rule,
count: 2, // 2 occurrences
},
})
.expect(200);

objectRemover.add(
space1,
createdMaintenanceWindow.id,
'rules/maintenance_window',
'alerting',
true
);

const { body: finish } = await supertest
.post(
`${getUrlPrefix(space1)}/internal/alerting/rules/maintenance_window/${
createdMaintenanceWindow.id
}/_finish`
)
.set('kbn-xsrf', 'foo')
.send()
.expect(200);

// Status now upcoming, new start and end dates reflect the upcoming event
expect(finish.status).eql('upcoming');
expect(finish.event_start_time).eql(createdMaintenanceWindow.events[1].gte);
expect(finish.event_end_time).eql(createdMaintenanceWindow.events[1].lte);

// Cannot finish an upcoming maintenance window
await supertest
.post(
`${getUrlPrefix(space1)}/internal/alerting/rules/maintenance_window/${
createdMaintenanceWindow.id
}/_finish`
)
.set('kbn-xsrf', 'foo')
.send()
.expect(400);
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function getMaintenanceWindowTests({ getService }: FtrProviderCon
freq: 2, // weekly
},
};
after(() => objectRemover.removeAll());
afterEach(() => objectRemover.removeAll());

for (const scenario of UserAtSpaceScenarios) {
const { user, space } = scenario;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function updateMaintenanceWindowTests({ getService }: FtrProvider
freq: 2, // weekly
},
};
after(() => objectRemover.removeAll());
afterEach(() => objectRemover.removeAll());

for (const scenario of UserAtSpaceScenarios) {
const { user, space } = scenario;
Expand Down Expand Up @@ -90,6 +90,58 @@ export default function updateMaintenanceWindowTests({ getService }: FtrProvider
});
}

it('should update fields correctly', async () => {
const { body: createdMaintenanceWindow } = await supertest
.post(`${getUrlPrefix('space1')}/internal/alerting/rules/maintenance_window`)
.set('kbn-xsrf', 'foo')
.send({
title: 'test-maintenance-window',
duration: 60 * 60 * 1000, // 1 hr
r_rule: {
dtstart: new Date().toISOString(),
tzid: 'UTC',
freq: 2, // weekly
count: 1,
},
})
.expect(200);

objectRemover.add(
'space1',
createdMaintenanceWindow.id,
'rules/maintenance_window',
'alerting',
true
);

const newRRule = {
dtstart: moment.utc().add(1, 'day').toISOString(),
tzid: 'CET',
freq: 3,
count: 5,
};

const { body: updatedMW } = await supertest
.post(
`${getUrlPrefix('space1')}/internal/alerting/rules/maintenance_window/${
createdMaintenanceWindow.id
}`
)
.set('kbn-xsrf', 'foo')
.send({
title: 'test-maintenance-window-new',
duration: 60 * 1000,
r_rule: newRRule,
enabled: false,
})
.expect(200);

expect(updatedMW.title).eql('test-maintenance-window-new');
expect(updatedMW.duration).eql(60 * 1000);
expect(updatedMW.r_rule).eql(newRRule);
expect(updatedMW.title).eql('test-maintenance-window-new');
});

it('should update RRule correctly when removing fields', async () => {
const { body: createdMaintenanceWindow } = await supertest
.post(`${getUrlPrefix('space1')}/internal/alerting/rules/maintenance_window`)
Expand Down
Loading