Skip to content

Commit

Permalink
Fixes #37762 - Don't send empty host search query to REX (#11118)
Browse files Browse the repository at this point in the history
(cherry picked from commit 8cd215e)
  • Loading branch information
jeremylenz authored and chris1984 committed Aug 28, 2024
1 parent 0591e90 commit 60f340c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ import { PACKAGE_SEARCH_QUERY } from './PackagesTab/YumInstallablePackagesConsta
import { PACKAGES_SEARCH_QUERY, SELECTED_UPDATE_VERSIONS } from './PackagesTab/HostPackagesConstants';

// PARAM BUILDING
const baseParams = (options) => {
export const buildHostSearch = ({ hostname, hostSearch }) => {
let result = hostSearch ?? `name ^ (${hostname})`;
if (result === '') {
// user has selected all hosts
result = 'set? name'; // the name field is NOT NULL, so this will match all hosts
}
return result;
};
export const baseParams = (options) => {
const {
feature, hostname, hostSearch, descriptionFormat, inputs = {},
} = options;
const search = hostSearch ?? `name ^ (${hostname})`;
const search = buildHostSearch({ hostname, hostSearch });
return ({
job_invocation: {
feature,
Expand Down Expand Up @@ -89,7 +97,7 @@ const katelloPackagesUpdateParams = (options) => {
const {
hostname, search, hostSearch, versions, descriptionFormat,
} = options;
const searchQuery = hostSearch ?? `name ^ (${hostname})`;
const searchQuery = buildHostSearch({ hostname, hostSearch });
return ({
job_invocation: {
feature: REX_FEATURES.KATELLO_PACKAGES_UPDATE_BY_SEARCH,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { baseParams, buildHostSearch } from '../RemoteExecutionActions';

describe('buildHostSearch', () => {
it('Replaces empty string with special search', () => {
const options = {
hostname: 'test',
hostSearch: '',
};
expect(buildHostSearch(options)).toEqual('set? name');
});
it('Composes hostname search when hostSearch is not passed', () => {
const options = {
hostname: 'test',
};
expect(buildHostSearch(options)).toEqual('name ^ (test)');
});
it('Composes hostSearch when hostname is not passed', () => {
const options = {
hostSearch: 'test',
};
expect(buildHostSearch(options)).toEqual('test');
});
});

describe('baseParams', () => {
it('Composes base params', () => {
const options = {
feature: 'feature',
hostname: 'hostname',
hostSearch: 'hostSearch',
descriptionFormat: 'descriptionFormat',
inputs: { input: 'input' },
};
expect(baseParams(options)).toEqual({
job_invocation: {
feature: 'feature',
inputs: { input: 'input' },
description_format: 'descriptionFormat',
search_query: 'hostSearch',
},
});
});
});

0 comments on commit 60f340c

Please sign in to comment.