From e8bcd96933c5bad881109b5248e2d8a66b11af62 Mon Sep 17 00:00:00 2001 From: Alison Goryachev Date: Wed, 2 Dec 2020 15:53:39 -0500 Subject: [PATCH] address review feedback --- .../snapshot_restore/lib/elasticsearch.ts | 8 +++ .../snapshot_restore/snapshot_restore.ts | 68 ++++++++++++++++++- 2 files changed, 73 insertions(+), 3 deletions(-) diff --git a/x-pack/test/api_integration/apis/management/snapshot_restore/lib/elasticsearch.ts b/x-pack/test/api_integration/apis/management/snapshot_restore/lib/elasticsearch.ts index 7ab99ccac40df6..932df405dde128 100644 --- a/x-pack/test/api_integration/apis/management/snapshot_restore/lib/elasticsearch.ts +++ b/x-pack/test/api_integration/apis/management/snapshot_restore/lib/elasticsearch.ts @@ -60,6 +60,13 @@ export const registerEsHelpers = (getService: FtrProviderContext['getService']) }); }; + const getPolicy = (policyName: string) => { + return es.sr.policy({ + name: policyName, + human: true, + }); + }; + const deletePolicy = (policyName: string) => es.sr.deletePolicy({ name: policyName }); const cleanupPolicies = () => @@ -77,5 +84,6 @@ export const registerEsHelpers = (getService: FtrProviderContext['getService']) createPolicy, deletePolicy, cleanupPolicies, + getPolicy, }; }; diff --git a/x-pack/test/api_integration/apis/management/snapshot_restore/snapshot_restore.ts b/x-pack/test/api_integration/apis/management/snapshot_restore/snapshot_restore.ts index 3171dc2fceacf7..575da0db2a759b 100644 --- a/x-pack/test/api_integration/apis/management/snapshot_restore/snapshot_restore.ts +++ b/x-pack/test/api_integration/apis/management/snapshot_restore/snapshot_restore.ts @@ -15,9 +15,13 @@ const REPO_NAME = 'test_repo'; export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); - const { createRepository, createPolicy, deletePolicy, cleanupPolicies } = registerEsHelpers( - getService - ); + const { + createRepository, + createPolicy, + deletePolicy, + cleanupPolicies, + getPolicy, + } = registerEsHelpers(getService); describe('Snapshot Lifecycle Management', function () { before(async () => { @@ -79,6 +83,27 @@ export default function ({ getService }: FtrProviderContext) { expect(body).to.eql({ acknowledged: true, }); + + const policyFromEs = await getPolicy(POLICY_NAME); + expect(policyFromEs[POLICY_NAME]).to.be.ok(); + expect(policyFromEs[POLICY_NAME].policy).to.eql({ + name: 'my_snapshot', + schedule: '0 30 1 * * ?', + repository: REPO_NAME, + config: { + indices: ['my_index'], + ignore_unavailable: true, + partial: false, + metadata: { + meta: 'my_meta', + }, + }, + retention: { + expire_after: '1d', + max_count: 10, + min_count: 5, + }, + }); }); it('should create a policy with only required fields', async () => { @@ -98,6 +123,14 @@ export default function ({ getService }: FtrProviderContext) { expect(body).to.eql({ acknowledged: true, }); + + const policyFromEs = await getPolicy(REQUIRED_FIELDS_POLICY_NAME); + expect(policyFromEs[REQUIRED_FIELDS_POLICY_NAME]).to.be.ok(); + expect(policyFromEs[REQUIRED_FIELDS_POLICY_NAME].policy).to.eql({ + name: 'my_snapshot', + repository: REPO_NAME, + schedule: '0 30 1 * * ?', + }); }); }); @@ -151,6 +184,27 @@ export default function ({ getService }: FtrProviderContext) { expect(body).to.eql({ acknowledged: true, }); + + const policyFromEs = await getPolicy(POLICY_NAME); + expect(policyFromEs[POLICY_NAME]).to.be.ok(); + expect(policyFromEs[POLICY_NAME].policy).to.eql({ + name: 'my_snapshot', + schedule: '0 0 0 ? * 7', + repository: REPO_NAME, + config: { + indices: ['my_index'], + ignore_unavailable: true, + partial: false, + metadata: { + meta: 'my_meta', + }, + }, + retention: { + expire_after: '1d', + max_count: 10, + min_count: 5, + }, + }); }); it('should allow optional fields to be removed', async () => { @@ -166,6 +220,14 @@ export default function ({ getService }: FtrProviderContext) { expect(body).to.eql({ acknowledged: true, }); + + const policyFromEs = await getPolicy(POLICY_NAME); + expect(policyFromEs[POLICY_NAME]).to.be.ok(); + expect(policyFromEs[POLICY_NAME].policy).to.eql({ + name: 'my_snapshot', + schedule: '0 30 1 * * ?', + repository: REPO_NAME, + }); }); }); });