|
6 | 6 |
|
7 | 7 | import expect from '@kbn/expect'; |
8 | 8 |
|
9 | | -import { getRandomString } from './lib'; |
10 | | -import { getAutoFollowIndexPayload } from './fixtures'; |
| 9 | +import { REMOTE_CLUSTER_NAME } from './constants'; |
11 | 10 | import { registerHelpers as registerRemoteClustersHelpers } from './remote_clusters.helpers'; |
12 | 11 | import { registerHelpers as registerAutoFollowPatternHelpers } from './auto_follow_pattern.helpers'; |
13 | 12 |
|
@@ -37,43 +36,60 @@ export default function({ getService }) { |
37 | 36 |
|
38 | 37 | describe('when remote cluster does not exist', () => { |
39 | 38 | 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 | + }); |
42 | 45 |
|
43 | | - const { body } = await createAutoFollowPattern(undefined, payload).expect(404); |
| 46 | + expect(body.statusCode).to.be(404); |
44 | 47 | expect(body.attributes.cause[0]).to.contain('no such remote cluster'); |
45 | 48 | }); |
46 | 49 | }); |
47 | 50 |
|
48 | 51 | describe('when remote cluster exists', () => { |
49 | | - before(() => addCluster()); |
| 52 | + before(async () => addCluster()); |
50 | 53 |
|
51 | 54 | describe('create()', () => { |
52 | 55 | 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); |
56 | 64 | expect(body.acknowledged).to.eql(true); |
57 | 65 | }); |
58 | 66 | }); |
59 | 67 |
|
60 | 68 | describe('get()', () => { |
61 | 69 | 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); |
65 | 72 | expect(body.attributes.cause).not.to.be(undefined); |
66 | 73 | }); |
67 | 74 |
|
68 | 75 | 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 | + }); |
77 | 93 | }); |
78 | 94 | }); |
79 | 95 | }); |
|
0 commit comments