Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Oct 6, 2022
1 parent 1a1521d commit efb1725
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export class KbnClientSavedObjects {
'epm-packages',
'epm-packages-assets',
'fleet-preconfiguration-deletion-record',
'fleet-fleet-server-host',
];

const newOptions = { types, space: options?.space };
Expand Down
12 changes: 12 additions & 0 deletions x-pack/plugins/fleet/common/types/rest_spec/fleet_server_hosts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { FleetServerHost } from '../models';

import type { ListResult } from './common';

export type GetFleetServerHostsResponse = ListResult<FleetServerHost>;
118 changes: 118 additions & 0 deletions x-pack/test/fleet_api_integration/apis/fleet_server_hosts/crud.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { skipIfNoDockerRegistry } from '../../helpers';
import { setupFleetAndAgents } from '../agents/services';

export default function (providerContext: FtrProviderContext) {
const { getService } = providerContext;
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');
const kibanaServer = getService('kibanaServer');

describe('fleet_fleet_server_hosts_crud', async function () {
skipIfNoDockerRegistry(providerContext);
before(async () => {
await kibanaServer.savedObjects.cleanStandardList();
await esArchiver.load('x-pack/test/functional/es_archives/fleet/empty_fleet_server');
});
setupFleetAndAgents(providerContext);

let defaultFleetServerHostId: string;

before(async function () {
const { body: defaultRes } = await supertest
.post(`/api/fleet/fleet_server_hosts`)
.set('kbn-xsrf', 'xxxx')
.send({
id: 'test-default-123',
name: 'Default',
is_default: true,
host_urls: ['https://test.fr:8080', 'https://test.fr:8081'],
})
.expect(200);

await supertest
.post(`/api/fleet/fleet_server_hosts`)
.set('kbn-xsrf', 'xxxx')
.send({
name: 'Test',
host_urls: ['https://test.fr:8080', 'https://test.fr:8081'],
})
.expect(200);

defaultFleetServerHostId = defaultRes.item.id;
});

after(async () => {
await kibanaServer.savedObjects.cleanStandardList();
await esArchiver.unload('x-pack/test/functional/es_archives/fleet/empty_fleet_server');
});

describe('GET /fleet_server_hosts', () => {
it('should list the fleet server hosts', async () => {
const { body: res } = await supertest.get(`/api/fleet/fleet_server_hosts`).expect(200);

expect(res.items.length).to.be(2);
});
});

describe('GET /fleet_server_hosts/{itemId}', () => {
it('should return the requested fleet server host', async () => {
const { body: fleetServerHost } = await supertest
.get(`/api/fleet/fleet_server_hosts/${defaultFleetServerHostId}`)
.expect(200);

expect(fleetServerHost).to.eql({
item: {
id: 'test-default-123',
name: 'Default',
is_default: true,
host_urls: ['https://test.fr:8080', 'https://test.fr:8081'],
is_preconfigured: false,
},
});
});

it('should return a 404 when retrieving a non existing fleet server host', async function () {
await supertest.get(`/api/fleet/fleet_server_hosts/idonotexists`).expect(404);
});
});

describe('PUT /fleet_server_hosts/{itemId}', () => {
it('should allow to update an existing fleet server host', async function () {
await supertest
.put(`/api/fleet/fleet_server_hosts/${defaultFleetServerHostId}`)
.set('kbn-xsrf', 'xxxx')
.send({
name: 'Default updated',
})
.expect(200);

const {
body: { item: fleetServerHost },
} = await supertest
.get(`/api/fleet/fleet_server_hosts/${defaultFleetServerHostId}`)
.expect(200);

expect(fleetServerHost.name).to.eql('Default updated');
});

it('should return a 404 when updating a non existing fleet server host', async function () {
await supertest
.put(`/api/fleet/fleet_server_hosts/idonotexists`)
.set('kbn-xsrf', 'xxxx')
.send({
name: 'new host1',
})
.expect(404);
});
});
});
}
3 changes: 3 additions & 0 deletions x-pack/test/fleet_api_integration/apis/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,8 @@ export default function ({ loadTestFile, getService }) {

// Integrations
loadTestFile(require.resolve('./integrations'));

// Fleet server hosts
loadTestFile(require.resolve('./fleet_server_hosts/crud'));
});
}

0 comments on commit efb1725

Please sign in to comment.