[5.6] Resolve known APIs (#24399)

This commit is contained in:
Larry Gregory 2018-10-23 12:51:08 -04:00 committed by GitHub
parent e4ae9b67ac
commit 51aff7d3c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 4 deletions

View file

@ -1,12 +1,14 @@
let _ = require("lodash");
const KNOWN_APIS = ['es_5_0'];
module.exports.resolveApi = function (sense_version, apis, reply) {
let result = {};
_.each(apis, function (name) {
{
// for now we ignore sense_version. might add it in the api name later
let api = require('./' + name);
result[name] = api.asJson();
if (KNOWN_APIS.includes(name)) {
// for now we ignore sense_version. might add it in the api name later
let api = require('./' + name);
result[name] = api.asJson();
}
}
});

View file

@ -0,0 +1,51 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { resolveApi } from './server';
describe('resolveApi', () => {
it('allows known APIs to be resolved', () => {
const mockReply = jest.fn((result) => ({ type: () => result }));
const result = resolveApi('Sense Version', ['es_5_0'], mockReply);
expect(result).toMatchObject({
es_5_0: {
endpoints: expect.any(Object),
globals: expect.any(Object),
name: expect.any(String),
}
});
});
it('does not resolve APIs that are not known', () => {
const mockReply = jest.fn((result) => ({ type: () => result }));
const result = resolveApi('Sense Version', ['unknown'], mockReply);
expect(result).toEqual({});
});
it('handles request for apis that are known and unknown', () => {
const mockReply = jest.fn((result) => ({ type: () => result }));
const result = resolveApi('Sense Version', ['es_5_0'], mockReply);
expect(result).toMatchObject({
es_5_0: {
endpoints: expect.any(Object),
globals: expect.any(Object),
name: expect.any(String),
}
});
});
});

View file

@ -1,6 +1,7 @@
{
"rootDir": "../../..",
"roots": [
"<rootDir>/src/core_plugins/console/api_server",
"<rootDir>/src/core_plugins/kibana/public/dashboard",
"<rootDir>/ui_framework/"
],