Skip to content

Commit af76d67

Browse files
committed
Fix API integration tests.
1 parent 1daf9ad commit af76d67

File tree

3 files changed

+43
-40
lines changed

3 files changed

+43
-40
lines changed

x-pack/test/api_integration/apis/management/cross_cluster_replication/auto_follow_pattern.helpers.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,27 @@
55
*/
66

77
import { API_BASE_PATH } from './constants';
8-
import { getRandomString } from './lib';
9-
import { getAutoFollowIndexPayload } from './fixtures';
108

119
export const registerHelpers = supertest => {
1210
let autoFollowPatternsCreated = [];
1311

1412
const loadAutoFollowPatterns = () => supertest.get(`${API_BASE_PATH}/auto_follow_patterns`);
1513

16-
const getAutoFollowPattern = name =>
17-
supertest.get(`${API_BASE_PATH}/auto_follow_patterns/${name}`);
14+
const getAutoFollowPattern = id => supertest.get(`${API_BASE_PATH}/auto_follow_patterns/${id}`);
1815

19-
const createAutoFollowPattern = (
20-
name = getRandomString(),
21-
payload = getAutoFollowIndexPayload()
22-
) => {
23-
autoFollowPatternsCreated.push(name);
16+
const createAutoFollowPattern = payload => {
17+
autoFollowPatternsCreated.push(payload.id);
2418

2519
return supertest
2620
.post(`${API_BASE_PATH}/auto_follow_patterns`)
2721
.set('kbn-xsrf', 'xxx')
28-
.send({ ...payload, id: name });
22+
.send(payload);
2923
};
3024

31-
const deleteAutoFollowPattern = name => {
32-
autoFollowPatternsCreated = autoFollowPatternsCreated.filter(c => c !== name);
25+
const deleteAutoFollowPattern = id => {
26+
autoFollowPatternsCreated = autoFollowPatternsCreated.filter(c => c !== id);
3327

34-
return supertest.delete(`${API_BASE_PATH}/auto_follow_patterns/${name}`).set('kbn-xsrf', 'xxx');
28+
return supertest.delete(`${API_BASE_PATH}/auto_follow_patterns/${id}`).set('kbn-xsrf', 'xxx');
3529
};
3630

3731
const deleteAllAutoFollowPatterns = () =>

x-pack/test/api_integration/apis/management/cross_cluster_replication/auto_follow_pattern.js

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
import expect from '@kbn/expect';
88

9-
import { getRandomString } from './lib';
10-
import { getAutoFollowIndexPayload } from './fixtures';
9+
import { REMOTE_CLUSTER_NAME } from './constants';
1110
import { registerHelpers as registerRemoteClustersHelpers } from './remote_clusters.helpers';
1211
import { registerHelpers as registerAutoFollowPatternHelpers } from './auto_follow_pattern.helpers';
1312

@@ -37,43 +36,60 @@ export default function({ getService }) {
3736

3837
describe('when remote cluster does not exist', () => {
3938
it('should throw a 404 error when cluster is unknown', async () => {
40-
const payload = getAutoFollowIndexPayload();
41-
payload.remoteCluster = 'unknown-cluster';
39+
const { body } = await createAutoFollowPattern({
40+
id: 'pattern0',
41+
remoteCluster: 'unknown-cluster',
42+
leaderIndexPatterns: ['leader-*'],
43+
followIndexPattern: '{{leader_index}}_follower',
44+
});
4245

43-
const { body } = await createAutoFollowPattern(undefined, payload).expect(404);
46+
expect(body.statusCode).to.be(404);
4447
expect(body.attributes.cause[0]).to.contain('no such remote cluster');
4548
});
4649
});
4750

4851
describe('when remote cluster exists', () => {
49-
before(() => addCluster());
52+
before(async () => addCluster());
5053

5154
describe('create()', () => {
5255
it('should create an auto-follow pattern when cluster is known', async () => {
53-
const name = getRandomString();
54-
const { body } = await createAutoFollowPattern(name).expect(200);
55-
56+
const { body, statusCode } = await createAutoFollowPattern({
57+
id: 'pattern1',
58+
remoteCluster: REMOTE_CLUSTER_NAME,
59+
leaderIndexPatterns: ['leader-*'],
60+
followIndexPattern: '{{leader_index}}_follower',
61+
});
62+
63+
expect(statusCode).to.be(200);
5664
expect(body.acknowledged).to.eql(true);
5765
});
5866
});
5967

6068
describe('get()', () => {
6169
it('should return a 404 when the auto-follow pattern is not found', async () => {
62-
const name = getRandomString();
63-
const { body } = await getAutoFollowPattern(name).expect(404);
64-
70+
const { body } = await getAutoFollowPattern('missing-pattern');
71+
expect(body.statusCode).to.be(404);
6572
expect(body.attributes.cause).not.to.be(undefined);
6673
});
6774

6875
it('should return an auto-follow pattern that was created', async () => {
69-
const name = getRandomString();
70-
const autoFollowPattern = getAutoFollowIndexPayload();
71-
72-
await createAutoFollowPattern(name, autoFollowPattern);
73-
74-
const { body } = await getAutoFollowPattern(name).expect(200);
75-
76-
expect(body).to.eql({ ...autoFollowPattern, name });
76+
await createAutoFollowPattern({
77+
id: 'pattern2',
78+
remoteCluster: REMOTE_CLUSTER_NAME,
79+
leaderIndexPatterns: ['leader-*'],
80+
followIndexPattern: '{{leader_index}}_follower',
81+
});
82+
83+
const { body, statusCode } = await getAutoFollowPattern('pattern2');
84+
85+
expect(statusCode).to.be(200);
86+
expect(body).to.eql({
87+
name: 'pattern2',
88+
remoteCluster: REMOTE_CLUSTER_NAME,
89+
active: true,
90+
leaderIndexPatterns: ['leader-*'],
91+
followIndexPattern: '{{leader_index}}_follower',
92+
});
7793
});
7894
});
7995
});

x-pack/test/api_integration/apis/management/cross_cluster_replication/fixtures.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@
77
import { REMOTE_CLUSTER_NAME } from './constants';
88
import { getRandomString } from './lib';
99

10-
export const getAutoFollowIndexPayload = (remoteCluster = REMOTE_CLUSTER_NAME, active = true) => ({
11-
active,
12-
remoteCluster,
13-
leaderIndexPatterns: ['leader-*'],
14-
followIndexPattern: '{{leader_index}}_follower',
15-
});
16-
1710
export const getFollowerIndexPayload = (
1811
leaderIndexName = getRandomString(),
1912
remoteCluster = REMOTE_CLUSTER_NAME,

0 commit comments

Comments
 (0)