[Fleet] fix pr condition to unblock prs if available versions not available (#154808)

## Summary

Fixing pr condition in https://github.com/elastic/kibana/pull/154649

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Kyle Pollich <kyle.pollich@elastic.co>
This commit is contained in:
Julia Bardi 2023-04-12 16:56:54 +02:00 committed by GitHub
parent 67308c6f8b
commit 0efdf351e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 3 deletions

View file

@ -49,13 +49,35 @@ const mockedFetch = fetch as jest.MockedFunction<typeof fetch>;
const mockedWrite = write as jest.MockedFunction<typeof write>;
const mockedBuild = new Build(config);
const processEnv = process.env;
describe('FetchAgentVersionsList', () => {
beforeEach(() => {
process.env = {
...processEnv,
// Ensure these tests can run in PR builds
BUILDKITE_PULL_REQUEST: undefined,
};
mockedFetch.mockReset();
(mockedBuild.resolvePath as jest.Mock<any>).mockReset();
mockedWrite.mockReset();
});
afterEach(() => {
process.env = processEnv;
});
describe('when BUILDKITE_PULL_REQUEST is set', () => {
it('does not run task', async () => {
process.env.BUILDKITE_PULL_REQUEST = '1234';
await FetchAgentVersionsList.run(config, new ToolingLog(), mockedBuild);
expect(mockedFetch).not.toHaveBeenCalled();
});
});
describe('when valid JSON is returned from versions endpoint', () => {
it('does not throw', async () => {
mockedFetch.mockResolvedValueOnce({

View file

@ -11,6 +11,9 @@ import fetch from 'node-fetch';
import { ToolingLog } from '@kbn/tooling-log';
import { write, Task } from '../lib';
const isPr = () =>
!!process.env.BUILDKITE_PULL_REQUEST && process.env.BUILDKITE_PULL_REQUEST !== 'false';
const getAvailableVersions = async (log: ToolingLog) => {
const options = {
headers: {
@ -41,7 +44,7 @@ const getAvailableVersions = async (log: ToolingLog) => {
} catch (error) {
const errorMessage = 'Failed to fetch Elastic Agent versions list';
if (process.env.BUILDKITE_PULL_REQUEST === 'true') {
if (isPr()) {
// For PR jobs, just log the error as a warning and continue
log.warning(errorMessage);
log.warning(error);
@ -61,7 +64,7 @@ export const FetchAgentVersionsList: Task = {
async run(config, log, build) {
// Agent version list task is skipped for PR's, so as not to overwhelm the versions API
if (process.env.BUILDKITE_PULL_REQUEST === 'true') {
if (isPr()) {
return;
}

View file

@ -13,7 +13,9 @@ export default function (providerContext: FtrProviderContext) {
const supertest = getService('supertest');
const kibanaServer = getService('kibanaServer');
describe('Agent available_versions API', () => {
// Skipped due to agent versions list not being built in CI
// Ref https://github.com/elastic/kibana/pull/154808
describe.skip('Agent available_versions API', () => {
it('should return a non empty list of versions', async () => {
const kibanaVersion = await kibanaServer.version.get();
const kibanaVersionCoerced = semverCoerce(kibanaVersion)?.version;